Get purchased product from PaymentIntent

Viewed 962

in my app i want to list past purchases for a stripe customer. So I was looking at the relevant API objects like PaymentIntents, Sessions or Charges. But they all do not seem to contain any reference to Product or Price, which I would need to list the purchased products.

Subscriptions contain a list of items that are contained in that subscription, so I was expecting PaymentIntents to have something like that too.

Does anyone has an idea how to archive my list of past purchases? Thanks!

1 Answers

I did some digging through the Stripe API docs[1] and, out of the three objects you referrenced (PaymentIntent, Session, Charges), the only one that I can see being able to trace back to a product is the Session.

Session objects have a line_items property[2] which can be followed all the way down to line_items.data.price.product[3]. To access this you’ll need to inlcude the expand=["data.line_items"] parameter to your call to list Checkout Sessions. You can read more about expanding API responses here[4]

So for all the charges to your customers that were done using Checkout Sessions, you could list them all, use the customer property to associate earch session with a customer in your application, traverse the the returned data, and then query the API for the product details. If you have a lot of customers & products these API calls will add up fast so I would store this data in your back-end to avoid hitting rate limits[5].

Alternatively, you could just save the product ID (either Stripe or your local version) as metadata[6] for any of the above Stripe payment objects listed. That would allow you to link any payment object you wish to a product.


  1. https://stripe.com/docs/api
  2. https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
  3. https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product
  4. https://stripe.com/docs/expand
  5. https://stripe.com/docs/rate-limits
  6. https://stripe.com/docs/api/metadata
Related