reactjswebsocketstripe-paymentsfastapimiddleware

Best way to update user infos in frontend from stripe webhook


I am currently finalizing a payment system in my ReactJS - FastAPI web app, and I'm facing a problem.

Indeed, I use stripe for payments and I use the stripe webhooks system to update the user infos in the db (like the current plan, the period, if the user plan is active or not etc.).

However, the problem with that is that then, some events are asynchronous and not come from a frontend request (payment renewal fail, end of trial period, upgrade at the end of billing cycle etc.), which means that the frontend does not "receive" the changes.

The problem with that is that if it happens while the user is still connected, I don't find the cleanest way to update the user infos saved in frontend (stored with redux states in my app).

So I'd love to have some explanations about it, cause I don't know how people commonly handle that !

Indeed I thought about a few things :

Thanks in advance for your replies !


Solution

  • Finally the best option was to directly send websocket messages to the appropriate room when an update is done from stripe webhook so that when the user connects to the frontend his account is automatically updated thanks to the ws pending message.