diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index ce55da9e558e..82c82d836071 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -270,7 +270,7 @@ class BaseDriver extends AbstractPaymentDriver * @param array $data * @return null|\App\Models\ClientGatewayToken */ - public function storeGatewayToken(array $data): ?ClientGatewayToken + public function storeGatewayToken(array $data, array $additional = []): ?ClientGatewayToken { $company_gateway_token = new ClientGatewayToken(); $company_gateway_token->company_id = $this->client->company->id; @@ -279,6 +279,11 @@ class BaseDriver extends AbstractPaymentDriver $company_gateway_token->company_gateway_id = $this->company_gateway->id; $company_gateway_token->gateway_type_id = $data['payment_method_id']; $company_gateway_token->meta = $data['payment_meta']; + + foreach ($additional as $key => $value) { + $company_gateway_token->{$key} = $value; + } + $company_gateway_token->save(); if ($this->client->gateway_tokens->count() == 1) { diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 2142e73bc336..57d685245a00 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -54,7 +54,7 @@ class CreditCard $stripe_method = $this->stripe->getStripePaymentMethod($stripe_response->payment_method); - $this->storePaymentMethod($stripe_method, $request->payment_method_id); + $this->storePaymentMethod($stripe_method, $request->payment_method_id, $customer); return redirect()->route('client.payment_methods.index'); } @@ -205,7 +205,7 @@ class CreditCard throw new \Exception('Failed to process the payment.', 1); } - private function storePaymentMethod(\Stripe\PaymentMethod $method, $payment_method_id) + private function storePaymentMethod(\Stripe\PaymentMethod $method, $payment_method_id, $customer) { try { $payment_meta = new \stdClass; @@ -221,7 +221,7 @@ class CreditCard 'payment_method_id' => $payment_method_id, ]; - $this->stripe->storeGatewayToken($data); + $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); } catch (\Exception $e) { return $this->stripe->processInternallyFailedPayment($this->stripe, $e); }