Developer Documentation

Integrate Truepaybd in an afternoon.

Create a hosted checkout from your server, let the customer pay with bKash or Nagad Send Money, and receive a signed webhook only after Truepaybd has verified the transaction server-side.

Overview

Truepaybd is a hosted checkout and payment verification gateway for Bangladesh (BDT). Your server creates a payment request with a merchant API key; the customer is redirected to a hosted checkout page; the customer sends money from their bKash or Nagad wallet and submits the Transaction ID.

Payments are never approved by the browser or by raw SMS text. Every transaction is evaluated by the backend verification engine. When an authorized independent provider check is unavailable, a matched payment enters REVIEW_REQUIRED for auditable human verification instead of being falsely approved.

Base URL. All endpoints on this page are relative to your deployment origin, for example https://pay.example.com/api/v1. Responses use a consistent envelope: { "success": true, "code": "...", "message": "...", "data": ... }.

Authentication

Each API surface uses a different credential. Never expose a secret in browser code.

SurfaceHeaderUsed by
Merchant server API X-API-Key: rp_... Your backend creating payments and reading status
Hosted checkout submission X-Checkout-Token: chk_... The hosted checkout page only
Android notification evidence X-Device-Token: rpd_... The Truepaybd Merchant Android app
Merchant console / admin Authorization: Bearer <jwt> Signed-in dashboard users; supports TOTP 2FA

API keys are generated in the console under API & Webhooks. The secret is shown once at creation and again only after a regeneration. Live and sandbox keys are separate; sandbox keys tag every payment they create as sandbox data.

Quickstart

1

Create an account and an API key

Register a merchant, open the console, then create a key in the API & Webhooks section.

2

Create a hosted checkout

POST the order to /api/v1/payment/create and redirect the customer to checkout_url.

3

Fulfil from the webhook

Activate the order only on a verified payment.verified event, after checking the signature.

Create a payment request

cURL
curl -X POST https://pay.example.com/api/v1/payment/create \
  -H "X-API-Key: rp_live_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order_1001_attempt_1" \
  -d '{
    "order_id": "ORDER_1001",
    "amount": 499.00,
    "currency": "BDT",
    "customer_id": "USER_101",
    "description": "Pro Subscription — 1 month",
    "success_url": "https://example.com/payment/success",
    "cancel_url": "https://example.com/payment/cancel",
    "webhook_url": "https://example.com/api/payment/webhook",
    "plan_code": "PRO_MONTHLY",
    "plan_duration_days": 30
  }'
Response · 201 Created
{
  "success": true,
  "code": "CREATED",
  "message": "Payment request created successfully.",
  "data": {
    "payment_id": "PAY_8F2A91C7",
    "order_id": "ORDER_1001",
    "amount": 499.0,
    "currency": "BDT",
    "status": "CREATED",
    "is_sandbox": false,
    "checkout_token": "chk_...",
    "checkout_url": "https://pay.example.com/checkout/chk_...",
    "expires_at": "2026-12-04T12:30:00+00:00",
    "created_at": "2026-12-04T12:00:00+00:00"
  }
}

Always persist payment_id and order_id. Passing the same Idempotency-Key for the same merchant returns the original payment instead of creating a duplicate.

Hosted checkout

Redirect the customer to the checkout_url returned above. The page shows your configured bKash or Nagad send-money number, the exact amount, and a countdown. The customer sends the money, then enters the Transaction ID.

The checkout page reads the session with GET /api/v1/payment/checkout/{checkout_token} and submits with POST /api/v1/payment/submit using the checkout token header. No API secret is ever present in the page.

Amounts must match exactly. Partial payments are rejected. A Transaction ID can be submitted only once across the whole platform.

Payment status

Poll the public status endpoint while the customer is on the checkout page:

cURL
curl https://pay.example.com/api/v1/payment/checkout/chk_xxxxxxxx/status

Or read the server-side record with your API key:

cURL
curl https://pay.example.com/api/v1/payment/PAY_8F2A91C7 \
  -H "X-API-Key: rp_live_xxxxxxxxxxxxxxxx"

