#charisma2761
1 messages ยท Page 1 of 1 (latest)
Hello charisma2761, we'll be with you shortly! Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
โข charisma2761, 21 hours ago, 19 messages
Hey there
Hi
Sorry I found out I didn't specify the 100% I mentioned
I wanted to mean with a 100% off promo code, which means the customer will complete checkout but pay nothing
So you want to know if they used a promo code during the Checkout Session?
No, I just want to know which products were bought with that 100% off
Oh then all you should need to do is expand line_items
I'm not sure I understand in that case what the issue is
I did the expand but line_items are not showing when I apply the promo code
Can you show me the JSON that you see when you retrieve here?
Hmmm I don't see you retrieving any Checkout Sessions server-side in your test logs.
To mean?
Ah one sec
I missed it
Okay can you show me your exact code that you are running? And are you running this in a Webhook handler?
Yes in a webhook handler
Okay can you show me that code? My guess here is that you are logging out the Webhook's Event JSON instead of your retrieval request.
But hard to say exactly
The code is like this
const session = await stripe.checkout.sessions.retrieve(webhookData.id, { expand: ['line_items', 'line_items.data.price.product', 'payment_intent'], })
where webhookData.id is the the session id
Can you show me the full snippet
Like the entire relevant piece of the Webhook handler
It too long since it includes a lot of out BE after sale handling, but I can put the relevant together
Is there an api to retrieve a checkout session?
Online
May be on dashboard or something
You could use the CLI or you could make a cURL request if you just want to do this one-off not in your code to make sure it works
Got it!
paymentStatus = '',
resData: any = { status: 200, data: {} }, // IResponseObject
paidProductsDebug = {}
try {
const event = stripe.webhooks.constructEvent(rawBody, headerSig, webhookSecret)
console.log(`Incoming event: ${event.type}`)
// https://stripe.com/docs/api/events/types?lang=node#event_types-checkout.session.completed
switch (event.type) {
case 'checkout.session.completed':
webhookData = event.data.object as Stripe.Checkout.Session
paymentStatus = 'payment_succeeded'
break
case 'charge.dispute.closed':
webhookData = event.data.object as Stripe.Dispute
if (webhookData.status === 'lost') {
paymentStatus = 'refund_succeeded'
resData = await refundHandler(webhookData)
}
break
// case 'promotion_code.updated':
// webhookData = event.data.object as Stripe.Checkout.Session
// paymentStatus = 'promo_code_used'
// break
case 'charge.refunded':
default:
webhookData = event.data.object as Stripe.Charge
console.log(`Unhandled event type ${event.type}`)
}
if (paymentStatus === 'payment_succeeded') {
// retrieve session with expanded properties
const session = await stripe.checkout.sessions.retrieve(webhookData.id, {
expand: ['line_items', 'line_items.data.price.product', 'payment_intent'],
})
console.log(`${JSON.stringify(session)}`)
if (!session) {
throw new Error(`Checkout session ${webhookData.id} not found`)
}
}```
That's the relevant part I put together
๐ hopping in here since bismarck has to head out soon - give me a minute to catch up
What do you see when you log session.line_items right after retrieving the session?
oh awesome! glad to hear it's working ๐
Thanks for the help