0

I'm using stripe and I'm trying to list all items the customer has bought, but logging those items returns undefined. What did I do wrong? And how does the listLineItems function work? (The session object is a stripe checkout session object.)

      if(event.type === "checkout.session.completed") {
        const session = event.data.object;
        var items =  await stripe.checkout.sessions.listLineItems(
        session.id,
        function(err, lineItems) {
        console.log(err);
        }
        );
         console.log(items);
      }
Luis
  • 23
  • 4

1 Answers1

1

You should wrap listLineItems call in a Promise to be able to await it:

const items = await new Promise((resolve, reject) => {
  stripe.checkout.sessions.listLineItems(
    session.id,
    { limit: 100 },
    (err, lineItems) => {
      if(err) {
        return reject(err);
      }
      resolve(lineItems)
    }
  )
})