#mackan-cehckout-session
1 messages · Page 1 of 1 (latest)
Can you clarify that last sentence? You want to get the Checkout Session that a discount was used for?
I want to get the customer-facing discount code that was used in a checkout session
If you expand total_details.breakdown you can get the a list of discounts in the with total_details.breakdown.discounts.discount property
https://stripe.com/docs/api/quotes/object#quote_object-total_details-breakdown-discounts-discount
And then from there you can look up the discount object and expand itspromotion_code property to get the code https://stripe.com/docs/api/discounts/object#discount_object-promotion_code
So I need to send a request to get the code?
Correct, you need to do additional API lookups, all of that is not present in just what the webhook sends
Alright, thanks!
Right, trying to expand it, I only get the issue StripeInvalidRequestError: This property cannot be expanded (promotion_code)
I'm using the stripe-node package, getting the coupon ID from a request to get a checkout session;
Getting the session;
const session = await stripe.checkout.sessions.retrieve(sessionId, {
expand: [ 'line_items', 'line_items.data.discounts', 'payment_intent', 'total_details.breakdown' ],
})
And getting the coupon;
const discounts: Stripe.Checkout.Session.TotalDetails.Breakdown.Discount[] = session.total_details?.breakdown?.discounts as Stripe.Checkout.Session.TotalDetails.Breakdown.Discount[]
const coupon = await stripe.coupons.retrieve(discounts[0].discount.coupon.id, {
expand: ['promotion_code'],
})
The second request works fine without the expand parameter
Whoops I now see that I linked you to a delete call. It looks the coupons.retrienve response does not have promotion_code at all
Looking in to the proper call again, my apologies
No worries!
I am getting the api id of the promotion from my session retrieval though, is that something I'm able to leverage?
Great to hear!
On another note, is there any way for customers to enter multiple promo codes on the hosted checkout page? Would be good to know if I need to account for that in my implementation
I also looked at https://stripe.com/docs/api/discounts/object again, the example response has the code in the metadata field, is that something I can retreive from my session?