how to get items purchased by customer with stripe on success page

Solution 1:

Instead of making several seperate API calls to get the customer, to get their history from the past certain amount of time, you can ask the API to return the line_items in the first request to retrieve the session object.

Bad

router.get('/success', passport.authenticate('jwt', {session: false}), async (req, res) => {

  const session = await stripe.checkout.sessions.retrieve(req.query.sessionId);
    
  // More requests, etc..
}

Better

router.get('/success', passport.authenticate('jwt', {session: false}), async (req, res) => {

  const session = await stripe.checkout.sessions.retrieve(req.query.sessionId, {
    expand: ['line_items'],
  });
    
  // etc..
}

This gives you back what they just purchased, so you can congratulate them on the success page much more easily.