Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Support 3D Secure with PRAPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten-stripe committed Feb 27, 2019
1 parent 7df4c45 commit 51608dd
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions public/javascripts/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,28 @@

// Callback when a source is created.
paymentRequest.on('source', async event => {
try {
const paymentResponse = await stripe.handleCardPayment(
paymentIntent.client_secret,
{
source: event.source.id,
}
);
handlePayment(paymentResponse);
event.complete('success');
} catch (error) {
// Confirm the PaymentIntent with the source returned from the payment request.
const {error} = await stripe.confirmPaymentIntent(
paymentIntent.client_secret,
{
source: event.source.id,
// We set use_stripe_sdk to true so that we can use Stripe.js for 3D Secure if needed.
use_stripe_sdk: true,
}
);
if (error) {
// Report to the browser that the payment failed.
event.complete('fail');
handlePayment({error});
} else {
// Report to the browser that the confirmation was successful, prompting
// it to close the browser payment method collection interface.
event.complete('success');
// Let Stripe.js handle the rest of the payment flow, including 3D Secure if needed.
const response = await stripe.handleCardPayment(
paymentIntent.client_secret
);
handlePayment(response);
}
});

Expand Down

0 comments on commit 51608dd

Please sign in to comment.