Skip to content

Commit

Permalink
Fix Stripe 3DS flow in case 3D secure is involved
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rootpd committed Jun 18, 2021
1 parent 9c1e13c commit 202b2e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
10 changes: 7 additions & 3 deletions src/gateways/AbstractStripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
Expand Down
28 changes: 2 additions & 26 deletions src/seeders/sales_funnels/stripe-elements-sample.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 () {
Expand Down

0 comments on commit 202b2e1

Please sign in to comment.