Reputation: 275
I have a very basic website that runs a stripe checkout with 2 product. This all works fine and I am able to sell products and they appear in the dashboard. Now I want to automate the whole shipping process and get the shipping address for each new purchase along with what was purchased. I can get the address through the stripe API but I can't find any GET commands that can tell me which product sku was ordered along with the Charge. This seems like something that should be pretty easy to find out? It shows up in the web GUI dashboard but not in the web requests. I've read through the documents here https://stripe.com/docs/api but I'm not finding much help.
I have a working web request in python that can return all of my charges that were created but it has no product info.
Upvotes: 3
Views: 1212
Reputation: 275
Alright I found out how to do it. It's a little convoluted and should be streamlined by stripe but here is how you can do it.
First requests a list of events like this (I'm using python)
import stripe
foo = stripe. PaymentIntent.list(type='checkout.session.completed',limit=10)
Once you get the events you can find the payment intent buried inside of the json object.
payment_intent = foo['data']['object']['payment_intent']
Once you have a payment intent you can retrieve the payment_intent object from stripe like this
charges = stripe.PaymentIntent.retrieve(payment_intent)['charges']['data'][0]
which will yield a charges object that has all the billing data in it.
Now to the get the product that was ordered from that payment intent. This can be found in the event object at
item = events['data'][<insert or loop over this list element>]['data']['object']['display_items'][0]['sku']['attributes']['name']
And doing this you can get the shipping and item that was sold.
Upvotes: 1