Merge pull request #6752 from turbo124/v5-develop

Fixes for ACH Auto Billing
This commit is contained in:
David Bomba 2021-10-01 13:58:00 +10:00 committed by GitHub
commit dbd605f38a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 4 deletions

View File

@ -500,7 +500,7 @@ class CompanyController extends BaseController
$account->delete();
if(Ninja::isHosted())
\Modules\Admin\Jobs\Account\NinjaDeletedAccount::dispatch($account_key);
\Modules\Admin\Jobs\Account\NinjaDeletedAccount::dispatch($account_key, $request->all());
LightLogs::create(new AccountDeleted())
->increment()

View File

@ -30,6 +30,7 @@ class SubdomainController extends BaseController
'invoiceninja',
'cname',
'sandbox',
'stage',
];
public function __construct()

View File

@ -407,7 +407,7 @@ class Account extends BaseModel
}
}
catch(\Exception $e){
\Sentry\captureMessage("I encountered an error with email quotas - defaulting to SEND");
\Sentry\captureMessage("I encountered an error with email quotas for account {$this->key} - defaulting to SEND");
}
return false;

View File

@ -22,7 +22,9 @@ use App\Jobs\Util\SystemLogger;
use App\Mail\Gateways\ACHVerificationNotification;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver;
@ -145,6 +147,62 @@ class ACH
return render('gateways.stripe.ach.pay', $data);
}
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();
if ($invoice) {
$description = "Invoice {$invoice->number} for {$amount} for client {$this->stripe->client->present()->name()}";
} else {
$description = "Payment with no invoice for amount {$amount} for client {$this->stripe->client->present()->name()}";
}
$this->stripe->init();
$response = null;
try {
$state = [
'gateway_type_id' => GatewayType::BANK_TRANSFER,
'amount' => $this->stripe->convertToStripeAmount($amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
'currency' => $this->stripe->client->getCurrencyCode(),
'customer' => $cgt->gateway_customer_reference,
'source' => $cgt->token,
];
$state['charge'] = \Stripe\Charge::create([
'amount' => $state['amount'],
'currency' => $state['currency'],
'customer' => $state['customer'],
'source' => $state['source'],
'description' => $description,
], $this->stripe->stripe_connect_auth);
$payment_hash->data = array_merge((array)$payment_hash->data, $state);
$payment_hash->save();
if ($state['charge']->status === 'pending' && is_null($state['charge']->failure_message)) {
return $this->processPendingPayment($state, false);
}
return $this->processUnsuccessfulPayment($state);
} catch (Exception $e) {
if ($e instanceof CardException) {
return redirect()->route('client.payment_methods.verification', ['payment_method' => $source->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
}
throw new PaymentFailed($e->getMessage(), $e->getCode());
}
}
public function paymentResponse($request)
{
@ -201,7 +259,7 @@ class ACH
}
}
public function processPendingPayment($state)
public function processPendingPayment($state, $client_present = true)
{
$this->stripe->init();
@ -224,6 +282,9 @@ class ACH
$this->stripe->client->company,
);
if(!$client_present)
return $payment;
return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]);
}

View File

@ -15,11 +15,13 @@ namespace App\PaymentDrivers\Stripe;
use App\Events\Payment\PaymentWasCreated;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver;
use App\PaymentDrivers\Stripe\ACH;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Stripe\Exception\ApiConnectionException;
@ -51,6 +53,9 @@ class Charge
*/
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
if($cgt->gateway_type_id == GatewayType::BANK_TRANSFER)
return (new ACH($this->stripe))->tokenBilling($cgt, $payment_hash);
nlog(" DB = ".$this->stripe->client->company->db);
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();

View File

@ -314,7 +314,9 @@ class StripePaymentDriver extends BaseDriver
$this->init();
$client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)->whereCompanyGatewayId($this->company_gateway->id)->first();
$client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)
->whereCompanyGatewayId($this->company_gateway->id)
->first();
//Search by customer reference
if ($client_gateway_token && $client_gateway_token->gateway_customer_reference) {

View File

@ -45,6 +45,10 @@ class TriggeredActions extends AbstractService
$this->quote = $this->quote->service()->markSent()->save();
}
if ($this->request->has('convert') && $this->request->input('convert') == 'true') {
$this->quote = $this->quote->service()->convert()->save();
}
return $this->quote;
}