Skip to content

February 2025 · Payments · MERN · SSLCommerz · Security

Building Secure Payment Flows with SSLCommerz

What I learned integrating SSLCommerz into a MERN store: why the browser cannot be trusted, and how to make sure a paid order is never lost.

Building Secure Payment Flows with SSLCommerz

Why local gateways matter

On my MERN e-commerce project, Stripe alone was not enough, because customers here pay with bKash, Nagad, Rocket and local cards. SSLCommerz covers those through one integration. The integration itself is not long. Getting it right is what takes the time.

Never trust the total from the browser

If the front end tells the gateway how much to charge, anyone with DevTools can change it. So the client only sends a cart ID or items. The server loads real prices from the database, works out the total, saves a pending order, and only then starts the payment.

The success page is not proof

People close their browsers and connections drop. If you mark an order paid when the success page loads, some paid orders will be lost, and someone could also just visit that URL. SSLCommerz sends an Instant Payment Notification from its server to yours, and that is what should update the order, after you validate it.

Validate, then compare

When the IPN arrives, call the validation API with the ID it gave you. Then compare the amount and currency with the saved order. Only if they match is the order paid. Keep the raw response too. You will want it the first time someone disputes a payment.

Handle the second notification

The same notification can arrive twice. A unique constraint on the transaction ID and an early return for orders already paid will stop you from reducing stock or sending confirmations twice. This is the small detail that separates a demo from something you can leave running.

Md. Fawjul Azim

Focusing on building high-performance web applications with modern tech stacks.