PaySeren API
Accept local payments and send payouts across Asia with one integration. JSON over HTTPS, signed with HMAC-SHA256.
Base URL
Your Merchant ID and API secret are in the merchant portal under API & webhooks. The secret is shown once when created or rotated. Keep it on your server only, never in a browser or mobile app.
payment_url, wait for our webhook, credit the player when the status is success.Authentication
Every request carries three headers:
| Header | Value |
|---|---|
X-Merchant-Id | Your Merchant ID, for example BP0101 |
X-Timestamp | Current Unix time in seconds. Requests older or newer than 5 minutes are refused. |
X-Signature | Lower-case hex HMAC-SHA256 of the string below, keyed with your API secret |
String to sign: the four parts joined with dots, no spaces.
{timestamp}.{METHOD}.{path_with_query}.{raw_body}
path_with_query is the path exactly as sent, for example /v1/orders/M-1001. For GET requests raw_body is empty. Sign the exact bytes you send: serialize the JSON once, sign that string, send that string.
const crypto = require('crypto');
const MERCHANT_ID = 'BP0101', SECRET = process.env.PAYSEREN_SECRET;
async function payseren(method, path, payload) {
const body = payload ? JSON.stringify(payload) : '';
const ts = Math.floor(Date.now() / 1000).toString();
const sig = crypto.createHmac('sha256', SECRET)
.update(`${ts}.${method}.${path}.${body}`).digest('hex');
const res = await fetch('https://api.example.com' + path, {
method, body: body || undefined,
headers: { 'content-type': 'application/json', 'x-merchant-id': MERCHANT_ID, 'x-timestamp': ts, 'x-signature': sig },
});
return res.json();
}
function payseren(string $method, string $path, ?array $payload = null) {
$merchantId = 'BP0101'; $secret = getenv('PAYSEREN_SECRET');
$body = $payload ? json_encode($payload, JSON_UNESCAPED_SLASHES) : '';
$ts = (string) time();
$sig = hash_hmac('sha256', "$ts.$method.$path.$body", $secret);
$ch = curl_init('https://api.example.com' . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method, CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $body ?: null,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', "X-Merchant-Id: $merchantId", "X-Timestamp: $ts", "X-Signature: $sig"],
]);
return json_decode(curl_exec($ch), true);
}
import hmac, hashlib, json, time, os, requests
MERCHANT_ID, SECRET = "BP0101", os.environ["PAYSEREN_SECRET"].encode()
def payseren(method, path, payload=None):
body = json.dumps(payload, separators=(",", ":")) if payload else ""
ts = str(int(time.time()))
sig = hmac.new(SECRET, f"{ts}.{method}.{path}.{body}".encode(), hashlib.sha256).hexdigest()
r = requests.request(method, "https://api.example.com" + path, data=body or None,
headers={"content-type": "application/json", "x-merchant-id": MERCHANT_ID, "x-timestamp": ts, "x-signature": sig})
return r.json()
If you set allowed IPs in the portal, requests from any other IP are refused with ip_not_whitelisted.
Amounts & idempotency
Amounts are decimal strings in the main currency unit with up to 2 decimals: "1449.00", "500". Responses always use 2 decimals.
merchant_order_no is your own unique reference. Sending the same one twice never creates a second order: you get the original back with "duplicate": true. If a request times out, retry it with the same merchant_order_no.
Create pay-in
/v1/payin| Field | Type | Required | Description |
|---|---|---|---|
merchant_order_no | string, max 64 | yes | Your unique order reference |
currency | string | yes | INR, BDT, PKR ... see methods |
method | string | yes | For example UPI, BKASH, NAGAD |
amount | string | yes | Within your limits for this method |
callback_url | string | no | Webhook URL for this order. Defaults to the one in the portal. |
customer | object | no | id (your player ID), ip, return_url (where to send the player after paying) |
{
"merchant_order_no": "M-1001",
"currency": "INR",
"method": "UPI",
"amount": "10000.00",
"customer": { "id": "player-77", "ip": "103.21.4.10", "return_url": "https://casino.example/cashier" }
}
Response 201 Created (or 200 with "duplicate": true):
{
"order_no": "PIMX3JEL6I4FE0646C",
"merchant_order_no": "M-1001",
"direction": "payin", "currency": "INR", "method": "UPI",
"amount": "10000.00", "fee": "325.00",
"status": "pending",
"payment_url": "https://pay.example/checkout/...",
"utr": null, "failure_reason": null,
"created_at": "2026-12-01T10:15:00.000Z", "completed_at": null, "duplicate": false
}
Redirect the player to payment_url. Do not credit anything yet: the final result comes by webhook.
Create payout
/v1/payoutAmount plus fee is reserved from your available balance at once. If the payout fails, it is returned in full.
| Field | Type | Required | Description |
|---|---|---|---|
merchant_order_no | string | yes | Your unique reference |
currency, method, amount | string | yes | As for pay-in |
beneficiary | object | yes | Bank: name, account, ifsc. UPI: name, upi. Wallets (bKash, Nagad...): name, account (wallet number) |
callback_url | string | no | Webhook URL for this order |
{
"merchant_order_no": "W-5512",
"currency": "BDT", "method": "BKASH", "amount": "2500",
"beneficiary": { "name": "Rahim Uddin", "account": "01712345678" }
}
pending for a while if the bank is slow. Never send the same money again under a new reference while one is pending: query it, or wait for the webhook.Get order
/v1/orders/{order_no or merchant_order_no}Returns the same object as the create calls. Use it to check an order if you missed a webhook.
Get balance
/v1/balance{ "INR": { "available": "9675.00", "payout_hold": "2040.00" } }
available can be paid out or settled. payout_hold is reserved for payouts still in progress.
Receiving webhooks
When an order reaches success or failed we send a POST with the order object (same fields as above) to your webhook URL, with two headers:
| Header | Value |
|---|---|
X-Timestamp | Unix seconds |
X-Signature | hex HMAC-SHA256 of {timestamp}.{raw_body} with your API secret |
Verify the signature on the raw body before trusting it, then answer with any 2xx. Otherwise we retry: 10 attempts over about 4 hours. The same order can arrive more than once: process it idempotently by order_no. You can resend any webhook from the portal.
app.post('/payseren/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const raw = req.body.toString('utf8');
const ts = req.get('x-timestamp');
const expected = crypto.createHmac('sha256', SECRET).update(`${ts}.${raw}`).digest('hex');
const got = Buffer.from(req.get('x-signature') || '');
if (got.length !== expected.length || !crypto.timingSafeEqual(got, Buffer.from(expected))) return res.sendStatus(401);
const order = JSON.parse(raw);
// credit or refund once per order.order_no
res.sendStatus(200);
});
$raw = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_TIMESTAMP'] ?? '';
$expected = hash_hmac('sha256', "$ts.$raw", getenv('PAYSEREN_SECRET'));
if (!hash_equals($expected, $_SERVER['HTTP_X_SIGNATURE'] ?? '')) { http_response_code(401); exit; }
$order = json_decode($raw, true);
// credit or refund once per $order['order_no']
http_response_code(200);
Order statuses
| Status | Meaning | Final |
|---|---|---|
pending | Created, waiting for the payer or the bank | no |
success | Money received (pay-in) or delivered (payout). utr holds the bank reference. | yes |
failed | Not completed. failure_reason says why. Payout funds are back in your balance. | yes |
A final status never changes.
Methods
The methods, limits and prices enabled for your account are listed in the portal under API & webhooks. Common codes:
| Currency | Pay-in | Payout |
|---|---|---|
| INR | UPI | IMPS, UPI |
| BDT | BKASH, NAGAD, ROCKET, UPAY | BKASH, NAGAD, ROCKET, UPAY |
| PKR | JAZZCASH, EASYPAISA | JAZZCASH, EASYPAISA |
Errors
Errors return a non-2xx status and a JSON body {"error": "code", "message": "..."}.
| HTTP | error | What to do |
|---|---|---|
| 400 | validation_error, invalid_amount, invalid_json | Fix the request; details lists the fields |
| 400 | method_not_enabled | Currency or method not enabled for you. Contact support. |
| 400 | amount_out_of_range | Outside your limits for this method; message gives them |
| 400 | insufficient_balance | Not enough available balance for payout plus fee |
| 400 | daily_limit_exceeded | Your daily limit for this direction is reached; message gives it |
| 400 | payin_rejected_risk, payout_rejected_risk | Refused by risk rules (blocked account, too many attempts). Do not retry the same details. |
| 403 | payouts_frozen | Payouts are on hold for your account. Contact support. |
| 401 | missing_auth_headers, invalid_signature, timestamp_out_of_range | Check the signing string, secret and server clock |
| 403 | ip_not_whitelisted, merchant_suspended | Check allowed IPs, or contact support |
| 404 | order_not_found | Wrong reference |
| 503 | no_channel_available | Temporarily unavailable for this amount or method. Retry later. |
| 500 | internal_error | Retry with the same merchant_order_no |
Go-live checklist
- Secret stored on your server only, never in frontend code
- Signature uses the exact body bytes you send
- Server clock synced (NTP); timestamps within 5 minutes
- Webhook signature verified on the raw body; duplicates handled by
order_no - Players credited only on
successwebhooks, never on redirect back from the payment page - Allowed IPs set in the portal
- Timeouts retried with the same
merchant_order_no - Tested end to end on your sandbox account (ask us for
YOURCODE_TESTcredentials; it uses a test bank, no real money)
Good to know
- Large or unusual payouts can stay
pendinga little longer while our team approves them. Your balance is held during that time and released if the payout fails. - If a customer pays a different amount than requested, the webhook carries the real
amountand the originalrequested_amount. Credit the player withamount. - Service status and maintenance notes: /status (JSON at
/status.json).