Status lifecycle

  • CREATED / WAITING_FOR_PAYMENT — checkout opened, nothing submitted.
  • TRANSACTION_SUBMITTED / VERIFYING — Transaction ID received, checks running.
  • PENDING — verification is still awaiting an independent signal.
  • REVIEW_REQUIRED — evidence matched but human financial review is required.
  • VERIFIED — approved after an authorized verification check.
  • REJECTED, EXPIRED, CANCELLED — terminal failures.
  • REFUNDED — a completed refund is recorded against the payment.

Webhooks

Register an HTTPS endpoint in the console. Truepaybd sends one signed request per lifecycle event: payment.verified, payment.rejected, payment.expired and payment.refunded.

Every delivery includes:

HeaderPurpose
X-Truepaybd-Signaturet=<timestamp>,v1=<hmac>; a v0 value is added during secret rotation grace.
X-Truepaybd-TimestampUnix seconds. Reject deliveries older than five minutes.
X-Truepaybd-Idempotency-KeyStable per payment and event; deduplicate on it.

Failed deliveries retry with exponential backoff. You can inspect and retry them from the console, or via GET /api/v1/merchant/webhooks/logs.

Use the raw request body exactly as received. Re-serialising the JSON changes the bytes and breaks the signature.

Signature verification

Compute HMAC-SHA256(secret, "{timestamp}.{raw_body}") and compare it with the v1 value using constant-time equality.

Python
import hashlib, hmac, time

def verify_signature(secret: str, header: str, raw_body: bytes) -> bool:
    parts = dict(item.split("=", 1) for item in header.split(",") if "=" in item)
    timestamp = int(parts["t"])
    if abs(time.time() - timestamp) > 300:
        return False
    expected = hmac.new(
        secret.encode(),
        f"{timestamp}.".encode() + raw_body,
        hashlib.sha256,
    ).hexdigest()
    return hmac.compare_digest(expected, parts["v1"])
Node.js
const crypto = require("crypto");

function verifySignature(secret, header, rawBody) {
  const parts = Object.fromEntries(
    header.split(",").map((item) => item.split("="))
  );
  const timestamp = Number(parts.t);
  if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false;

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.`)
    .update(rawBody)
    .digest("hex");

  return crypto.timingSafeEqual(
    Buffer.from(expected),
    Buffer.from(parts.v1)
  );
}

Error codes

Errors return the standard envelope with success: false and a machine-readable code. Branch on the code, not the message.

CodeMeaning
INVALID_API_KEYMissing, malformed, revoked or inactive key.
INVALID_PAYMENTUnknown payment or checkout token.
PAYMENT_EXPIREDThe checkout window has closed.
INVALID_TRANSACTION_IDTransaction ID does not match the provider format.
TRANSACTION_ALREADY_USEDThe Transaction ID was already submitted.
AMOUNT_MISMATCHThe paid amount does not equal the requested amount.
VERIFICATION_PENDINGChecks have not produced a final outcome yet.
VALIDATION_ERRORRequest body failed schema validation.
RATE_LIMITEDToo many requests for this endpoint or IP.

Sandbox testing

Sandbox mode provides a full checkout flow without moving real money. Create a sandbox key in the console, or use the public demo at /sandbox when it is enabled on the deployment.

  • Sandbox payments are stored with is_sandbox = true and are never mixed into live reporting.
  • Sandbox decisions are simulated; they do not call a payment provider.
  • Sandbox webhooks are delivered to a local sink you can inspect on the sandbox page.
Sandbox is gated by server configuration and returns 404 when disabled. Never enable it in production.

Rate limits

Limits are enforced per client and endpoint; the exact values are configurable by the operator.

  • Payment creation and API reads: general merchant limit.
  • Checkout transaction submission: 20 requests per minute.
  • Authentication and OTP endpoints: 5–15 requests per minute.

When a limit is exceeded the API returns 429 with a Retry-After header.

Need a higher limit or a provider integration review? Contact support@truepaybd.com or open the console support channel.