Using Server-Sent Events for payment confirmation
Polling is not always the best experience for mobile payment confirmation.
While working on a project using Expo, I implemented a payment flow that listens for confirmation through Server-Sent Events.
After payment begins, the app opens an authenticated event stream using the merchant reference. When a successful event arrives, it:
- Stops the pending state
- Updates the payment result
- Closes the connection
- Makes the generated waybill available
- Moves the user into the next part of the workflow
The flow also handles malformed events, connection errors, cleanup when the screen unmounts, and a five-minute timeout when confirmation never arrives.
What I like about this feature is that it connects several parts of the product: payment, status, checkpoints and QR-verifiable waybills.
The result for the user is simple: make the payment and see the trip become ready without manually refreshing the screen.
Originally shared on LinkedIn.