Integrating bKash Payments Securely in Your Web App
How the bKash checkout flow works, where developers usually go wrong, and how to confirm every payment on your server.

Understanding the Checkout Flow
A bKash checkout has three main stages. Your server first requests a token, then creates a payment with the amount and an invoice number, and bKash returns a page where the customer enters their number, OTP and PIN. After that, bKash sends the customer back to your callback URL, and your server must execute the payment to complete it. The important detail is that all of these calls belong on the server. Your app key and secret should never appear in frontend code.
Never Trust the Callback Alone
A callback that says success only tells you what the browser was sent. Before marking an order as paid, execute the payment on your server, compare the returned amount with the order total stored in your database, and save the transaction ID. If the execute response times out, use the query endpoint to check the real status instead of assuming the payment failed. Otherwise, a customer can be charged while the order stays unpaid.
Handling Duplicates and Refunds
Customers refresh pages and double-click buttons, so your callback handler must be idempotent. Store each payment ID with a unique constraint and return early if it has already been processed. Keep tokens cached until they expire rather than requesting a new one for every order. Finally, build refunds into the admin panel from the start, and record who issued each one. Sandbox testing should cover success, failure, cancellation and insufficient balance before you switch to live credentials.
What I check before going live
Sandbox success tells you very little on its own. Before launch I test a cancelled payment, a failed PIN, a closed tab mid-payment and a double click on the pay button. I also confirm that refunds work and that finance can match each transaction ID to an order. These cases are boring to test, and they are exactly where real support tickets come from.