Fixes for webhook

This commit is contained in:
Lars Kusch 2023-01-16 21:21:04 +01:00
parent 95f2e47abf
commit 1580a93a6e

View File

@ -18,6 +18,7 @@ use App\Factory\PaymentFactory;
use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\Client;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\Country; use App\Models\Country;
use App\Models\GatewayType; use App\Models\GatewayType;
@ -730,10 +731,12 @@ class StripePaymentDriver extends BaseDriver
return response()->json([], 200); return response()->json([], 200);
} elseif ($request->type === "checkout.session.completed"){ } elseif ($request->type === "checkout.session.completed"){
// Store payment token for Stripe BACS // Store payment token for Stripe BACS
$setup_intent = $this->stripe->stripe->setupIntents->retrieve($request->data['setup_intent'], []); $this->init();
$customer = $this->stripe->findOrCreateCustomer(); $setup_intent = $this->stripe->setupIntents->retrieve($request->data['object']['setup_intent'], []);
$this->stripe->attach($setup_intent->payment_method, $customer); $this->client = Client::where('id', ClientGatewayToken::where('gateway_customer_reference', $request->data['object']['customer'])->first()->client_id)->first();
$payment_method = $this->stripe->getStripePaymentMethod($setup_intent->payment_method); $customer = $this->findOrCreateCustomer();
$this->attach($setup_intent->payment_method, $customer);
$payment_method = $this->getStripePaymentMethod($setup_intent->payment_method);
$payment_meta = new \stdClass; $payment_meta = new \stdClass;
$payment_meta->brand = (string) $payment_method->bacs_debit->sort_code; $payment_meta->brand = (string) $payment_method->bacs_debit->sort_code;
$payment_meta->last4 = (string) $payment_method->bacs_debit->last4; $payment_meta->last4 = (string) $payment_method->bacs_debit->last4;
@ -745,7 +748,7 @@ class StripePaymentDriver extends BaseDriver
'token' => $payment_method->id, 'token' => $payment_method->id,
'payment_method_id' => GatewayType::BACS, '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); return response()->json([], 200);
} elseif ($request->type === "mandate.updated"){ } elseif ($request->type === "mandate.updated"){
// Check if payment method BACS is still valid // Check if payment method BACS is still valid