Search code examples
stripe-payments

Get the purchase history of a user including prices/items


I have a web application. Users need to buy different packs of credits to use this web application. For instance, one pack of 5000 credits costs 4.99 USD; one pack of 10000 credits costs 7.99 USD. I use Stripe to manage the purchase. I can use the following code to create a checkout session where users can adjust the quantity to buy priceId.

    const session = await stripe.checkout.sessions.create({
      customer: customer.id,
      mode: "payment",
      line_items: [
        {
          price: priceId,
          quantity: 1,
          adjustable_quantity: {
            enabled: true,
            minimum: 1,
            maximum: 10,
          },
        },
      ],
      success_url: successUrl,
      expand: ['line_items'],
    });

Then, given a user, I would like to write a function to get his purchase history. I'm thinking of using stripe.charges.list. But in a charge, we know the amount the user paid, we don't know what price/item he bought. Does anyone know how to solve that?


Solution