Fixes for stripe sepa payment method duplicating each time token billing is used.

This commit is contained in:
David Bomba 2023-05-08 20:33:21 +10:00
parent 80e20c0f1e
commit 9fd016e6e1
4 changed files with 34 additions and 10 deletions

View File

@ -543,7 +543,8 @@ class ACH
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_STRIPE,
$this->stripe->client
$this->stripe->client,
$this->stripe->client->company,
);
throw new PaymentFailed('Failed to process the payment.', 500);
@ -570,6 +571,20 @@ class ACH
'payment_method_id' => $payment_method_id,
];
/**
* Ensure the method does not already exist!!
*/
$token = ClientGatewayToken::where([
'gateway_customer_reference' => $customer->id,
'token' => $method->id,
'client_id' => $this->stripe->client->id,
'company_id' => $this->stripe->client->company_id,
])->first();
if($token)
return $token;
return $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
} catch (Exception $e) {
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);

View File

@ -194,17 +194,14 @@ class Charge
switch ($type) {
case 'visa':
return PaymentType::VISA;
break;
case 'mastercard':
return PaymentType::MASTERCARD;
break;
case PaymentType::SEPA:
return PaymentType::SEPA;
case PaymentType::BACS:
return PaymentType::BACS;
default:
return PaymentType::CREDIT_CARD_OTHER;
break;
}
}
}

View File

@ -11,14 +11,15 @@
namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\Models\GatewayType;
use App\Models\PaymentType;
use App\Jobs\Util\SystemLogger;
use App\Exceptions\PaymentFailed;
use App\Models\ClientGatewayToken;
use App\PaymentDrivers\StripePaymentDriver;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
class SEPA
{
@ -159,6 +160,17 @@ class SEPA
'payment_method_id' => GatewayType::SEPA,
];
$token = ClientGatewayToken::where([
'gateway_customer_reference' => $method->customer,
'token' => $method->id,
'client_id' => $this->stripe->client->id,
'company_id' => $this->stripe->client->company_id,
])->first();
if($token) {
return $token;
}
$this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $method->customer]);
} catch (\Exception $e) {
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);

View File

@ -106,7 +106,7 @@ class StripePaymentDriver extends BaseDriver
/**
* Initializes the Stripe API.
* @return void
* @return self
*/
public function init()
{