retrieve customer email on stripe after checkout session node.js

Viewed 289

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?

1 Answers
Related