InquireAI / inquire

Inquire is a generalized chatbot ready to handle anything you throw at it.
https://inquire.run
MIT License
3 stars 0 forks source link

(web) handle stripe webhooks better #10

Closed ethan-stone closed 1 year ago

ethan-stone commented 1 year ago

Need to adjust stripe webhooks to handle events better. Especially the fact that the order of events is not guaranteed. Did not know this prior.

https://stripe.com/docs/webhooks/best-practices

I think the only place where this is a problem is when the checkout session completes. A subscription is created with the status incomplete, and then stripe attempts to charge the customer, and then immediately the subscription status is updated based on the result of the charge. Since these events are so close I think we should just ignore the customer.subscription.created event entirely and just listen for customer.subscription.updated and we both create and update the subscription in that one event.

I'll implement this tomorrow as described. @Lucas-Kohorst if you have a chance can you look into this and see if my thought process is sound. The webhook is in web/src/pages/api/stripe/webhook/index.ts

Lucas-Kohorst commented 1 year ago

interesting, this seems solid to me. One other point stripe mentions is that you can use the "API to fetch any missing objects". Even though just listening for customer.subscription.updated seems like a good way to do it, in the future could likely also integrate checks on missing objects?