#mhiggie-order
1 messages · Page 1 of 1 (latest)
hey just confused about how to get orders in general
we are using checkout-sessions
or can you send me the customer ID?
curious if we are supposed to create a customer during that checkout-session
cus_L1poHwHcHi0zoj
we are in a test environment
for context, in this project we r making a simple ecomm platform
users checkout using stripe checkout-sessiosn
and we want to show the past orders of a specific user BUT we are not receiving a customer ID in the response of creating a checkout-session
OK, thanks for letting me know the background. Btw the order API is very old, and I'll recommend using the price/product API instead
Here's what I'd recommend
- use the Product/Price API to create a price
- use the Customer API to create a customer object
- Pass the price and customer to the Checkout Session API
- listen for the
checkout.session.completedand you will get the customer and price in the checkout session event data object.
https://stripe.com/docs/payments/checkout/fulfill-orders this doc should help you
currently we are holding product/pricing data in our own db
then passing the cartItems through the checkout session
why do we create product/Price api?
once we get the id from the checkout session response we plan to save it to our user in db
what api call can we make to get past orders for that user if Orders is depricated?
How do you associate the product/price saved in your DB with Stripe?
we add it to the line items of the checkout session
I guess you are using line_items.price_data when creating checkout session?
yes
OK, it works as well. If you have existing Stripe price objects then you can pass them via the line_items.price param
okay cool
everything works (we can see customer purchases on test dashboard) BUT the session-checkout does not return the stripe customer Id, which we need so user can see orders history
how do we solve those two issues?
Do you pass a customer ID when creating the session?
no
so i should create a customer first, then grab the id from customer create response, and pass to session
or should i pass the user id from our own db
I'll suggest creating a Stripe customer object and associate it with your user in your DB, so when you are about to create a checkout session, you can get the customer ID from your user DB and then pass it to the Stripe Checkout Session API/
epic
thank you
second issue, we have the customer id now. Great. how do we use it to get past orders for that user
The Stripe API doesn't keep track of the past purchased items for a customer, it only keeps the past payment history. I think it'll be easy to keep the record in your own DB.
ohhhhhhh
wow hah
kk we can do that
awesome thank you Jack!
Have a great rest of ur day
Happy to help 🙂