#mackan-cehckout-session

1 messages · Page 1 of 1 (latest)

coral storm
pale swallow
#

Can you clarify that last sentence? You want to get the Checkout Session that a discount was used for?

hybrid maple
#

I want to get the customer-facing discount code that was used in a checkout session

pale swallow
hybrid maple
#

So I need to send a request to get the code?

pale swallow
#

Correct, you need to do additional API lookups, all of that is not present in just what the webhook sends

hybrid maple
#

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

pale swallow
#

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

hybrid maple
#

No worries!

#

I am getting the api id of the promotion from my session retrieval though, is that something I'm able to leverage?

pale swallow
#

Try that out and let me know

hybrid maple
#

Will do!

#

It worked and I see the code now! Thanks!

pale swallow
#

Great to hear!

hybrid maple
#

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

pale swallow
#

Checkout currently only supports one Coupon promo code at a time

#

That would be the coupon's metadata so if you set that manually I think you should be able to see it

hybrid maple
#

Ah! I'll give it a try!

#

It appears in the call to get the promo code, but not in the session discounts, any ideas?