Create Payment
POST /api/payments/create
Create a balance-recharge payment for your account. You receive a hosted payment URL — send your payer there, and after payment the payer is redirected to your custom success page.
Requirements:
- The hostname of your
success_url(andcancel_url, if used) must be registered on our side before use (contact support to allowlist your domain, e.g.shop.example.com). Requests with unregistered hosts are rejected with422. - Your account needs a valid Bangladeshi mobile number (
01XXXXXXXXX) in its profile; the payment gateway requires one for every payment. Without it the request is rejected with422.
Payers can pay with bKash, Nagad, Rocket, Upay and other mobile wallets, cards (Visa, Mastercard, American Express) and internet banking.
Request Parameters
Section titled “Request Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| amount | number | Yes | Amount in BDT. Minimum 20. |
| success_url | string | Yes | HTTPS URL on an allowlisted host. Payer is sent here after payment. |
| cancel_url | string | No | HTTPS URL on an allowlisted host. Payer is sent here if they cancel or the payment fails. |
Request Example
Section titled “Request Example”curl -X POST https://api.awajdigital.com/api/payments/create \ -H "Authorization: Bearer your_api_token_here" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d '{ "amount": 500, "success_url": "https://shop.example.com/payment/success", "cancel_url": "https://shop.example.com/payment/cancel" }'// Browser JavaScript (Fetch API)const response = await fetch('https://api.awajdigital.com/api/payments/create', { method: 'POST', headers: { 'Authorization': 'Bearer your_api_token_here', 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: 500, success_url: 'https://shop.example.com/payment/success', cancel_url: 'https://shop.example.com/payment/cancel' })});
const data = await response.json();console.log(data);// Node.js with axiosconst axios = require('axios');
async function createPayment() { try { const response = await axios.post('https://api.awajdigital.com/api/payments/create', { amount: 500, success_url: 'https://shop.example.com/payment/success', cancel_url: 'https://shop.example.com/payment/cancel' }, { headers: { 'Authorization': 'Bearer your_api_token_here', 'Accept': 'application/json', 'Content-Type': 'application/json' } });
console.log(response.data); } catch (error) { console.error('Error:', error.response?.data || error.message); }}
createPayment();# Python with requestsimport requests
def create_payment(): url = 'https://api.awajdigital.com/api/payments/create' headers = { 'Authorization': 'Bearer your_api_token_here', 'Accept': 'application/json', 'Content-Type': 'application/json' } data = { 'amount': 500, 'success_url': 'https://shop.example.com/payment/success', 'cancel_url': 'https://shop.example.com/payment/cancel' }
try: response = requests.post(url, json=data, headers=headers) print(response.json()) except requests.exceptions.RequestException as e: print(f'Error: {e}')
create_payment()<?php// PHP with cURL$url = 'https://api.awajdigital.com/api/payments/create';$token = 'your_api_token_here';
$data = [ 'amount' => 500, 'success_url' => 'https://shop.example.com/payment/success', 'cancel_url' => 'https://shop.example.com/payment/cancel'];
$ch = curl_init($url);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer ' . $token, 'Accept: application/json', 'Content-Type: application/json']);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);curl_close($ch);
$result = json_decode($response, true);print_r($result);?>Success Response Example
Section titled “Success Response Example”{ "success": true, "payment_url": "https://pay.example.com/checkout/23e02880-...", "invoice_id": "17941438309537516"}Redirect your payer to payment_url. After payment, the flow is:
-
The payment gateway returns the payer to our server first. The payer sees a short “confirming your payment” page while we confirm the payment with the gateway server-to-server and credit your balance — usually a few seconds, at most about 2 minutes.
-
We then redirect the payer to your
success_urlwith two query parameters appended:invoice_id— the payment referencestatus—completed(paid and credited) orpending(not confirmed yet)
A cancelled or failed payment goes to your
cancel_urlinstead (or tosuccess_urlif you sent nocancel_url), withstatusset tocancelledorfailed.
A payment that is still pending is credited by itself as soon as the gateway confirms it: the gateway notifies us directly, and we keep re-checking pending payments for 24 hours. A payment is never credited twice, however many of these confirm it.
Error Responses
Section titled “Error Responses”| Status | Description |
|---|---|
| 401 | Missing or invalid access token |
| 422 | Validation failed (amount < 20, non-https URL, non-allowlisted host, no valid mobile number on your account) |
| 502 | Gateway error — payment could not be created (safe to try again) |
