#escardalda
1 messages · Page 1 of 1 (latest)
How can I help?
Hello! I need help with webhooks. I am doing a checkout session to pay for a subscription and I have a little problem with webhooks. When I make the checkout request I save the chekoutsessionid in the DB and when I receive the "checkout.session.completed" event I search by the ID and save the subscription ID in the same table.
This way, when the rest of the subscription events arrive I can save the information correctly in DB.
What is happening to me is that sometimes the subscription events arrive first than the session checkout event and I cannot make the link between them and I don't know which database record I should edit.
How can I link my checkout session request to subscription events if I don't receive the "heckout.session.completed" event first?
Excuse me, I have an emergency and I'm going to have to go out. You can close the thread and tomorrow I will write to you again or else tomorrow I will review the thread and respond.
Thank you and sorry for the inconvenience.
Yeah sorry about the delay
things are running busy
I'll try and respond before closing out, feel free to refer to the answer later on and ask a follow up if unclear
Thank you! And don't worry, I understand that you are busy, there are many of us asking questions hehe
One option here would be to not listen to customer.subscriptions.* events when you create a subscription.
You can just rely on the checkout.session.completed event for subscription creation.
When you receive that event, you can look up the subscription it is linked to by expanding the subscription parameter
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-subscription
That should get you the information about the subscription without needing to listen to customer.subscriptions.* events.
More info on subscription webhooks: https://stripe.com/docs/billing/subscriptions/webhooks