mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 08:54:34 -04:00
Fixes for token billing with stripe bank transfers
This commit is contained in:
parent
b28d76d491
commit
04226eb827
@ -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)]);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user