From 6e71f6bb6f584ecb13add289bc1a8bd7b9abc834 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 3 Aug 2021 02:41:05 +0200 Subject: [PATCH] Fix issue with requires_action (#1226) --- resources/views/payment.blade.php | 2 ++ src/Http/Controllers/PaymentController.php | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/resources/views/payment.blade.php b/resources/views/payment.blade.php index 5eb174da..b92735b3 100644 --- a/resources/views/payment.blade.php +++ b/resources/views/payment.blade.php @@ -301,6 +301,8 @@ class="inline-block w-full px-4 py-3 bg-gray-100 hover:bg-gray-200 text-center t if (this.paymentMethod.type === 'card') { if (this.paymentIntent.status === 'requires_payment_method') { data.payment_method.card = this.paymentElement; + } else if (this.paymentIntent.status === 'requires_action') { + data.payment_method = this.paymentIntent.payment_method.id; } paymentPromise = stripe.confirmCardPayment(secret, data); diff --git a/src/Http/Controllers/PaymentController.php b/src/Http/Controllers/PaymentController.php index 5f750e22..80f9ff49 100644 --- a/src/Http/Controllers/PaymentController.php +++ b/src/Http/Controllers/PaymentController.php @@ -32,13 +32,17 @@ public function show($id) $id, ['expand' => ['payment_method']]) ); + $paymentIntent = Arr::only($payment->asStripePaymentIntent()->toArray(), [ + 'id', 'status', 'payment_method_types', 'client_secret', 'payment_method', + ]); + + $paymentIntent['payment_method'] = Arr::only($paymentIntent['payment_method'] ?? [], 'id'); + return view('cashier::payment', [ 'stripeKey' => config('cashier.key'), 'amount' => $payment->amount(), 'payment' => $payment, - 'paymentIntent' => Arr::only($payment->asStripePaymentIntent()->toArray(), [ - 'id', 'status', 'payment_method_types', 'client_secret', - ]), + 'paymentIntent' => array_filter($paymentIntent), 'paymentMethod' => (string) request('source_type', optional($payment->payment_method)->type), 'errorMessage' => request('redirect_status') === 'failed' ? 'Something went wrong when trying to confirm the payment. Please try again.'