Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe webhooks events order

I'm currently building a node application that's using Stripe for payments. I've got webhooks setup and working as I want to create subscribers in my application but require the response from the stripe webhooks to store the data received for different events in different collections in my mongo db.

The issue I'm having is that the order of events sent by Stripe is not always in the same order and in order to create relationships between documents/collections I require that the event handlers are triggered in the following order:

  1. customer.created
  2. customer.card.created (relates to customer)
  3. invoice.created (relates to customer)

As it stands the event handler for 2 can be executed before 1 and 3 before 2 etc.

What would be the best way to ensure my handlers are executed in the correct order every time? I'm thinking promises of some-sort. If this is the case, what's a good promise module for node?

like image 421
leaksterrr Avatar asked Sep 28 '22 03:09

leaksterrr


1 Answers

You can reject hook if an event is missing, stripe will try it later but if you want it to happen quick, you can make a small loop waiting for max 10 seconds and who checks every second if missing event is arrived).

I have same problem when updating a billing plan, the event invoice.updated arrives before invoice.created ...

like image 174
hugsbrugs Avatar answered Sep 30 '22 05:09

hugsbrugs