API Documentation
Integrate PayIn and PayOut into your application using our simple REST API. All responses are JSON.
Download PHP Kit
Includes ready PayIn, PayOut and signature_v2 webhook verifier.
◈ Overview
Base URL
URL
http://www.chaopaopay.site/api/v1/
Request Format
All requests must be POST with Content-Type: application/json body. Responses are always JSON.
◇ Sandbox (Test Mode)
Test your integration end-to-end without moving real money. The sandbox mirrors the live API exactly — same endpoints, same callback signature.
Sandbox Base URL
URL
https://sandbox.chaopaopay.site/api/v1/
Demo Credentials
| Field | Value |
|---|---|
Merchant ID | M-SANDBOX |
API Key | pk_test_demo1234567890ab |
Secret Key | sk_test_demo1234567890ab |
Sandbox API keys always start with
pk_test_. Live keys are rejected in the sandbox and vice versa. Payins return a hosted checkout page that auto-completes the payment and fires a signed callback to your callback_url — verify it the same way as live.◆ Authentication
All API requests require the following HTTP headers.
| Header | Value | Required |
|---|---|---|
X-API-Key | Your API Key (from merchant panel) | Yes |
X-Merchant-ID | Your Merchant ID e.g. M2024XXXXXX | Yes |
Content-Type | application/json | Yes |
Secret Key is not needed for API calls — only for verifying incoming callbacks.
Example Headers
HTTP
X-API-Key: your_api_key_here X-Merchant-ID: M2024XXXXXX Content-Type: application/json
▦ Payment Channels
| Channel | Code | PayIn | PayOut |
|---|---|---|---|
bKash |
101 |
Supported | Supported |
Nagad |
102 |
Supported | Supported |
Rocket |
103 |
Supported | Supported |
Currency is always BDT. More channels may be added in the future.
↑ PayIn — Create Payment
POST
/api/v1/payin/create.php
Create a payment request and redirect your customer to the payment page.
Request Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
trx_id | string | Your unique transaction ID | Yes |
amount | decimal | Payment amount e.g. 100.50 | Yes |
method_code | integer | 101=bKash, 102=Nagad, 103=Rocket | Yes |
customer_name | string | Customer full name | Yes |
callback_url | string | Webhook URL for status notifications | Yes |
return_url | string | Redirect URL after payment completes | Yes |
customer_email | string | Customer email | Optional |
customer_phone | string | Customer phone number | Optional |
customer_address | string | Customer address | Optional |
description | string | Payment description / note | Optional |
Example Request
PHP
$data = [
'trx_id' => 'PAY-' . time(),
'amount' => 1500.00,
'method_code' => 101,
'customer_name' => 'John Doe',
'callback_url' => 'https://yourdomain.com/webhook/payin',
'return_url' => 'https://yourdomain.com/success',
'customer_email' => 'john@example.com',
'customer_phone' => '+8801234567890',
];
$ch = curl_init('http://www.chaopaopay.site/api/v1/payin/create.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-API-Key: YOUR_API_KEY',
'X-Merchant-ID: YOUR_MERCHANT_ID',
]);
$result = json_decode(curl_exec($ch), true);
if ($result['success']) {
header('Location: ' . $result['data']['payment_url']);
}
Success Response
JSON
{
"success": true,
"message": "Payment request created",
"data": {
"transaction_id": "TRX20241201ABC123",
"trx_id": "PAY-123456",
"amount": 1500.00,
"currency": "BDT",
"status": "pending",
"payment_url": "https://gateway.chaopaopay.dev/pay/..."
}
}
↓ PayOut — Withdrawal
POST
/api/v1/payout/create.php
Submit a payout request to send funds to a bKash or Nagad account.
Request Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
trx_id | string | Your unique transaction ID | Yes |
amount | integer | Withdrawal amount in BDT. Must be a whole number (e.g. 1000). Decimal amounts are not supported — the fractional part is dropped (e.g. 122.40 becomes 122.00). | Yes |
method_code | integer | 101=bKash, 102=Nagad, 103=Rocket | Yes |
account_number | string | Recipient wallet number | Yes |
account_name | string | Recipient full name | Yes |
notify_url | string | Webhook URL for status updates | Yes |
description | string | Payout note / reference | Optional |
Amount rules: Payout amounts must be whole numbers (decimals are dropped). The recipient receives exactly
amount; the merchant is charged amount + fee from their available balance. Gateway charges are separate and reported as gateway_fee in the callback.
Example Request
PHP
$data = [
'trx_id' => 'WIT-' . time(),
'amount' => 1000.00,
'method_code' => 101,
'account_number' => '01712345678',
'account_name' => 'John Doe',
'notify_url' => 'https://yourdomain.com/webhook/payout',
'description' => 'Commission payout',
];
$ch = curl_init('http://www.chaopaopay.site/api/v1/payout/create.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-API-Key: YOUR_API_KEY',
'X-Merchant-ID: YOUR_MERCHANT_ID',
]);
$result = json_decode(curl_exec($ch), true);
Success Response
JSON
{
"success": true,
"message": "Payout request submitted",
"data": {
"transaction_id": "TRX20241201PAY456",
"trx_id": "WIT-001",
"amount": 1000.00,
"fee": 20.00,
"net_amount": 1000.00,
"currency": "BDT",
"status": "pending",
"account_number": "017***5678"
}
}
⊙ Check Status
POST
/api/v1/transaction/status.php
Query the current status of any transaction.
Request
JSON
// By system transaction_id
{ "transaction_id": "TRX20241201ABC123" }
// OR by your own trx_id
{ "trx_id": "PAY-123456" }
Transaction Status Values
- pending Awaiting payment or processing
- processing Payment in progress
- completed Successfully completed
- failed Payment failed
- cancelled Payout cancelled
- refunded Amount refunded
↺ Webhook / Callback
We send a POST request with a JSON body to your callback_url whenever a transaction status changes.
Always verify the signature_v2 to ensure the callback is genuinely from us. Return HTTP 200 with
{"success":true} to acknowledge.Callback Payload — PayIn Success
JSON
{
"transaction_id": "TRX20241201ABC123",
"trx_id": "PAY-123456",
"type": "payin",
"amount": 1500.00,
"paid_amount": 1500.00,
"fee": 52.50,
"net_amount": 1447.50,
"currency": "BDT",
"status": "completed",
"gateway_trx_id": "COW-987654321",
"gateway_payment_trx_id": "TXN-COW-11223344",
"customer_name": "John Doe",
"updated_at": "2024-12-01T14:35:00+06:00",
"signature": "legacy_sha256",
"signature_version": 2,
"signature_v2": "hmac_sha256"
}
Callback Payload — PayOut Success
JSON
{
"transaction_id": "TRX20241201PAY456",
"trx_id": "WIT-001",
"type": "payout",
"amount": 1000.00,
"paid_amount": 1000.00,
"fee": 20.00,
"net_amount": 1000.00,
"currency": "BDT",
"status": "completed",
"gateway_trx_id": "COW-987654322",
"gateway_payment_trx_id": "TXN-COW-11223345",
"updated_at": "2024-12-01T14:40:00+06:00",
"signature": "legacy_sha256",
"signature_version": 2,
"signature_v2": "hmac_sha256"
}
Field Reference
| Field | Type | Description |
|---|---|---|
transaction_id | string | System transaction ID (our side) |
trx_id | string | Your merchant order ID |
type | string | payin or payout |
amount | decimal | Original order amount |
paid_amount | decimal | Actual amount collected / sent by gateway (may differ on partial payment) |
fee | decimal | PayIn: merchant fee deducted from paid_amount.PayOut: merchant fee charged on top of amount (deducted separately from the merchant's available balance). |
net_amount | decimal | PayIn: merchant settlement = paid_amount − fee.PayOut: amount received by recipient = paid_amount. The merchant's total deduction is amount + fee. |
currency | string | Always BDT |
status | string | completed, failed, cancelled, pending |
gateway_trx_id | string | Gateway-side order ID |
gateway_payment_trx_id | string | Gateway payment transaction ID |
customer_name | string | Customer name (PayIn only) |
updated_at | string | Callback generation time (ISO 8601) |
signature | string | Legacy SHA-256 field; retained for compatibility |
signature_version | integer | Always 2 |
signature_v2 | string | HMAC-SHA256 signature over all financial fields (see below) |
Secret Key is different from your API Key. Find it in your Merchant Panel under API Settings.
signature_v2 is hash_hmac('sha256', json_encode($fields, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), secret_key) over the exact field order below — not a simple concatenation. Money fields must be formatted with exactly 2 decimals.Webhook integration: point
callback_url / notify_url to your HTTPS webhook, decode JSON, rebuild the signed field array, compare with signature_v2 using hash_equals, then update your own order idempotently. Use paid_amount for actual settlement; treat unsigned fields like customer_name and updated_at as informational only. Return HTTP 200 only after your update succeeds.signature_v2 Fields (in exact order)
ORDER
[
transaction_id,
trx_id,
type,
currency,
status,
amount, // formatted: number_format($amount, 2, '.', '')
paid_amount, // null or number_format($paid, 2, '.', '')
fee, // number_format($fee, 2, '.', '')
net_amount, // number_format($net, 2, '.', '')
gateway_trx_id,
gateway_payment_trx_id
]
Verify Signature (PHP)
PHP
// Your secret key from Merchant Panel → API Settings
$secretKey = 'YOUR_SECRET_KEY_FROM_MERCHANT_PANEL';
$raw = file_get_contents('php://input');
$data = json_decode($raw, true);
// Rebuild the exact signed fields array
$fields = [
$data['transaction_id'],
$data['trx_id'],
$data['type'],
$data['currency'],
$data['status'],
number_format((float)$data['amount'], 2, '.', ''),
$data['paid_amount'] === null ? null : number_format((float)$data['paid_amount'], 2, '.', ''),
number_format((float)$data['fee'], 2, '.', ''),
number_format((float)$data['net_amount'], 2, '.', ''),
$data['gateway_trx_id'],
$data['gateway_payment_trx_id'],
];
$expected = hash_hmac(
'sha256',
json_encode($fields, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
$secretKey
);
if (hash_equals($expected, $data['signature_v2'] ?? '')) {
// Valid — update your order
http_response_code(200);
echo json_encode(['success' => true]);
} else {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'INVALID_SIGNATURE']);
}
Callbacks may be delivered more than once (retries). Always treat
transaction_id + status as idempotent keys — update only if the status actually changed.⚠ Error Codes
| Code | HTTP | Description |
|---|---|---|
AUTH_FAILED | 401 | Invalid API Key or Merchant ID |
INSUFFICIENT_BALANCE | 402 | Not enough balance for payout |
INVALID_PARAMS | 400 | Missing or invalid request parameters |
DUPLICATE_ORDER | 409 | Transaction ID already exists |
INVALID_WITHDRAW_PASS | 403 | Incorrect withdrawal password |
ACCOUNT_SUSPENDED | 403 | Merchant account suspended |
SERVER_ERROR | 500 | Internal server error |
bKash
Nagad
Rocket