From 5d98b288281704f9d6f7a0d940bab752c76e94c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 13 Oct 2021 13:56:28 +0200 Subject: [PATCH] Store payment method on request --- app/PaymentDrivers/Stripe/SEPA.php | 11 +++++------ resources/js/clients/payments/stripe-sepa.js | 9 +++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/PaymentDrivers/Stripe/SEPA.php b/app/PaymentDrivers/Stripe/SEPA.php index 0261b7b395ff..de40976c5ed4 100644 --- a/app/PaymentDrivers/Stripe/SEPA.php +++ b/app/PaymentDrivers/Stripe/SEPA.php @@ -67,16 +67,15 @@ class SEPA public function paymentResponse(PaymentResponseRequest $request) { - $gateway_response = json_decode($request->gateway_response); $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all()); $this->stripe->payment_hash->save(); if (property_exists($gateway_response, 'status') && $gateway_response->status == 'processing') { - - - $this->storePaymentMethod($gateway_response); + if ($request->store_card) { + $this->storePaymentMethod($gateway_response); + } return $this->processSuccessfulPayment($gateway_response->id); } @@ -97,7 +96,7 @@ class SEPA 'gateway_type_id' => GatewayType::SEPA, ]; - $this->stripe->createPayment($data, Payment::STATUS_PENDING); + $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( ['response' => $this->stripe->payment_hash->data, 'data' => $data], @@ -108,7 +107,7 @@ class SEPA $this->stripe->client->company, ); - return redirect()->route('client.payments.index'); + return redirect()->route('client.payments.show', $payment->hashed_id); } public function processUnsuccessfulPayment() diff --git a/resources/js/clients/payments/stripe-sepa.js b/resources/js/clients/payments/stripe-sepa.js index f5e4fe33f8a2..eeb4b411fc03 100644 --- a/resources/js/clients/payments/stripe-sepa.js +++ b/resources/js/clients/payments/stripe-sepa.js @@ -134,6 +134,15 @@ class ProcessSEPA { 'input[name="gateway_response"]' ).value = JSON.stringify(result.paymentIntent); + let tokenBillingCheckbox = document.querySelector( + 'input[name="token-billing-checkbox"]:checked' + ); + + if (tokenBillingCheckbox) { + document.querySelector('input[name="store_card"]').value = + tokenBillingCheckbox.value; + } + document.getElementById('server-response').submit(); }