gianlps
gianlps

Reputation: 207

retrieve customer email on stripe after checkout session node.js

I have this:

    app.get('/create-checkout-session', async (req, res) => {
    let customer = {
        price: req.query.price,
        quantity: req.query.number,
        page: req.query.page
    }

    let successurl = 'http://localhost:1111/' + customer.page + ''
    let failedurl = 'http://localhost:1111/' + customer.page + ''
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: [
      {
        price_data: {
          currency: 'cad',
          product_data: {
            name: 'Giveaway Entry',
          },
          unit_amount: customer.price,
        },
        quantity: customer.quantity,
      },
    ],
    mode: 'payment',
    success_url: successurl,
    cancel_url: failedurl,
  });
  console.log(session)

  res.redirect(303, session.url);
});

it is working fantastic. Except that after the checkout session completes, it redirects me back to my page. But it doesn't store the email address that they type in (on the stripe checkout page) in the session object. so I logged it like this:

console.log(session)

and it returns:

customer_email: null

why is this happening and how can i fix it?

Upvotes: 3

Views: 1578

Answers (1)

Pompey
Pompey

Reputation: 1354

The Checkout Session's customer_email property is for creating a Checkout Session with an email pre-filled[1]. To see the email that your customer entered in to the Checkout form, check the Session's customer_details.email property[2].

[1] https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-customer_email

[2] https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-customer_details-email

Upvotes: 3

Related Questions