How to Access Bangladesh Payments API?Developer Tutorials for Beginners

How to Access Bangladesh Payments API?Developer Tutorials for Beginners

I. Overview of the Bangladesh Payments Market

As one of the fastest growing economies in South Asia, Bangladesh's e-payments market has boomed in recent years. With increased smartphone penetration and improved internet infrastructure, more and more businesses and developers are looking to access localised payment solutions. In this article, we will introduce in detail how to access the mainstream payment APIs in Bangladesh from the technical level.

II. Preliminary preparatory work

1. Choosing the right payment service provider

The major payment gateways operating in Bangladesh include:

  • bKash (largest market share)
  • Nagad (government-backed digital wallet)
  • Rocket (part of Dutch-Bangla Bank)
  • Upay
  • SureCash

2. Register for a merchant account

Visit the official website of the selected provider and complete the following steps:

  1. Submission of business registration documents
  2. Fill in the application form
  3. Waiting for review (usually 3-7 working days)
  4. Get Merchant ID and API Key

3. API documentation access

After successful registration, log in to the merchant back office to download the latest version of API documentation. Most providers support RESTful API interfaces.

III. Development Environment Configuration

1. Basic requirements

- HTTPS protocol (SSL certificate required) 
- IP whitelist setting (required for some platforms)
-Server time zone set to UTC+6 (Dhaka time)

2. SDK installation (PHP as an example)

// Install the official SDK via Composer. 
composer require bkash/api-client

// or manually introduced
require_once 'path/to/bKashApi.php';

Other languages such as Python/Java/Node.js also have corresponding SDKs available.

Fourth, the core API docking process

The following are typical integration steps:

1. authentication

//Example: Getting an access token 
const authResponse = await fetch('https://api.bkash.com/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'username': '[YOUR_MERCHANT_USERNAME]',
'password': '[YOUR_API_PASSWORD]'
},
body: JSON.stringify({ grant_type: 'client_credentials' })
});

2. Creating a transaction request

# Python Example - Initiating a Payment Request  
import requests

payload = {
"mode": "0011", # test mode code
"payerReference": "INV12345".
"callbackURL": "https://yourdomain.com/callback",
"amount": "500",
"currency": "BDT".
"intent": "sale"
}
headers = {
"Authorization": "Bearer [ACCESS_TOKEN]",
"X-App-Key":"[APP_KEY]"
}
response=requests.post("https://api.bkash.com/create",json=payload,headers=headers)

3. Handling callback notifications

All transaction status changes are notified via webhook:

// Java Spring Boot Receive Callback Example  
@PostMapping("/payment/callback")
public ResponseEntity handleCallback(@RequestBody CallbackData data) {
if(data.getStatus().equals("Completed")){
// Update order status to paid
} else {
//Documentation of reasons for failure
}
return new ResponseEntity("OK", HttpStatus.OK);
}

4. Enquire about transaction results

Even if you receive a callback you should proactively enquire for confirmation:

$transactionId="TRX789012".  
$queryUrl="https://api.nagad.com/query/".$transactionId;
$ch=curl_init($queryUrl);
curl_setopt($ch,CURLOPT_HTTPHEADER,[
'Authorization:Bearer '.$accessToken,
'X-Merchant-ID:'.$merchantId
]);
$result=curl_exec($ch);
/* Returns JSON format.
{
"statusCode": "0000",
"amount": "1000",
"trxTimestamp": "2023-05

V. Testing and use of sandbox environments

1. Obtaining test vouchers

All major payment platforms offer a sandbox environment:

Required for application:

- Test mobile phone number (to receive verification code)
- Virtual Merchant ID
- Simulate API key

2.Common Test Scenarios

use case Amount tested (BDT) Expected results
microfinance 10-100 prompt settlement
Large transactions 5000+ OTP authentication may be required
Duplicate Order ID Any amount should return an error
expired session Time-out paymentID |Transaction expiry alert|Transaction expiry alert
# cURL test example (Nagad)
curl -X POST \
https://sandbox.mynagad.com/api/checkout \
-H 'Content-Type: application/json' \
-d '{
"merchantId": "TEST001".
"invoiceNumber": "DEMO123".
"amount": "50.00"
}'

VI. Production environment on-line checklist

Complete the following steps before switching to the official environment:

  1. SSL Certificates Pass PCI DSS Compliance Testing
  2. IP whitelisting has been configured in the payment platform backend
  3. Webhook endpoint stress test (200+ TPS support recommended)
  4. Reconciliation module integration completed
  5. Bangla language error message localised

VII. Special considerations

1.Bangladesh Local Compliance Requirements

-Must keep transaction records for at least 5 years  
-Transactions over 5,000 BDT require submission of additional authentication
-Banning access to high-risk industries such as gambling/adult content

2.Currency & Fees

Comparison of rates for major payment methods:

Payment Fee Comparison
(Note: Pictures need to be replaced with actual data charts)

bKash → 1.85% + VAT    
Nagad → Fixed 15 BDT/pen
Rocket → Corporate accounts negotiable up to 1%
Credit Card Access → 3%-4% (not recommended)

VIII. Troubleshooting Guide

Reference when the API returns an error:

HTTP Status Code Analysis

Table: Comparison of common error codes

| coding | hidden meaning | prescription |
|----|----- ----|----- ------|
401 Authentication failure ⇒ check if timestamp is in UTC+6 time zone
403 IP not authorised ⇒ contact customer service to add server IP
429 Request flow limiting ⇒ reduce call frequency or request quota increase
503 Service Maintenance ⇒ view official status page (status.nagad.com)

// Example of typical error handling logic (bKash)
try {
const payment = await bkash.createPayment(params);
} catch (error) { //catch a business-specific exception

if(error.code === 'INSUFFICIENT_BALANCE'){
alert("The user's wallet balance is insufficient");;
} else if(error.code === 'TX_TIMEOUT'){
console.log("This order has expired, please re-initiate it");
}
}

ix. best practice recommendations

Based on our experience of matching 50+ local businesses:

✔️ hybrid integration strategy
Simultaneous access to at least two payment channels (e.g. bKash + Nagad) to avoid a single point of failure affecting revenue.

✔️ Intelligent Route Optimisation
Automatic channel switching based on real-time success rates:

if(number of bkash failures > 3){  
fallbackTo(nagadAPI).
}

✔️ Enhanced localisation experience

  • Adjustment of business hours display during Ramadan
  • UI adapted to right-to-left reading habits (Bengali interface)

For more detailed code examples or platform-specific docking manuals, feel free to visit our developer community [link] for the latest resources. This article will continue to be updated to reflect the new regulation changes in Bangladesh Central Bank in 2024.