#felix_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ 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.
- felix_webhooks, 17 hours ago, 9 messages
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?
Since line_items (which contains the product(s)) isn't expanded by default, you'll need to make an api call to retrieve the line items: https://docs.stripe.com/api/checkout/sessions/line_items
The parameter to pass is the session.completed id?
cs_ id
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?
product is expandable, so yeah
You'd need to expand data.price.product when listing the line items
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?
let product = await stripe.checkout.sessions.retrieve(event.data.object.id, {expand: ['data.price.product']})
event.data.object.id = chekout session completed id
Oh you used the wrong api endpoint
That's for retrieving checkout session
I suggested you use: https://docs.stripe.com/api/checkout/sessions/line_items
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']}
);```
I got it, thank you for your help ๐
No problem!
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? ๐
Hello! I'm taking over and catching up...
Can you give me an example Event ID so I can take a look?
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
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.
The short video here might be worth a watch to help you get a feel for how everything fits together: https://stripe.com/docs/payments/tour#payment-objects
So I can expand the invoice to get the payment_intent?
So, instead of expanding payment_intent.payment_method it sounds like you would want to expand subscription.latest_invoice.payment_intent.payment_method
Yep!
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?
Or is it impossible in cause of this
Yeah, you could do it that way too if you don't want any of the Subscription info.
And I guess I need to extend the payment method again to get the method? Like PayPal etc?
Yes.
You wrote it already, sorry..
No worries!
Is it not recommended to use multiple "retrieve" or "listLineItems" requests, is there a smarter way or is it just fine?
Not sure I understand. Not recommended by whom?
In general in cause of request flooding.
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.
I gotchu
Is the customer.subscription.deleted event fired, if the recurring payment cannot proceed?
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?
If that's how you have it configured, yes. But not everyone has Subscriptions configured to cancel after all payment attempts fail.
Okay, thank you all for ur help, I'm new to stripe ^^
No problem, happy to help!
Is there a kind of "sub.renewed" event, cant find smth about it.
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.
Yes already thought about this method, okay, should work out, ty again hahahaha
On the *.updated Events there will be a previous_attributes property so you can see what changed in the update. https://docs.stripe.com/api/events/object#event_object-data-previous_attributes