How to handle 3D card authentication through Stripe in node

1.6k Views Asked by At

I'm new to integrate stripe payment. I confused how to integrate 3D secure authentication. In my application on Backend platform using node with Hapi framework. Here is the some of code of paymnet intent which is given below.

 let params = {
    amount: 100,
    currency: "CAD",
    payment_method_types: ['card'],
    payment_method: "card_1HqytjG6OdQYWdifbWxCrVGB", //cardId
    customer: "users5fc1c5ff44d8605030499c00", //userId
}

let intent = await stripe.paymentIntents.create(params {
            idempotencyKey: uuidv4());
let paymetConfirm =  await stripe.paymentIntents.confirm(intent.id, intend.payment_method);

It's working fine with some of the test cards which not require 3D secure authentication.

  1. 4242424242424242
  2. 2223003122003222

Not working with these cards require 3D authentication)

  1. 4000002760003184
  2. 4000002500003155

So, when I check the response of the API (with 3D authentication card) return one of the sub-object is

next_action: {
    type: 'use_stripe_sdk',
    use_stripe_sdk: {
    type: 'three_d_secure_redirect',
     stripe_js: 'https://hooks.stripe.com/redirect/authenticate/src_1Hs1zhG6OdQYWdifEWTcyUvC?client_secret=src_client_secret_okgYE1A4eOovEFL9g0sgN29U',
  source: 'src_1Hs1zhG6OdQYWdifEWTcyUvC'
}

},

When I take this URL and paste on the browser it redirects the page of 3d Secure, There are two option

  1. complete authentication
  2. fail authentication

Note- Stripe SDK is set up only on the backend platform(Node)

My question is that

  1. Is there any way not to confirm from the client-side, automatically confirm from the backend platform.
  2. For the scenario, we have to set up a stripe SDK on the client-side(android,IOS).?
  3. when I click on the URL which are inside next_action object which are given above,There are two option inside it,that is complete and failure authentication(3D page view) how to integrate clicking on itmy API hit respectively. how to achieve it?

Please help me.Thanks

1

There are 1 best solutions below

2
On

Your payments are failing with 3DS enabled cards because you aren't authenticating them on the client. Your current flow of confirming server side won't work with 3DS enabled cards, as you aren't giving the user an opportunity to do the 3DS flow.

It's not really recommended to confirm the payment server-side, as it adds unnecessary round trips to the server without really adding anything. However if you do still want to confirm server side, Stripe has a guide on how to do that here: https://stripe.com/docs/payments/accept-a-payment-synchronously