diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index 75789084245c..631e2a7be670 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -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); diff --git a/app/PaymentDrivers/Stripe/Charge.php b/app/PaymentDrivers/Stripe/Charge.php index fbed56e34e41..05833ccecc63 100644 --- a/app/PaymentDrivers/Stripe/Charge.php +++ b/app/PaymentDrivers/Stripe/Charge.php @@ -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; } } } diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index b5b5a7268d29..1023d8ff6580 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -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); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 8e813802b13c..bdac90e9c0b2 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -106,7 +106,7 @@ class StripePaymentDriver extends BaseDriver /** * Initializes the Stripe API. - * @return void + * @return self */ public function init() {