简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM