Ask Question

How can I prefill the email address of the user in the Stripe Checkout Form?

I am using the Stripe Checkout form to let my users pay for their subscription of my SaaS.

In the form the user has to provide its email address. As I already know the email address of the user I would like to save him the extra step and prefill it for him. Is that possible?

JavaScript

5893 views

AuthorΒ΄s Dominik Sumer image

Dominik Sumer

πŸ‘
1
Last edited on

1 Answer available

Best answer

Usually you're creating (or retrieving) a stripe customer when handling subscriptions. When you're creating the stripe customer in the first place you can provide the email address of the user. Then, when you pass the customer to the checkout creation api, the email address field will automatically prefilled.

Here is a code snippet for this:

const customer = await stripe.customers.create({
  email: user.email,
  name: user.displayName,
});

const session = await stripe.checkout.sessions.create({
  mode: 'subscription',
  customer: customer.id, // here you pass the id of the customer
  // other configuration options follow here
});
πŸŽ‰
1