#sreekanth_api

1 messages ¡ Page 1 of 1 (latest)

surreal flumeBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1232622610081124475

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

bold palmBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

true bison
#

hi

bold palmBOT
worldly vessel
#

hi there!

#

are you using Checkout Session? and you want to prefill the card of the user?

true bison
#

The issue arises from our current flow: users add their card details to Stripe, and during payment, we present their saved cards for selection. Once a card is selected and the user clicks submit, we handle the payment on the backend. However, we face a challenge with secure payments that require authentication, as we cannot complete the transaction until authentication is successfully completed

worldly vessel
#

how are you accepting payments? Checkout Session, Payment Element, something else?

true bison
#

we are adding the card details to the stripe during signup and we are using the same for payment...

worldly vessel
#

can you answer my question above?

true bison
#

customer = await stripe.customers.create({
payment_method: req.body.paymentMethod
});

// List the customer's payment methods to find one to charge
const paymentMethods = await stripe.paymentMethods.list({
  customer: customer.id,
  type: "card"
});

// Create and confirm a PaymentIntent with the order amount, currency, 
// Customer and PaymentMethod ID
paymentIntent = await stripe.paymentIntents.create({
  amount: calculateOrderAmount(),
  currency: "usd",
  payment_method: paymentMethods.data[0].id,
  customer: customer.id,
  off_session: true,
  confirm: true
});

res.send({
  succeeded: true,
  clientSecret: paymentIntent.client_secret,
  publicKey: process.env.STRIPE_PUBLISHABLE_KEY
});
worldly vessel
#

so you are using the PaymentIntent API, got it.

true bison
#

const token = await stripe.tokens.create({
card: {

    number: req.body['card[number]'],
    exp_month: req.body['card[exp_month]'],
    exp_year: req.body['card[exp_year]'],
    cvc: req.body['card[cvc]'],
    name: req.body.cardholder_name,

  },
});
const card = await stripe.customers.createSource(
  customer.id,
  { source: token.id }
);



console.log("carddetails",card);
const updatedCustomer = await stripe.customers.update(customer.id, {
  invoice_settings: {
    default_payment_method: card.id
  }
})
worldly vessel
#

wait why are you using Tokens? this is a very old integration that we don't recommend using.

true bison
#

yes, this is old code....

worldly vessel
#

However, we face a challenge with secure payments that require authentication, as we cannot complete the transaction until authentication is successfully completed
When 3DS is required, you have to tell your customers to come back to your website, and there confirm the PaymentIntent on the frontend to trigger 3DS.

true bison
#

as you can see code we are collecting the card details and attaching to the customer... and we are using the same for payment...

#

Since we are directly handling payments in the backend, the issue we are facing pertains to authenticated payments

worldly vessel
#

Since we are directly handling payments in the backend, the issue we are facing pertains to authenticated payments
yes, I explains above how to handle this

true bison
#

currently we are showing saved cards in the custom ui and making payments directly in the backend...

worldly vessel
#

yes I know.

true bison
#

If we use payment elements or checkout, will saved cards be displayed?

worldly vessel
#

are you asking a different question now? so your previous issue is resolved?

true bison
#

No, if we use payment elements or checkout, authentication for payment will be handled in the frontend. However, based on my observation, saved cards will not be displayed in the payment elements or checkout.

#

understood ?

worldly vessel
#

you are mixing completely different issues here.

  • if you want to confirm the payment on the backend, that is possible! you just need to handle the case where 3DS is requested (as I explained previously)
  • if you don't want to confirm the payment on the backend, then you can confirm it on the frontend (this is the recommended flow).
    so which option do you want?
#

If we use payment elements or checkout, will saved cards be displayed?
Checkout can display a saved card yes. Not with Payment Element currently, but you could build your own UI for this.

true bison
#

do we have any demo link?

worldly vessel
true bison
#

This means that we will notify the user to open the app, where we will display a popup with the same payment intent secret. The user can then accept it

worldly vessel
#

correct. and when you call the function above, the 3DS flow will start.

true bison
#

Are there any restrictions, such as needing to display it within the same domain?

worldly vessel
#

no, as long as you use the correct Stripe API key

true bison
#

so, we can send emails to that action ?

#

like we can show that custom ui in the email itself

worldly vessel
#

I'm not sure I understand. but yes you can send your own emails, with a link to your website, that then calls stripe.confirmCardPayment().