#Ritchie
1 messages · Page 1 of 1 (latest)
The ordering of webhooks will generally (though not always) align with the ordering of events. We don't recommend building anything that depends on the ordering of events for this reason
Not sure if that answers your question though. Feel free to fill in with more detail if that answer isn't sufficient
When I receive invoice.updated, I check if the invoice exists in my database before updating it. Otherwise, I insert it
I also update on events such as invoice.finalized and invoice.paid
Here's the order of events when I create a subscription from a checkout session:
It fails because it thinks the invoice doesn't exist, so attempts to create it. But by the time that query runs, it fails because the invoice does exist
The other events succeed. Maybe it's just a timing issue
Yeah, I think this is just a classic race condition. Also, it seems like maybe you're auto-advancing the Invoice through payment, so you shouldn't need to manually finalize it, right?
Right. Yeah, I create subscriptions through a checkout session. All the events occur when the checkout session is complete, I don't manually finalize it
I'll push the events to a queue and make sure they're handled sequentially
That would likely be the best solution, for sure
Thanks for your help!