#felix_webhooks

1 messages ยท Page 1 of 1 (latest)

real hornetBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1329121587177459725

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

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.

torn cradle
#

Hello, I'm currently facing the problem, that i cannot get the product id from the checkout.sesssion.completed data, is there a way to attach this id to the webhook event?

visual falcon
torn cradle
#

The parameter to pass is the session.completed id?

visual falcon
#

cs_ id

torn cradle
#

I got it, but it doesn't respond with the product id, it's responding with a list id.

#

Ahhh, my fault, it's inside the price object i guess, sorry ^^

#

The product name ist not included as I can see, is there a way to get it?

visual falcon
#

product is expandable, so yeah

#

You'd need to expand data.price.product when listing the line items

torn cradle
#

Im struggleing to expand it, i used the session id, but i think i used the wrong request string, which one would be valid?

#

data.object.price.product?

visual falcon
#

Should be data.price.product

#

Is that not working

#

Can you share the request id?

real hornetBOT
torn cradle
#

let product = await stripe.checkout.sessions.retrieve(event.data.object.id, {expand: ['data.price.product']})
event.data.object.id = chekout session completed id

visual falcon
#

Oh you used the wrong api endpoint

#

That's for retrieving checkout session

#

Which only retrieves the line items

#

You can do it with that endpoint, but the expand clause will be different since it's nested further in

#

Try

  event.data.object.id,
  {expand: ['data.price.product']}
);```
torn cradle
#

I got it, thank you for your help ๐Ÿ™‚

visual falcon
#

No problem!

torn cradle
#

One more question, if the payment_intent is null at the checkout.session.completed event, how to get the payment method, the customer used for this session?

#

I guess expanding smth right? ๐Ÿ˜‚

strong aspen
#

Hello! I'm taking over and catching up...

#

Can you give me an example Event ID so I can take a look?

torn cradle
#

cs_test_a1yrIAI1lbyRf5JJJcyJKpCdq8hoyrlcajhEO6mgj5ywAKNC2FxVGqOEKg

#

`// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
const stripe = require('stripe')('sk_test_51QhBihHFUFRS6hPEeQikTxDnKytfyDA6M7ovVK7s3zXKIg6r4NLXGEJAqSP7Jxh6DlEjKZCHRiztbevkO9wlSzHa00OnyUvz0c');

const session = await stripe.checkout.sessions.retrieve(
'{{SESSION_ID}}',
{
expand: ['payment_intent.payment_method'],
}
);`
Just like you documented i guess

#

But it's kind of weird, that this information needs to be fetched afterwards

strong aspen
#

Ah, this Checkout Session is in subscription mode, so it doesn't have a Payment Intent directly associated with it. Instead, it has a subscription. That Subscription will have a latest_invoice, and that Invoice will have a payment_intent.

torn cradle
#

So I can expand the invoice to get the payment_intent?

strong aspen
#

So, instead of expanding payment_intent.payment_method it sounds like you would want to expand subscription.latest_invoice.payment_intent.payment_method

#

Yep!

torn cradle
#

Is this valid: let paymentIntent = await stripe.checkout.sessions.retrieve(event.data.object.id, {expand: ['invoice.payment_intent']}); ?

#

Invoice is expandable but waht about the intent if I use the current session?

torn cradle
strong aspen
#

Yeah, you could do it that way too if you don't want any of the Subscription info.

torn cradle
#

And I guess I need to extend the payment method again to get the method? Like PayPal etc?

strong aspen
#

Yes.

torn cradle
#

You wrote it already, sorry..

strong aspen
#

No worries!

torn cradle
#

Is it not recommended to use multiple "retrieve" or "listLineItems" requests, is there a smarter way or is it just fine?

strong aspen
#

Not sure I understand. Not recommended by whom?

torn cradle
#

In general in cause of request flooding.

strong aspen
#

Just to make sure I understand, you're receiving checkout.session.completed Events, and when that happens you want to fetch the line items, Product info, and payment information, correct? If so, you need to make the requests to retrieve the information that's not in the Event when you receive it. There's no other way for you to get the data.

torn cradle
#

I gotchu

#

Is the customer.subscription.deleted event fired, if the recurring payment cannot proceed?

strong aspen
#

No, that Event is only fired if the Subscription is canceled.

torn cradle
#

But it's fired if the sub gets canceled in cause of the auto canceling if the payment can not proceed within the timeperiod set?

strong aspen
#

If that's how you have it configured, yes. But not everyone has Subscriptions configured to cancel after all payment attempts fail.

torn cradle
#

Okay, thank you all for ur help, I'm new to stripe ^^

strong aspen
#

No problem, happy to help!

torn cradle
#

Is there a kind of "sub.renewed" event, cant find smth about it.

strong aspen
#

The Subscription will generate a new Invoice every period, so you can listen for the various invoice.* Events.

#

There will also be customer.subscription.updated Events due to the changes on the Subscription itself.

torn cradle
#

Yes already thought about this method, okay, should work out, ty again hahahaha

strong aspen