Sort order for Stripe websites
I am currently building a node app using Stripe for payments. I have settings and webcams working as I want to create subscribers in my application, but to respond to requests from networked websites to store data received for different events in different collections in my mongo db.
The problem I'm running into is that the order of events dispatched by Stripe is not always in the same order and creating document / collection relationships requires event handlers to fire in the following order:
- customer.created
- client.card.created (client specific)
- invoice.created (client specific)
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 that my handlers are executed in the correct order every time? I think there are promises of some kind. If so, what's a good module for node?
source to share
You can dismiss the hook if the event is missing, stripe will try it later, but if you want it to happen quickly, you can do a little loop waiting for a maximum of 10 seconds and who checks every second if there is no event received with an error).
I have the same problem when updating the fill plan, the invoice.updated event arrives before invoice.created ...
source to share