From 1580a93a6e57c85ef25a606e75a7d95cdc88ddf1 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 16 Jan 2023 21:21:04 +0100 Subject: [PATCH] Fixes for webhook --- app/PaymentDrivers/StripePaymentDriver.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 5438e0e6c68c..169e6cb14e3f 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -18,6 +18,7 @@ use App\Factory\PaymentFactory; use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Http\Requests\Request; use App\Jobs\Util\SystemLogger; +use App\Models\Client; use App\Models\ClientGatewayToken; use App\Models\Country; use App\Models\GatewayType; @@ -730,10 +731,12 @@ class StripePaymentDriver extends BaseDriver return response()->json([], 200); } elseif ($request->type === "checkout.session.completed"){ // Store payment token for Stripe BACS - $setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data['setup_intent'], []); - $customer = $this->stripe->findOrCreateCustomer(); - $this->stripe->attach($setup_intent->payment_method, $customer); - $payment_method = $this->stripe->getStripePaymentMethod($setup_intent->payment_method); + $this->init(); + $setup_intent = $this->stripe->setupIntents->retrieve($request->data['object']['setup_intent'], []); + $this->client = Client::where('id', ClientGatewayToken::where('gateway_customer_reference', $request->data['object']['customer'])->first()->client_id)->first(); + $customer = $this->findOrCreateCustomer(); + $this->attach($setup_intent->payment_method, $customer); + $payment_method = $this->getStripePaymentMethod($setup_intent->payment_method); $payment_meta = new \stdClass; $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; $payment_meta->last4 = (string) $payment_method->bacs_debit->last4; @@ -745,7 +748,7 @@ class StripePaymentDriver extends BaseDriver 'token' => $payment_method->id, 'payment_method_id' => GatewayType::BACS, ]; - $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + $this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); return response()->json([], 200); } elseif ($request->type === "mandate.updated"){ // Check if payment method BACS is still valid