#charisma2761

1 messages ยท Page 1 of 1 (latest)

gritty spindleBOT
#

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

modern ingot
#

Hey there

main veldt
#

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

modern ingot
#

So you want to know if they used a promo code during the Checkout Session?

main veldt
#

No, I just want to know which products were bought with that 100% off

modern ingot
#

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

main veldt
#

I did the expand but line_items are not showing when I apply the promo code

modern ingot
#

Can you show me the JSON that you see when you retrieve here?

main veldt
#

Sure

modern ingot
#

Hmmm I don't see you retrieving any Checkout Sessions server-side in your test logs.

main veldt
#

To mean?

modern ingot
#

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?

main veldt
#

Yes in a webhook handler

modern ingot
#

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

main veldt
#

The code is like this
const session = await stripe.checkout.sessions.retrieve(webhookData.id, { expand: ['line_items', 'line_items.data.price.product', 'payment_intent'], })

modern ingot
#

Can you show me the full snippet

#

Like the entire relevant piece of the Webhook handler

gritty spindleBOT
main veldt
#

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

modern ingot
#

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

main veldt
#

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

arctic marsh
#

๐Ÿ‘‹ 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?

main veldt
#

I can now see the line items

#

I don't know what was wrong but all is fine now

arctic marsh
#

oh awesome! glad to hear it's working ๐Ÿ™‚

main veldt
#

Thanks for the help