Hacker News new | ask | show | jobs
by ravirajx7 1426 days ago
I think this is absolutely correct time to ask something to the people who have worked on this kinda integration. Currently we have a PSP which gives a webhook on successful payment. The challenge here is once I receive webhook (which is a stateless POST request to one of our server) we want to attach it to a browser with an open websocket connection. I have to make a redirect now what do you think is an ideal way to make it? Currently I am posting it directly to the notify page which is waiting for success/failure response. But the problem here is I don't have any mechanism through which I could make a post request directly with the browser context as well as redirect without explicit post(which ofcourse displays payload - think success/fail response). Can you provide a better way for handling the redirect here with form post?

To make things more clear we have our client which wants to display a QR hosted on a different service where it comes via http redirect on requesting one of the server API - then this service gets the webhook & it has to redirect back to the client again with the payment status/webhook response.

2 comments

Set up a Redis pub-sub: https://redis.io/docs/manual/pubsub/

The code for the websocket subscribes to Redis. The webhook will publish to Redis.

The sequence of actions is now that you send the client to the PSP, which will hit the webhook, that publishes to Redis, that the server side of the websocket is receiving, that realizes it should send the message to the client, that receives the message from the websocket, that then tells the client to redirect.

I was about to talk about issues with scaling Redis pubsub but apparently they just recently published a newer version (7) with proper sharding support in cluster mode!
You do have to be aware of Redis' limits. But for most sites, "people paying at the moment" is well within them. And Redis is the easiest solution to implement from scratch.

That said, if you're deployed in a cloud, look up cloud specific messaging services. Specifically AWS SNS, Google PubSub and Azure Web PubSub. But the pattern remains the same. The webhook publishes to the PubSub which finds the other end of the websocket which sends information to the client that does something with it.

I think my solution in another comment here would work for you: https://news.ycombinator.com/item?id=32138881