From 202b2e185ad15c713b2c8382fbf294de363a47e7 Mon Sep 17 00:00:00 2001 From: Peter Dulacka Date: Wed, 9 Jun 2021 11:10:01 +0200 Subject: [PATCH] Fix Stripe 3DS flow in case 3D secure is involved The original implementation was trigerring 3DS verification before the window was even submitted - stripe.js trigerred that automatically when creating setup intent. This caused that some banks displayed zero amount at the verification page which is not very OK. At all to be honest. Setup intent was not actually required to exist and it was only used to get paymentMethod ID. Creating just the PaymentMethod with the offline use support is enough. remp/crm#1893 --- src/gateways/AbstractStripe.php | 10 +++++-- .../sales_funnels/stripe-elements-sample.twig | 28 ++----------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/gateways/AbstractStripe.php b/src/gateways/AbstractStripe.php index 718374b..fdb0592 100644 --- a/src/gateways/AbstractStripe.php +++ b/src/gateways/AbstractStripe.php @@ -64,9 +64,13 @@ protected function processCheckout($payment, $futureUsage = 'on_session') $lineItems = []; foreach ($payment->related('payment_items') as $paymentItem) { $lineItems[] = [ - 'name' => $paymentItem->name, - 'amount' => $this->calculateStripeAmount($paymentItem->amount * $paymentItem->count, $this->applicationConfig->get('currency')), - 'currency' => $this->applicationConfig->get('currency'), + 'price_data' => [ + 'unit_amount' => $this->calculateStripeAmount($paymentItem->amount, $this->applicationConfig->get('currency')), + 'currency' => $this->applicationConfig->get('currency'), + 'product_data' => [ + 'name' => $paymentItem->name, + ], + ], 'quantity' => $paymentItem->count, ]; } diff --git a/src/seeders/sales_funnels/stripe-elements-sample.twig b/src/seeders/sales_funnels/stripe-elements-sample.twig index be4d9d3..e645d00 100644 --- a/src/seeders/sales_funnels/stripe-elements-sample.twig +++ b/src/seeders/sales_funnels/stripe-elements-sample.twig @@ -173,9 +173,9 @@ function processStripe(form) { var paymentMethodIdField = $('#stripePaymentMethodId'); var cardholderName = $('#cardholder-name'); - var selectedGateway = $('input[name=payment_gateway]').val(); + var selectedGateway = $('input[name=payment_gateway]:checked').val(); - if (selectedGateway === 'stripe') { + if (selectedGateway === 'stripe' || selectedGateway === 'stripe_recurrent') { stripe.createPaymentMethod('card', cardElement, { billing_details: {name: cardholderName.value } }).then(function(result) { @@ -188,30 +188,6 @@ }); return false; } - - if (selectedGateway === 'stripe_recurrent') { - $.post('/api/v1/stripe/setup-intent', function($data) { - stripe.confirmCardSetup( - $data['client_secret'], - { - payment_method: { - card: cardElement, - billing_details: { - name: cardholderName.value, - }, - } - }, - ).then(function(result) { - if (result.error) { - alert(result.error.message); - } else { - paymentMethodIdField.val(result.setupIntent.payment_method); - form.submit(); - } - }); - }, 'json'); - return false; - } } $email.change(function () {