Developer docs

Payments in two countries, three steps.

Create an order, show the payment, confirm it on your server. The customer pays on our page — or inside your own site and app. The code is right below.

BASEhttps://anamasiha.71i.site/api
“A payment page is the only page a customer reads twice — once to decide whether to trust it, and once to check the amount. Everything here is drawn for those two reads.” Class-XII design note · AIA PAYMENT GETWAY

Master prompts any AI · any project

One text does the whole integration. Choose where your customer pays, copy the prompt, give it to ChatGPT, Claude, Gemini or your coding assistant together with your project files — it connects your existing pay button to AIA PAYMENT GETWAY and makes your site send the customer’s real name and profile picture to the payment page.

  1. Copythe master prompt below.
  2. Pasteit into your AI with your project’s files.
  3. Fill inyour API key and webhook secret in the one config file it makes.
MASTER-PROMPT-INTERNAL.TXT≈ 5,300 words
MASTER PROMPT · INTERNAL (the customer pays INSIDE my own site or app) — connect my existing project to the AIA PAYMENT GETWAY UPI payment gateway
(Give this whole text to ChatGPT, Claude, Gemini or a coding assistant TOGETHER WITH the files of the project.)

=== YOUR ROLE ===
You are a senior payment-integration engineer and a strict security reviewer. You make the smallest change that works, you check every step against this text, and you never guess.

=== WHAT I ATTACHED ===
The source code of an EXISTING, working project: a website, a panel, a shop, a wallet, or the backend of an app. Read ALL of it before you write anything.

=== STEP 0 — WRITE THESE THREE LINES FIRST, THEN CONTINUE ===
A. The language, framework and database you found.
B. Where the existing "pay / deposit / add money / checkout" button and its amount field are (file and line), and which table holds balances or orders.
C. Which WAY from the list below you will use, and why.
If nothing is attached, or the code that talks to the database is missing, STOP and ask me for those files. Do not invent a project.

=== RULE 1 — THIS IS AN INTEGRATION, NOT A REBUILD ===
Do not redesign, modernise, clean up, rename or rewrite anything. Do not remove or change a page, feature, route, table, style or script that this payment does not need. The existing button and amount field keep their look. Change as few files and lines as possible.
Before you edit: list the existing files and features. After you edit: confirm each of them is still there and still works.
If you cannot integrate without touching unrelated code, STOP and tell me what blocks you.

=== THE GOAL ===
The user enters an amount and presses the EXISTING button → a payment box opens ON TOP OF THE SAME PAGE (his own name and profile picture, QR code, one key per UPI app — Google Pay, PhonePe, Paytm, BHIM and more —, countdown) → the user pays by UPI → the page updates by itself → the user is credited (or the order is delivered) EXACTLY ONCE — also when the browser is closed right after paying, and also when the same report arrives twice.

=== RULE 2 — ONE COUNTRY PER PAYMENT (India and Bangladesh are NOT mixed) ===
This gateway takes money in two countries and the two must never appear on the same screen:
  · India     → UPI. The order's currency is "INR". The customer sees the merchant's UPI QR, the exact receiving UPI ID directly beneath it, and one key per enabled UPI app. The QR encodes the real merchant payment request and is not covered by a logo.
  · Bangladesh→ bKash / Nagad / Rocket / Upay. The order's currency is "BDT". The customer sees the wallet's number,
                one-tap number and exact-amount copy, steps in Bangla or English, and one field for the TrxID. There is no wallet QR.
So a project that serves both countries makes TWO kinds of payment — it never shows a UPI QR to a Bangladeshi customer
and never shows a bKash number to an Indian one. Send "currency": "BDT" for Bangladesh and nothing (or "INR") for India.
A Bangladesh order is confirmed by the TRANSACTION ID (the payer types it and presses Verify, or the SMS app reads it);
an India order is confirmed by the gateway itself. Both report through the same webhook, with "currency" in the payload.

=== THE WAY TO SHOW THE PAYMENT — decide by these rules ===
WAY A · POPUP — the default for every website. My server creates the order, the page opens data.payment_url with AntoPay.open(). No redirect; the customer stays on my page.
WAY B · OWN SCREEN — for mobile apps (Android, Flutter, React Native, iOS) and only when I ask for my own design. Create the order with "checkout": "direct" and draw the QR code from data.upi_url yourself. Under the QR put one button per app from data.upi_apps (Google Pay, PhonePe, Paytm, BHIM …): a tap opens that app with the amount already filled in.
FALLBACK · when the popup cannot be shown (the page cannot run JavaScript, or in-site checkout is not in my plan) the browser goes to data.payment_url instead — the popup script does that by itself.
In every way callback_url is set and handled: it is where the customer lands when the popup cannot be used.

=== GATEWAY FACTS — exact and complete; nothing else exists ===
Base URL          https://anamasiha.71i.site/api
Popup script      https://anamasiha.71i.site/assets/js/antopay.js
Auth              header  X-API-Key: <secret API key>     (server side only — never in a page, an app or a log)
Bodies            JSON, header  Content-Type: application/json

  GET  /api/me                                   key      is the key right, which currency is ready? (first call of the integration)
  POST /api/create-order                         key      start a payment
  POST /api/check-status                         key      the truth about one order — the ONLY thing that may lead to a credit
  GET  /api/payment-status?token=TOKEN&wait=1    no key   live status for a SCREEN (browser or app); never a reason to credit

--- GET /api/me → 200
{ "status": "success", "data": { "ready": true, "problems": [],
  "currency_ready": {"INR": true, "BDT": false},
  "currency_problems": {"INR": [], "BDT": ["No Bangladesh wallet with a linked receiver phone is ready."]},
  "bangladesh_ready": false, "notes": [], "merchant": "My Shop", "plan": "Pro", "in_site_checkout": true,
  "accounts_connected": 1, "receiving_accounts": [{"id":12,"provider":"paytm","upi_id":"shop@paytm","display_name":"My Shop"}], "providers": ["paytm"], "webhooks": 1, "currency": "INR", "max_amount": 25000, "default_expiry_minutes": 5 } }
"ready": false → show data.problems to me; do not go live. Before creating an order, also check data.currency_ready for the currency I chose and show its data.currency_problems if false. "ready": true can mean one country is ready while the other is not.

--- POST /api/create-order
{ "amount": 149.00, "receiving_account_id": 12, "order_id": "MY-UNIQUE-ORDER-ID", "customer_name": "Rahul Kumar", "customer_image": "https://MY-REAL-DOMAIN/uploads/avatars/42.jpg",
  "customer_mobile": "9876543210", "callback_url": "https://MY-REAL-DOMAIN/pay-return", "description": "Wallet deposit", "expiry_minutes": 5 }
→ 201
{ "status": "success", "message": "Order created successfully",
  "data": { "payment_url": "https://anamasiha.71i.site/pay/8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv", "order_id": "MY-UNIQUE-ORDER-ID", "token": "8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
            "amount": 149, "currency": "INR", "receiving_account_id": 12, "customer_name": "Rahul Kumar", "customer_image": "https://MY-REAL-DOMAIN/uploads/avatars/42.jpg",
            "expires_at": "2026-01-15 10:35:41", "created_at": "2026-01-15 10:30:41" } }
data.notes (a list of texts, present only when there is something to say) = hints for ME, the developer, in plain words — for example that the name looks like a filler, or that the picture link was not usable and was left out. The order is created all the same. While testing, show them to me; never show them to the customer.
With "checkout": "direct" in the body (WAY B) the answer ALSO has:
  "upi_url": "upi://pay?pa=...&am=149.00&tr=...", "amount_to_pay": 149.00, "payee_name": "My Shop", "upi_id": "name@bank" or null,
  "seconds_left": 300, "pay_before": "2026-01-15 10:35:41", "status_url": "https://anamasiha.71i.site/api/payment-status?token=...",
  "upi_apps": [ { "id": "gpay", "name": "Google Pay", "android": "intent://pay?pa=...#Intent;scheme=upi;package=com.google.android.apps.nbu.paisa.user;end", "ios": "gpay://upi/pay?pa=..." },
                { "id": "phonepe", ... }, { "id": "paytm", ... }, { "id": "bhim", "name": "BHIM", "android": "intent://...", "ios": null }, ... ]
  upi_apps = ready-made links, one per app, each carrying exactly what upi_url carries. Use them as given, never build such a link yourself.
  "android" is for a web page opened in Chrome on Android (a plain <a href>). "ios" is for an iPhone; null = that app has no link on an iPhone, hide its button there.
  The plain upi_url stays as the button "Any UPI app" (Android shows the phone's own list of UPI apps).

FIELD RULES (the mistakes that cause errors)
- amount: a NUMBER in rupees with at most two decimals (149 or 149.5). Not paise. Not a string with commas. Greater than 0, not above data.max_amount of /api/me.
- receiving_account_id: required for every INR order. First check data.currency_ready.INR, then choose one id from data.receiving_accounts of GET /api/me and keep it in the one server-side config place. The gateway pins the payment link to it and never substitutes another UPI account. Leave this field out only for a BDT order; check data.currency_ready.BDT before creating that order.
- order_id: required, my own id, at most 100 characters, UNIQUE for ever — a second order with the same id answers 409. Never reuse one, not even after a failure.
- customer_name: required. Send the REAL name of the signed-in user — his full name, else his username: the gateway shows it to him on the payment page ("who is paying") and on the receipt, and sends it back unchanged. Take it from the signed-in user on the SERVER (session / database), never from a form field. Send "Customer" only when the project knows no name at all — then no name is shown.
- customer_image: optional but WANTED — the profile picture (avatar) of the signed-in user, as a FULL public https address of a picture (jpg, png, webp or gif; at most 500 characters). The gateway shows it small and round beside his name on the payment page and on the receipt, so he sees at once that it is his payment. If the project stores only a file name or a relative path, build the full address with the project's real public domain. No picture, a default placeholder, a data: address or a non-https address → leave the field out: the page then shows his initials. Never send a picture that needs a login to be seen.
- currency: optional. Leave it out for an India UPI order. Send "BDT" for a Bangladesh wallet order (bKash / Nagad / Rocket / Upay): that payment page shows the merchant's wallet number and a field for the TrxID. The order currency fixes the checkout country; a payer cannot switch to the other currency on the hosted page. If my site offers both countries, my own UI may ask which country the user needs and then create the corresponding INR or BDT order. Do not convert the amount yourself. Everything else (payment_url, popup, webhook, check-status) works the same; for BDT, "utr" is the TrxID.
- customer_mobile: optional, digits only. The payment page shows it with the middle hidden (98•••••210).
- callback_url: a full https address on the REAL public domain of the project. The gateway adds ?order_id=...&token=... itself. Never localhost.
- expiry_minutes: how long the order can be paid, counted from create-order (default 5). Give the user enough time (5 to 10; use 15 when the merchant also takes bKash / Nagad — sending money from a wallet and typing its TrxID takes longer than scanning a QR); more than 15 has no use — an opened payment closes after 15 minutes.
- Answers are success ONLY with HTTP 200 / 201 AND "status": "success". Everything else is an error — read "error" and "details".
- Time-outs: 10 s to connect, 30 s in total. If the network failed (no HTTP answer), do NOT assume failure: call check-status for that order_id.
- Dates are the gateway's local time as text ("Y-m-d H:i:s"). Store them as text; do not convert time zones.

--- POST /api/check-status      { "order_id": "MY-UNIQUE-ORDER-ID" }      (GET with ?order_id= works too)
→ 200
{ "status": "success", "data": { "order_id": "MY-UNIQUE-ORDER-ID", "amount": 149, "original_amount": 149, "currency": "INR",
  "payment_status": "success", "utr": "430112345678", "paid_at": "2026-01-15 10:31:07", "payment_method": "UPI", "provider": "paytm",
  "customer_name": "User Name", "payer_name": "NAME ON THE BANK RECEIPT" } }
payment_status is "pending", "success" or "failed". An unpaid order stays "pending" for up to 15 minutes after it was created, then it is "failed" for good.
customer_name = the name I sent with the order; it never changes. payer_name = the name on the bank receipt of the person who paid (null until paid, and when the bank gives none). Show them if useful; never decide a credit by a name.
"utr" is "N/A" until the order is paid. More fields may be present — ignore what you do not need. Asking every few seconds is fine: each call makes the gateway look for the payment again.
original_amount = what I asked for. amount = the order amount reported by the gateway. The gateway does not add balancing paise; it pauses a new exact-amount collision instead of guessing. Compare original_amount with my order and credit MY order's amount.
amount, original_amount and currency are ALWAYS in the currency of MY order. On current country-specific links, the customer pays in that same currency: INR by UPI or BDT by a Bangladesh wallet. paid_amount and paid_currency describe what actually arrived; exchange_rate is null for these new orders. Legacy payments created before country switching was retired may report a different paid currency. Never credit paid_amount instead of checking payment_status and the canonical order amount.

--- GET /api/payment-status?token=TOKEN&wait=1      (no key; for WAY B and for my own "waiting…" screen)
→ 200  { "status": "success", "data": { "payment_status": "pending", "order_id": "...", "amount": 149, "utr": null, "paid_at": null, "seconds_left": 212, "redirect_url": null, "next_poll_ms": 1000 } }
With wait=1 the request stays open up to about 15 seconds and may return when the gateway records the payment; provider, host and network latency still apply. While "pending": wait next_poll_ms, ask again. Stop at "success" or "failed" — then call MY server, which calls check-status.
This address answers 403 (code "plan_embed") when in-site checkout is not in my plan — then MY server asks check-status every 3 seconds instead.

--- ERRORS      { "error": "...", "details": "...", "code": "..." (sometimes) }
400 the body is not valid JSON                → a bug in my code
405 wrong HTTP method                         → a bug in my code
401 key missing or wrong                      → tell me to check the key in the config file
403 code "plan_embed"                         → in-site checkout is not in my plan: create the order again WITHOUT "checkout" and send the browser to data.payment_url (the popup falls back by itself)
404 order not found (check-status)            → treat as "unknown order", never credit
409 "Duplicate order_id"                      → that id exists already: call check-status for it; create a NEW id for a new attempt
409 code "amount_in_use"                      → another live INR order has the exact amount; nothing was created, so wait for that window to close and retry the SAME order_id without changing the amount
409 code "cannot_start" (only with "direct")  → no payment account can take it right now; nothing was kept, the same order_id may be sent again
422 a field is wrong                          → show "details" to me (developer), a short message to the user
422 code "receiving_account_required" | "receiving_account_unavailable" → refresh GET /api/me and choose one available receiving_accounts id; no order was created
409 code "receiving_account_unavailable" → the selected account changed after validation; refresh GET /api/me and choose again; no order was created
422 code "plan_amount"                        → the amount is above what my plan allows per payment: show "details"
429 code "plan_orders" | "plan_daily" | "plan_volume" | "plan_links" → a limit of my plan is reached: show "details"; do not retry in a loop
503 maintenance or busy                       → try again in a few seconds, at most 2 times
5xx or no answer                              → do not assume anything; check-status later

--- POPUP (WAY A)
<script src="https://anamasiha.71i.site/assets/js/antopay.js"></script>
AntoPay.open({ url: payment_url, onSuccess: function (p) {...}, onFailed: function (p) {...}, onClose: function (p) {...} });
p.order_id, p.amount, p.utr, p.paid_at · onClose gets p.paid (true / false) · AntoPay.close() closes the box.
After a payment the popup shows "paid" for a moment (about one and a half seconds; the owner of the gateway sets it) and then sends the browser to callback_url — unless onSuccess returns false (then the page stays). onSuccess itself is called at once, without that pause.
If the box cannot be shown (plan without in-site checkout, a rule against frames) the script goes to the hosted page by itself; the customer then returns to callback_url.
If the project sends a Content-Security-Policy header, add https://anamasiha.71i.site to script-src and to frame-src.
What the popup reports is for the SCREEN only. It is never proof of payment.

--- WEBHOOK (the gateway calls MY server)
POST to my webhook address, JSON body, sent ONCE (no retry), my server has 8 seconds to answer with HTTP 2xx.
Headers: X-Webhook-Event (payment.success | payment.failed), X-Webhook-Signature, X-Webhook-Timestamp
X-Webhook-Signature = lowercase hex HMAC-SHA256 of the RAW request body with my webhook secret as the key.
Body: { "event": "payment.success", "status": "success", "order_id": "MY-UNIQUE-ORDER-ID", "amount": "149.00", "original_amount": "149.00", "currency": "INR", "utr": "430112345678", "paid_at": "2026-01-15 10:31:07", "customer_name": "User Name", "payer_name": "NAME ON THE BANK RECEIPT", "timestamp": 1768451467, … more fields }
The only field you need from it is order_id.
Because it is sent once, the webhook alone is NOT enough: the return page, the page script and a safety net (below) must each be able to finish the order alone.

=== REFERENCE IMPLEMENTATION — tested end to end against this gateway ===
This PHP code was run against the real API: popup, redirect, webhook, the same webhook twice, a forged webhook, another user's order, a closed browser. It passed.
If the project is PHP: use it as it is and only adapt the table and column names and the way the project gets its database connection and its signed-in user.
If the project is in another language: port it LINE BY LINE — same functions, same order of checks, same SQL conditions. Do not "improve" the logic.

=== FILE: gateway-config.php ===
<?php
// The ONLY place for the gateway values. Never print them, never send them to the browser.
return [
    'base'           => 'https://anamasiha.71i.site/api',
    'key'            => 'PASTE_YOUR_API_KEY_HERE',
    'webhook_secret' => 'PASTE_YOUR_WEBHOOK_SECRET_HERE',
    'receiving_account_id' => 12, // choose an id returned by GET /api/me
    'expiry_minutes' => 5,
];

=== FILE: gateway.php ===
<?php
// Reference implementation — tested end to end against this gateway.
// Tables assumed here:  users(id, balance)  and  deposits(id, user_id, order_id UNIQUE, amount, status, gateway_token, utr, created_at, paid_at)
// status: pending | paid | failed

/** One request to the gateway. Returns [httpCode, decodedBody|null]. (0 = the gateway could not be reached) */
function gateway_call($method, $path, ?array $body = null)
{
    $cfg = require __DIR__ . '/gateway-config.php';
    $ch = curl_init(rtrim($cfg['base'], '/') . $path);
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST  => $method,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_TIMEOUT        => 30,
        CURLOPT_HTTPHEADER     => ['X-API-Key: ' . $cfg['key'], 'Content-Type: application/json', 'Accept: application/json'],
    ]);
    if ($body !== null) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
    }
    $raw = curl_exec($ch);
    $code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    $data = is_string($raw) ? json_decode($raw, true) : null;
    return [$code, is_array($data) ? $data : null];
}

/**
 * START: the local order is written first (PENDING), then the gateway order is created with the same order id.
 * $userName = the real name of the signed-in user, $userImage = the https address of his profile picture ('' = he has none):
 * the payment page shows both, small, so that he sees it is HIS payment.
 * Returns ['ok' => true, 'order_id' => …, 'payment_url' => …]  or  ['ok' => false, 'message' => …].
 */
function gateway_start(PDO $db, $userId, $userName, $amount, $callbackUrl, $userImage = '')
{
    $cfg = require __DIR__ . '/gateway-config.php';
    $amount = round((float)$amount, 2);
    if ($amount < 1) {
        return ['ok' => false, 'message' => 'Enter an amount of at least 1.'];
    }
    $orderId = 'DEP' . (int)$userId . 'T' . date('ymdHis') . bin2hex(random_bytes(3));      // unique, never reused
    $db->prepare("INSERT INTO deposits (user_id, order_id, amount, status, created_at) VALUES (?, ?, ?, 'pending', ?)")
       ->execute([(int)$userId, $orderId, $amount, date('Y-m-d H:i:s')]);

    $order = [
        'amount'         => $amount,
        'receiving_account_id' => (int)$cfg['receiving_account_id'],
        'order_id'       => $orderId,
        'customer_name'  => trim((string)$userName) !== '' ? (string)$userName : 'Customer',
        'callback_url'   => $callbackUrl,          // the gateway adds ?order_id=…&token=… itself
        'description'    => 'Wallet deposit',
        'expiry_minutes' => (int)$cfg['expiry_minutes'],
    ];
    if (preg_match('#^https://#i', (string)$userImage)) {
        $order['customer_image'] = (string)$userImage;      // only a full https address; without one the page shows his initials
    }
    [$code, $res] = gateway_call('POST', '/create-order', $order);
    if ($code !== 201 || empty($res['data']['payment_url'])) {
        $db->prepare("UPDATE deposits SET status = 'failed' WHERE order_id = ? AND status = 'pending'")->execute([$orderId]);
        $why = is_array($res) ? ($res['details'] ?? ($res['error'] ?? '')) : '';
        return ['ok' => false, 'message' => $why !== '' ? $why : 'The payment could not be started. Please try again.'];
    }
    $db->prepare("UPDATE deposits SET gateway_token = ? WHERE order_id = ?")->execute([(string)$res['data']['token'], $orderId]);
    return ['ok' => true, 'order_id' => $orderId, 'payment_url' => (string)$res['data']['payment_url']];
}

/**
 * CONFIRM: ask the gateway about one order and credit it EXACTLY ONCE.
 * Call it from everywhere — the return page, the page script, the webhook, a cron job — in any order, any number of times.
 * $onlyUserId: pass the signed-in user so nobody can confirm somebody else's order (null for webhook / cron).
 * Returns 'paid' | 'pending' | 'failed' | 'unknown'.
 */
function gateway_confirm(PDO $db, $orderId, $onlyUserId = null)
{
    $find = $db->prepare("SELECT * FROM deposits WHERE order_id = ?");
    $find->execute([(string)$orderId]);
    $dep = $find->fetch(PDO::FETCH_ASSOC);
    if (!$dep || ($onlyUserId !== null && (int)$dep['user_id'] !== (int)$onlyUserId)) {
        return 'unknown';
    }
    if ($dep['status'] === 'paid') {
        return 'paid';                                   // already credited: nothing to do
    }
    [$code, $res] = gateway_call('POST', '/check-status', ['order_id' => $dep['order_id']]);
    if ($code !== 200 || !isset($res['data']['payment_status'])) {
        return $dep['status'] === 'failed' ? 'failed' : 'pending';      // gateway not reachable now: ask again later
    }
    $data = $res['data'];
    if ($data['payment_status'] === 'success') {
        if (abs((float)$data['original_amount'] - (float)$dep['amount']) > 0.001) {
            return 'failed';                             // not the amount this order was created with
        }
        $db->beginTransaction();
        try {
            // "AND status <> 'paid'" + the row count: only ONE caller ever gets through, whoever comes first
            $mark = $db->prepare("UPDATE deposits SET status = 'paid', utr = ?, paid_at = ? WHERE order_id = ? AND status <> 'paid'");
            $mark->execute([(string)($data['utr'] ?? ''), date('Y-m-d H:i:s'), $dep['order_id']]);
            if ($mark->rowCount() === 1) {
                $db->prepare("UPDATE users SET balance = balance + ? WHERE id = ?")->execute([$dep['amount'], (int)$dep['user_id']]);
            }
            $db->commit();
        } catch (Throwable $e) {
            $db->rollBack();
            throw $e;
        }
        return 'paid';
    }
    if ($data['payment_status'] === 'failed') {
        $db->prepare("UPDATE deposits SET status = 'failed' WHERE order_id = ? AND status = 'pending'")->execute([$dep['order_id']]);
        return 'failed';
    }
    return 'pending';
}

/** WEBHOOK: the signature is checked on the RAW body first; the payment itself is still confirmed with check-status. */
function gateway_webhook(PDO $db)
{
    $cfg = require __DIR__ . '/gateway-config.php';
    $raw = (string)file_get_contents('php://input');
    $given = (string)($_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '');
    if ($cfg['webhook_secret'] === '' || $given === '' || !hash_equals(hash_hmac('sha256', $raw, $cfg['webhook_secret']), $given)) {
        http_response_code(401);
        echo 'bad signature';
        return;
    }
    $event = json_decode($raw, true);
    if (is_array($event) && !empty($event['order_id'])) {
        gateway_confirm($db, (string)$event['order_id']);
    }
    http_response_code(200);
    echo 'ok';
}

/** SAFETY NET: the webhook is sent once. Call this when the user opens the wallet page (or from a cron job every minute). */
function gateway_reconcile(PDO $db, $userId = null)
{
    $sql = "SELECT order_id FROM deposits WHERE status = 'pending' AND created_at >= ?" . ($userId !== null ? ' AND user_id = ' . (int)$userId : '') . ' ORDER BY id DESC LIMIT 5';
    $open = $db->prepare($sql);
    $open->execute([date('Y-m-d H:i:s', time() - 1800)]);
    foreach ($open->fetchAll(PDO::FETCH_COLUMN) as $orderId) {
        gateway_confirm($db, $orderId, $userId);
    }
}

=== FILE: pay-start.php ===
<?php
// The existing "Add money" button posts the amount here. Answers JSON for the page script.
require __DIR__ . '/app.php';                 // the project's own bootstrap: $db (PDO) and the signed-in $user
require __DIR__ . '/gateway.php';
header('Content-Type: application/json');
$returnUrl = APP_URL . '/pay-return.php';     // APP_URL = the real public address of this project, from its config
echo json_encode(gateway_start($db, $user['id'], $user['name'], $_POST['amount'] ?? 0, $returnUrl, $user['avatar_url'] ?? ''));

=== FILE: pay-confirm.php ===
<?php
// Called by the page script after the box says "paid", and safe to call at any time.
require __DIR__ . '/app.php';
require __DIR__ . '/gateway.php';
header('Content-Type: application/json');
$status = gateway_confirm($db, (string)($_GET['order_id'] ?? ''), $user['id']);
$balance = $db->query('SELECT balance FROM users WHERE id = ' . (int)$user['id'])->fetchColumn();
echo json_encode(['status' => $status, 'balance' => number_format((float)$balance, 2, '.', '')]);

=== FILE: pay-return.php ===
<?php
// callback_url: the customer's browser arrives here after paying (hosted page, or when the popup could not be used).
require __DIR__ . '/app.php';
require __DIR__ . '/gateway.php';
$status = gateway_confirm($db, (string)($_GET['order_id'] ?? ''), $user['id']);
header('Location: ' . APP_URL . '/wallet.php?deposit=' . $status);      // show "paid", "pending" or "failed" there

=== FILE: gateway-webhook.php ===
<?php
// The address to add in the gateway dashboard → Webhooks. No login, no CSRF check here: the signature is the proof.
require __DIR__ . '/app-db.php';              // only the database connection ($db) — no session
require __DIR__ . '/gateway.php';
gateway_webhook($db);

=== FILE: wallet-page-snippet.html ===
<!-- the existing form stays as it is; only this script is added -->
<script src="https://anamasiha.71i.site/assets/js/antopay.js"></script>
<script>
document.getElementById('depositForm').addEventListener('submit', function (e) {
  e.preventDefault();
  var form = this, button = form.querySelector('[type=submit]');
  button.disabled = true;
  fetch('pay-start.php', { method: 'POST', body: new FormData(form), credentials: 'same-origin' })
    .then(function (r) { return r.json(); })
    .then(function (res) {
      button.disabled = false;
      if (!res.ok) { alert(res.message); return; }
      var confirmNow = function () {
        fetch('pay-confirm.php?order_id=' + encodeURIComponent(res.order_id), { credentials: 'same-origin' })
          .then(function (r) { return r.json(); })
          .then(function (c) { if (c.status === 'paid') { location.reload(); } });
      };
      AntoPay.open({
        url: res.payment_url,
        onSuccess: function () { confirmNow(); return false; },   // "paid" on the screen → MY server asks the gateway; stay on this page
        onClose: confirmNow                                        // closed early: the payment may still have come in
      });
    })
    .catch(function () { button.disabled = false; alert('Network problem. Please try again.'); });
});
</script>

=== PORTING NOTES (other languages) ===
- Raw webhook body BEFORE any JSON parsing: Laravel $request->getContent() · Express express.raw({type:'application/json'}) · Django request.body · Flask request.get_data() · FastAPI await request.body() · Spring @RequestBody String · ASP.NET EnableBuffering + StreamReader · Go io.ReadAll(r.Body) · Rails request.raw_post
- Constant-time compare: hash_equals · crypto.timingSafeEqual · hmac.compare_digest · MessageDigest.isEqual · CryptographicOperations.FixedTimeEquals · hmac.Equal · ActiveSupport::SecurityUtils.secure_compare
- The webhook route has NO login and NO CSRF check (exempt only this one route). Everything else keeps its protection.
- The credit runs in ONE database transaction. Keep the condition "status <> 'paid'" in the UPDATE and credit only when exactly one row changed (or lock the row with SELECT … FOR UPDATE first).
- Money is stored as DECIMAL(12,2) or integer paise — never as float.
- MOBILE APP: the app never holds the API key or the webhook secret. It calls two endpoints of MY backend (start, confirm) and, with WAY B, the key-less payment-status address. Open the UPI app with the upi_url (Android: Intent.ACTION_VIEW; Flutter: url_launcher externalApplication; React Native: Linking.openURL) inside try/catch — when no UPI app answers, the QR code stays on the screen. For one button per app inside a NATIVE Android app: Intent(ACTION_VIEW, Uri.parse(upi_url)).setPackage(PACKAGE), where PACKAGE is the text between "package=" and ";" of that app's "android" link; on an iPhone open the app's "ios" link. A WebView must hand links that start with "intent:" or "upi:" to the system (shouldOverrideUrlLoading → Intent.parseUri / startActivity) — a WebView alone cannot open them. Ask the status again when the app comes back to the foreground.

=== REQUIRED FLOW ===
1. Find the existing pay / deposit button and amount field. Keep the UI.
2. Server: check that the user is signed in and validate the amount with the project's own rules.
3. Server: write a local order as PENDING with a new unique order id — BEFORE calling the gateway.
4. Server: choose the configured receiving_account_id from GET /api/me, then call create-order with that id, the signed-in user's real name (customer_name) and, when he has one, the full https address of his profile picture (customer_image). On any answer other than 201 mark the local order failed and show the gateway's "details".
5. Store data.token next to the local order.
6. Page: open data.payment_url in the popup (WAY A), or draw the own screen (WAY B).
7. When the screen reports success, when the popup is closed, and when the customer lands on callback_url: call MY server with the order id.
8. MY server calls check-status and runs the ONE credit function. It credits only when payment_status is "success", the order belongs to this user, and original_amount equals the local amount.
9. The webhook endpoint verifies the signature on the raw body, then runs the same function (through check-status — never from the webhook's own numbers).
10. Safety net: when the user opens the wallet / orders page (or by a cron job every minute), run the same function for his local PENDING orders of the last 30 minutes.
11. Nothing that comes from the browser or the app is trusted: not the amount, not the status, not the order id's owner.
12. Pending, failed, expired, duplicate and already-paid orders each get a clear message.

=== DATABASE ===
Reuse the existing user, wallet and transaction tables. Do not build a second wallet. Add only what is missing: one table (or columns) with the order id (UNIQUE), user id, amount, status (pending / paid / failed), gateway token, UTR, created and paid time. Give me the SQL.

=== ONE CONFIG PLACE ===
All gateway values live in exactly ONE server-side place (a config file or .env), with these placeholders — I paste the real values myself after upload:
AIAPAYMENTGETWAY_BASE_URL=https://anamasiha.71i.site/api
AIAPAYMENTGETWAY_API_KEY=PASTE_YOUR_API_KEY_HERE
AIAPAYMENTGETWAY_WEBHOOK_SECRET=PASTE_YOUR_WEBHOOK_SECRET_HERE
AIAPAYMENTGETWAY_RECEIVING_ACCOUNT_ID=12  # replace with one id from GET /api/me
AIAPAYMENTGETWAY_EXPIRY_MINUTES=5
Also add ONE small test page for me (signed-in admin only, or a command-line script): it calls GET /api/me and prints the answer, so that I can see in one click whether the key and the account are right.

=== SELF-CHECK — go through every line before you answer; fix what fails ===
[ ] The API key, webhook secret and chosen receiving account id appear in the one server-side config place only — credentials never appear in HTML, JavaScript, an app, a log or an error message.
[ ] Every INR create-order request sends one receiving_account_id currently returned by GET /api/me.
[ ] The local order exists BEFORE create-order is called, and its id is new every time.
[ ] There is exactly ONE function that credits. It is the only code that changes a balance for this gateway.
[ ] That function credits only after check-status said "success", the amount matches (original_amount) and the order belongs to the user.
[ ] Calling that function twice, or from two requests at the same moment, credits once (transaction + "status <> 'paid'" + row count, or a row lock).
[ ] Return page, page script, webhook and safety net all end in that function — each of them works alone.
[ ] customer_name is the real name of the signed-in user, read on the server; customer_image is a full public https address of his picture, or the field is left out.
[ ] The webhook checks the HMAC of the RAW body with a constant-time compare BEFORE parsing, answers 2xx fast, and never credits from its own body.
[ ] A user cannot confirm another user's order (the owner is checked on the server).
[ ] No localhost address anywhere; callback_url and the webhook address come from the project's real public address.
[ ] HTTP time-outs are set; a network failure never counts as "paid" or as "failed".
[ ] No existing page, route, table, style or feature was removed or renamed.
[ ] The test page for GET /api/me exists.

=== WHAT I WANT BACK — in this order ===
1. The three lines of STEP 0.
2. The list of files you add or change — nothing else is touched.
3. The COMPLETE final content of every added or changed file. No "…", no "rest stays the same".
4. The SQL I have to run.
5. Where exactly I paste the API key and the webhook secret.
6. The exact webhook address I add in the AIA PAYMENT GETWAY dashboard (Webhooks page), and that I copy its secret into the config.
7. How I test it: open the test page (GET /api/me), then pay 1 rupee — and what I should see after: paying; closing the page right after paying; opening the return address twice. On the payment page I must see my own user's name and picture.
Download .txt Open as a link
  • Internal = the payment box opens on your own page (or your app draws its own screen) — your customer never leaves. External = your customer goes to the payment page of AIA PAYMENT GETWAY and comes back; nothing is loaded into your pages.
  • Both send the signed-in customer’s name (customer_name) and profile picture (customer_image) with every order — he sees them on the payment page and on the receipt.
  • Both carry working code — run against this gateway before release: popup, redirect, webhook, a webhook sent twice, a forged one, a closed browser.
  • Credit exactly once, also when the page is refreshed or the same report arrives twice — and make the AI check its own work against a list before it answers.

Do not paste your real API key into an AI chat. The prompt asks for placeholders in one config file — put the real key there yourself after you upload the code.

Two countries, one gateway

The same API key, the same order, the same webhook. The only thing that changes is which country the order is for — and therefore which screen the customer sees.

Ask for the order in BDT (taka) and the payment page opens the Bangladesh panel: the wallet's own colour, the receiving number with a Copy key, the steps in Bangla or English — the payer taps one button to switch — and a Transaction ID field. Money goes straight to the wallet number; the gateway never holds it.

One line is the whole difference: send "currency": "BDT" in create-order. Leave it out (or send "INR") and the order is an Indian UPI one.

BANGLADESH · CREATE ORDER
POST https://anamasiha.71i.site/api/create-order
X-API-Key: <secret key>
Content-Type: application/json

{
  "amount": 500,
  "currency": "BDT",
  "order_id": "BD-1001",
  "customer_name": "Karim Uddin",
  "customer_mobile": "01711000111",
  "description": "Panel recharge",
  "callback_url": "https://your-site.com/payment/callback"
}

→ pay.php returns data.payment_url — send the customer there.

What the customer does

  1. Send Money from the wallet app (or *247# and the other USSD codes) to the number on the page.
  2. Type exactly the taka amount shown — one taka less or more cannot match.
  3. Type the Transaction ID from the confirmation SMS into the page and press Verify.
  4. The page turns green by itself. Your webhook fires and your server credits the customer.
  • No SMS app needed when the payer types the TrxID (the gateway calls the wallet's own status API where the owner set one) — the AntoPay SMS app only adds the case where nobody types anything.
  • No extra charge to the customer. The payer sends exactly the order amount; the gateway takes nothing from it.
  • Separate link, separate receipts: every BDT order is listed under its own currency, and the webhook carries "currency": "BDT".

Make a Bangladesh link Wallet numbers & SMS app

Leave currency out and the order is an Indian UPI one: a QR in the gateway's colours, one tap per UPI app (GPay, PhonePe, Paytm, BHIM…), and the payment confirms itself — nobody types anything.

INDIA · CREATE ORDER
POST https://anamasiha.71i.site/api/create-order
X-API-Key: <secret key>
Content-Type: application/json

{
  "amount": 149,
  "receiving_account_id": 12,
  "order_id": "IN-2001",
  "customer_name": "Ravi Kumar",
  "callback_url": "https://your-site.com/payment/callback"
}

→ the same data.payment_url, the same webhook.

What the customer does

  1. Scan the QR or tap the app he already has.
  2. Pay the exact amount — nothing to type, nothing to copy.
  3. The page finds the payment and turns green; your webhook fires.
  • One integration, two order types. Use the same key and endpoints. BDT selects Bangladesh wallets; INR uses UPI and a receiving_account_id from GET /api/me. Each link stays in its selected country.
  • Same webhook. "currency" tells your server which wallet the money came from.

Integrate UPI Try it live

Which country is an order? One field.

What you sendThe screen the customer getsWhat confirms it
"currency": "BDT"bKash / Nagad / Rocket / Upay panel, amount in ৳The Transaction ID (typed, or read by the SMS app)
no currency / "INR"UPI QR + app buttons, amount in ₹The UPI reference, found by the gateway itself

Bangladesh — a ৳ order, a wallet payment

  1. Your server creates the order with "currency": "BDT" — that one field makes it a Bangladesh order.
  2. Open data.payment_url for the customer (or in a popup). The page shows only the wallet flow: one-tap number copy, exact taka amount, steps and TrxID verification — no wallet QR.
  3. The customer sends the money with bKash / Nagad / Rocket / Upay and types the Transaction ID.
  4. Your webhook (payment.success, "currency": "BDT", "utr" = the TrxID) credits the customer — once.
BANGLADESH · PHP
$ch = curl_init('https://anamasiha.71i.site/api/create-order');
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ['X-API-Key: ' . $KEY, 'Content-Type: application/json'],
  CURLOPT_POSTFIELDS => json_encode([
    'amount' => 500,                 // taka
    'currency' => 'BDT',             // ← the only field that makes it a Bangladesh order
    'order_id' => 'BD-1001',
    'customer_name' => $user['name'],
    'callback_url' => 'https://your-site.com/payment/callback',
  ])]);
$data = json_decode(curl_exec($ch), true)['data'];
header('Location: ' . $data['payment_url']);

A Bangladesh order needs a wallet number with its phone in Bangladesh Wallets. Confirmation rules and the SMS app are described in the section above.

India — a ₹ order, a UPI payment

  1. Your server gets the available ids from GET /api/me, chooses one receiving_account_id, then creates the order without currency (or with "INR").
  2. Open data.payment_url. The page shows only UPI: a QR and app keys. The exact merchant UPI ID is also displayed just beneath the QR. No wallet number, no taka.
  3. The customer scans or taps his UPI app. Nothing is typed.
  4. The gateway finds the payment itself and calls your webhook — credit the customer once.
INDIA · PHP
$ch = curl_init('https://anamasiha.71i.site/api/create-order');
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ['X-API-Key: ' . $KEY, 'Content-Type: application/json'],
  CURLOPT_POSTFIELDS => json_encode([
    'amount' => 149,                 // rupees
    'receiving_account_id' => 12,    // choose an id returned by GET /api/me
    'order_id' => 'IN-2001',         // no "currency" → India / UPI
    'customer_name' => $user['name'],
    'callback_url' => 'https://your-site.com/payment/callback',
  ])]);
$data = json_decode(curl_exec($ch), true)['data'];
header('Location: ' . $data['payment_url']);

An India order needs one ready UPI account from data.receiving_accounts in GET /api/me. The resulting link stays pinned to that account.

Both countries in one project, separate checkouts

One API key, one webhook, one transactions model. The order currency fixes the country and checkout: INR shows UPI; BDT shows Bangladesh wallets. A customer never switches the payment currency on the hosted page.

  1. Keep one local order table with a country or currency column.
  2. Bangladesh → "currency": "BDT". India → nothing.
  3. Read currency in the webhook and credit the right wallet/balance of the customer.
  4. Optionally offer a country choice in your own UI (a customer's address or phone tells you which one). Never show both payment ways on one screen.

Verified once, credited once. Both kinds end in the same payment.success webhook with the same signature header; the only difference is "currency" and, for Bangladesh, "utr" carrying the TrxID.

Start here

The whole integration is on this screen. Copy, change the values, done.

1

Create the order your server

Send the amount and your own order number. Keep the API key on the server.

Create an order
curl -X POST "https://anamasiha.71i.site/api/create-order" \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 499,
    "receiving_account_id": 12,
    "order_id": "ORD-1001",
    "customer_name": "Rahim Uddin",
    "callback_url": "https://yourshop.com/thank-you"
  }'
<?php
$ch = curl_init('https://anamasiha.71i.site/api/create-order');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'amount'        => 499,
        'receiving_account_id' => 12, // choose an id returned by GET /api/me
        'order_id'      => 'ORD-' . time(),
        'customer_name' => 'Rahim Uddin',
        'callback_url'  => 'https://yourshop.com/thank-you',
    ]),
]);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);

if (($res['status'] ?? '') === 'success') {
    header('Location: ' . $res['data']['payment_url']); // send the customer to the checkout
    exit;
}
echo $res['error'] ?? 'Could not create the order';
const res = await fetch('https://anamasiha.71i.site/api/create-order', {
  method: 'POST',
  headers: { 'X-API-Key': 'anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    amount: 499,
    receiving_account_id: 12, // choose an id returned by GET /api/me
    order_id: 'ORD-' + Date.now(),
    customer_name: 'Rahim Uddin',
    callback_url: 'https://yourshop.com/thank-you',
  }),
});
const json = await res.json();

if (json.status === 'success') {
  // send the customer to the checkout
  console.log(json.data.payment_url);
}
import time
import requests

res = requests.post(
    "https://anamasiha.71i.site/api/create-order",
    headers={"X-API-Key": "anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
    json={
        "amount": 499,
        "receiving_account_id": 12,  # choose an id returned by GET /api/me
        "order_id": f"ORD-{int(time.time())}",
        "customer_name": "Rahim Uddin",
        "callback_url": "https://yourshop.com/thank-you",
    },
    timeout=15,
).json()

if res.get("status") == "success":
    print(res["data"]["payment_url"])  # send the customer to the checkout

The answer has data.payment_url and data.token. Save your order as “pending” before you go on.

2

Show the payment pick one way

In-site checkout The QR opens in a box on top of your page. The customer never leaves your site.

popup.html
<!-- once, anywhere on your page -->
<script src="https://anamasiha.71i.site/assets/js/antopay.js"></script>

<button id="pay">Pay ₹149</button>

<script>
document.getElementById('pay').onclick = async function () {
  // your server creates the order (step 1) and answers with data.payment_url
  const order = await (await fetch('/create-order', { method: 'POST' })).json();

  AntoPay.open({
    url: order.payment_url,
    onSuccess: function (p) {
      // p.order_id · p.amount · p.utr  — show "thank you";
      // deliver only after YOUR SERVER confirmed (step 3)
    },
    onClose: function (p) { /* box closed — p.paid tells if the money came in */ }
  });
};
</script>
<script src="https://anamasiha.71i.site/assets/js/antopay.js"></script>

<!-- no JavaScript of your own: the link opens as a popup -->
<a href="PAYMENT_URL" data-antopay>Pay now</a>

Every plan Send the customer to our payment page. He comes back to your callback_url after paying.

redirect
// $order = the decoded answer of create-order (step 1)
header('Location: ' . $order['data']['payment_url'], true, 303);
exit;
// Node / Express
res.redirect(303, order.data.payment_url);

// in a browser, with the payment_url your server returned
window.location.href = paymentUrl;

In-site checkout Your design, your screen — a website or a mobile app. Add "checkout": "direct" in step 1 and you get the QR link, the exact amount and a status address.

own screen
// "order" = the data object your server got in step 1 (never send the API key to the screen)

// 1. QR code — draw order.upi_url with any QR library
new QRCode(document.getElementById('qr'), order.upi_url);

// 2. phones — one button per app: a tap opens THAT app with the amount filled in
var iPhone = /iPhone|iPad|iPod/.test(navigator.userAgent);
order.upi_apps.forEach(function (app) {
  var link = iPhone ? app.ios : app.android;      // null = this app has no link on an iPhone
  if (!link) return;
  var a = document.createElement('a');
  a.href = link;
  a.textContent = app.name;
  document.getElementById('apps').appendChild(a);
});

// 2b. "Any UPI app" — Android shows the phone's own list of UPI apps
document.getElementById('upiBtn').href = order.upi_url;

// 3. the amount to show: order.amount_to_pay

// 4. wait for the payment — the held request can return when the gateway records paid status
async function waitForPayment() {
  for (;;) {
    const s = (await (await fetch(order.status_url + '&wait=1')).json()).data;
    if (s.payment_status === 'success') return showThankYou(s);   // then confirm on your server (step 3)
    if (s.payment_status === 'failed')  return showExpired();
    await new Promise(function (ok) { setTimeout(ok, s.next_poll_ms); });
  }
}
waitForPayment();
// "order" comes from YOUR backend (it called create-order with "checkout": "direct")

// open the payer's UPI app
try {
    startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(order.upiUrl)))
} catch (e: ActivityNotFoundException) {
    showQr(order.upiUrl)                       // no UPI app on this phone: show the QR instead
}

// when the user comes back from the UPI app
override fun onResume() {
    super.onResume()
    lifecycleScope.launch {
        val s = api.liveStatus(order.statusUrl + "&wait=1")        // GET, no API key
        if (s.paymentStatus == "success") backend.confirm(order.orderId)   // your server calls check-status
    }
}
// "order" comes from YOUR backend (it called create-order with "checkout": "direct")

QrImageView(data: order.upiUrl, size: 240);                 // package: qr_flutter

await launchUrl(Uri.parse(order.upiUrl),                    // package: url_launcher
    mode: LaunchMode.externalApplication);

Future<void> waitForPayment() async {
  while (mounted) {
    final r = await http.get(Uri.parse('${order.statusUrl}&wait=1'));
    final s = jsonDecode(r.body)['data'];
    if (s['payment_status'] == 'success') return confirmOnBackend(order.orderId);
    if (s['payment_status'] == 'failed') return showExpired();
    await Future.delayed(Duration(milliseconds: s['next_poll_ms']));
  }
}
curl -X POST https://anamasiha.71i.site/api/create-order \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 149,
    "receiving_account_id": 12,
    "order_id": "ORD-1001",
    "customer_name": "Rahim",
    "checkout": "direct"
  }'
{
  "status": "success",
  "data": {
    "order_id": "ORD-1001",
    "token": "8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "payment_url": "https://anamasiha.71i.site/pay/8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "checkout": "direct",
    "upi_url": "upi://pay?pa=shop@upi&pn=Your%20Shop&am=149.00&tr=ORD-1001&tn=ORD-1001&cu=INR",
    "amount_to_pay": 149,
    "payee_name": "Your Shop",
    "upi_id": "shop@upi",
    "seconds_left": 300,
    "pay_before": "2026-01-15 10:35:00",
    "status_url": "https://anamasiha.71i.site/api/payment-status?token=8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "upi_apps": [
      { "id": "gpay", "name": "Google Pay",
        "android": "intent://pay?pa=shop@upi&pn=Your%20Shop&am=149.00&tr=ORD-1001&tn=ORD-1001&cu=INR#Intent;scheme=upi;package=com.google.android.apps.nbu.paisa.user;end",
        "ios": "gpay://upi/pay?pa=shop@upi&pn=Your%20Shop&am=149.00&tr=ORD-1001&tn=ORD-1001&cu=INR" },
      { "id": "phonepe", "name": "PhonePe", "android": "intent://pay?…package=com.phonepe.app;end", "ios": "phonepe://pay?…" },
      { "id": "paytm", "name": "Paytm", "android": "intent://pay?…package=net.one97.paytm;end", "ios": "paytmmp://pay?…" },
      { "id": "bhim", "name": "BHIM", "android": "intent://pay?…package=in.org.npci.upiapp;end", "ios": null }
    ]
  }
}
3

Confirm on your server before you deliver

We send your webhook after the gateway accepts the required payment evidence. Check the signature and credit the order once.

Webhook receiver
<?php
// webhook.php — receives payment events
$secret  = 'whsec_your_webhook_secret';
$payload = file_get_contents('php://input');
$sent    = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';

if (!hash_equals(hash_hmac('sha256', $payload, $secret), $sent)) {
    http_response_code(401);
    exit('Invalid signature');
}

$event = json_decode($payload, true);
if ($event['event'] === 'payment.success') {
    // Mark $event['order_id'] as paid. Keep this idempotent:
    // the same event can be delivered more than once.
}
http_response_code(200);
echo 'OK';
const express = require('express');
const crypto = require('crypto');
const app = express();

// the raw body is needed to verify the signature
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const expected = crypto.createHmac('sha256', 'whsec_your_webhook_secret').update(req.body).digest('hex');
  const sent = req.get('X-Webhook-Signature') || '';
  if (expected.length !== sent.length || !crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sent))) {
    return res.status(401).send('Invalid signature');
  }

  const event = JSON.parse(req.body);
  if (event.event === 'payment.success') {
    // mark event.order_id as paid (keep it idempotent)
  }
  res.send('OK');
});

app.listen(3000);
import hashlib
import hmac
from flask import Flask, request

app = Flask(__name__)
SECRET = b"whsec_your_webhook_secret"

@app.post("/webhook")
def webhook():
    expected = hmac.new(SECRET, request.data, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, request.headers.get("X-Webhook-Signature", "")):
        return "Invalid signature", 401

    event = request.get_json()
    if event["event"] == "payment.success":
        pass  # mark event["order_id"] as paid (keep it idempotent)
    return "OK"

No webhook yet? Ask POST /api/check-status with your order_id — see Check status.

One rule. The popup, the redirect and the screen only tell the customer what happened. Your server decides: deliver only after the webhook or check-status says success.

A shorter prompt for one stack

The master prompt works for every project. If you want a shorter one, pick how the customer pays and what your project is built with.

1 · How the customer pays

2 · Your project

integration-prompt.txt
You are a senior PHP payment-integration engineer and security reviewer.

I am attaching the COMPLETE source code of an EXISTING PHP project. First read the whole project and understand its architecture: authentication, users, the existing Deposit / Add Money / Checkout flow, the database schema, transaction tables, routes or controllers, and the hosting constraints.

=== RULE 1 — DO NOT REBUILD ANYTHING ===
This is an INTEGRATION-ONLY task. Do not redesign, modernise, clean up or rewrite the project. Do not remove, rename or change any existing page, feature, route, table, style or script that is not required for this payment integration. Keep the existing UI exactly as it is. Change the minimum number of files and lines.
Before editing, list the existing files and features. After editing, confirm that each of them still exists and still works.
If you cannot integrate safely without touching unrelated code, STOP and explain what is blocking you. Do not invent a replacement.

=== TASK ===
Connect the EXISTING pay / deposit button and its amount field to the AIA PAYMENT GETWAY payment gateway. The user enters an amount, presses the existing button, a payment box opens ON TOP OF THE SAME PAGE (no redirect), pays by UPI, and the page continues. The user is credited exactly once.

=== GATEWAY API ===
Base URL:       https://anamasiha.71i.site/api
Create order:   POST https://anamasiha.71i.site/api/create-order      (server only — needs the secret API key)
Check status:   POST https://anamasiha.71i.site/api/check-status      (server only — needs the secret API key)
Live status:    GET  https://anamasiha.71i.site/api/payment-status?token=TOKEN&wait=1      (no key — may be called from a browser or an app)
Popup script:   https://anamasiha.71i.site/assets/js/antopay.js
Auth header:    X-API-Key: <secret API key>
Content-Type:   application/json

Create-order body:
{
  "amount": 100.00,
  "receiving_account_id": 12,
  "order_id": "UNIQUE_LOCAL_ORDER_ID",
  "customer_name": "REAL NAME OF THE SIGNED-IN USER",
  "customer_image": "https://MY-REAL-DOMAIN/uploads/avatars/42.jpg",
  "customer_mobile": "9876543210",
  "callback_url": "https://MY-REAL-DOMAIN/payment/callback",
  "description": "Wallet deposit",
  "expiry_minutes": 5
}
receiving_account_id is required for every INR order: choose one id from data.receiving_accounts returned by GET /api/me. The payment link stays pinned to that account. Leave it out only when currency is BDT.
customer_name is required: the real name of the signed-in user, read on the server (never a filler such as "Customer" or "User") — he sees it on the payment page and on the receipt. customer_image is optional: the full public https address of his profile picture; leave the field out when he has none.
Success (HTTP 201) returns: data.payment_url, data.order_id, data.token, data.amount, data.expires_at (and data.notes — a list of remarks — when the gateway had to leave something out, e.g. a picture address it cannot use)
With "checkout": "direct" in the body it ALSO returns: data.upi_url, data.amount_to_pay, data.payee_name, data.upi_id (can be null), data.seconds_left, data.status_url, data.upi_apps (list of { id, name, android, ios or null } — one ready-made link per UPI app)
Errors return:  { "error": "...", "details": "..." } with HTTP 400 / 401 / 403 / 404 / 409 / 422 / 429 / 5xx
HTTP 403 with "code": "plan_embed" means in-site checkout is not part of the merchant's plan: create the order again WITHOUT "checkout" and redirect to payment_url.

Check-status body:  { "order_id": "UNIQUE_LOCAL_ORDER_ID" }
Returns: data.payment_status ("pending" | "success" | "failed"), data.amount (what the customer paid), data.original_amount (what was requested), data.utr, data.paid_at
amount and original_amount are always in the order currency. data.paid_amount and data.paid_currency report what actually arrived; on new country-specific links they match the order currency. Never credit paid_amount instead of checking payment_status.

Live status returns: data.payment_status ("pending" | "success" | "failed"), data.amount, data.utr, data.paid_at, data.seconds_left, data.next_poll_ms
With wait=1 the request stays open (up to about 15 seconds) and may return as soon as the gateway records the payment. Provider, hosting and network latency still apply. Ask again after data.next_poll_ms milliseconds while the status is "pending".

Popup: AntoPay.open({ url: payment_url, onSuccess: fn(p), onFailed: fn(p), onClose: fn(p) })  — p.order_id, p.amount, p.utr
After a payment the popup sends the browser to callback_url?order_id=...&token=... unless onSuccess returns false.

After payment on the hosted page or in the popup the customer's browser is redirected to:  callback_url?order_id=...&token=...
That redirect, the popup's onSuccess and the live status are NOT proof of payment. They only tell the SCREEN what to show.

Webhook: AIA PAYMENT GETWAY sends a POST with a JSON body to my webhook URL.
Headers: X-Webhook-Event (e.g. payment.success), X-Webhook-Signature, X-Webhook-Timestamp
Signature = lowercase hex HMAC-SHA256 of the RAW request body, using my webhook secret as the key.
Body fields: event, status, order_id, amount, original_amount, currency, utr, paid_at, customer_name (as I sent it), payer_name (name on the bank receipt, can be null), timestamp
Answer with HTTP 2xx within 8 seconds.

=== HOW THE CUSTOMER PAYS — POPUP ON TOP OF MY OWN PAGE (in-site checkout, no redirect) ===
Load the script once on the page:  <script src="https://anamasiha.71i.site/assets/js/antopay.js"></script>
The pay button calls MY server (fetch / AJAX). My server creates the order and answers with payment_url. The page then calls AntoPay.open({ url: payment_url, ... }). The QR code appears in a box on top of my page; the customer never leaves it.
In onSuccess(p): call MY server with p.order_id; the server runs check-status and credits (step 8-10); then update the page (new balance / thank-you). Never credit from the values in p.
Keep callback_url as well: the popup sends the browser there after a payment (return false from onSuccess to stay on the page), and it is the fallback when the script cannot run.
If the merchant's plan has no in-site checkout, the script continues on the hosted payment page by itself — nothing extra to code.

=== REQUIRED FLOW ===
1. Find the existing pay / deposit button and amount field. Keep the UI.
2. On the server: authenticate the current user and validate the amount with the project's own rules.
3. Create a local PENDING order with a unique order id BEFORE calling the gateway.
4. Call create-order from the SERVER with that order id and amount. Use expiry_minutes = 5.
5. Store the returned token and payment_url next to the local order.
6. Build callback_url from the real deployed domain of this project — never hard-code localhost.
7. Do NOT redirect. Return payment_url to the page as JSON and open it with AntoPay.open({ url: payment_url, onSuccess, onClose }).
8. When the customer is back on the callback page — or the popup / my own screen reports success — read order_id, load the local order and call check-status from the SERVER.
9. Credit ONLY when payment_status is "success", the order belongs to the right user, and data.original_amount equals the local order amount.
10. Use a database transaction and a row lock (or a unique constraint) so the same order can NEVER be credited twice.
11. Add a server-side webhook endpoint. Verify X-Webhook-Signature with a constant-time comparison on the raw body, then call check-status and run the SAME idempotent credit function.
12. Callback, screen report and webhook can arrive in any order, or all, or only one of them. Each must be safe on its own.
13. Never trust amount, status, order id or user id that come from the browser or the app.
14. Handle pending, failed, expired, duplicate and already-paid orders with a clear message for the user.

=== DATABASE ===
Reuse the existing user, wallet and transaction tables. Do not create a second wallet system. Add only the columns or the single table that is really needed: gateway order id (unique), user id, amount, status, token, UTR, created and paid timestamps.

=== ONE CONFIG PLACE ===
Create ONE file, config/aiapaymentgetway.php, that returns an array:
AIAPAYMENTGETWAY_BASE_URL => https://anamasiha.71i.site/api
AIAPAYMENTGETWAY_API_KEY => YOUR_API_KEY
AIAPAYMENTGETWAY_WEBHOOK_SECRET => YOUR_WEBHOOK_SECRET
AIAPAYMENTGETWAY_RECEIVING_ACCOUNT_ID => 12
AIAPAYMENTGETWAY_EXPIRY_MINUTES => 5
The real API key must never appear in frontend code, HTML, JavaScript, API responses, logs or the repository. I will paste the real values into that one place myself after upload — use clear placeholders.

=== NOTES FOR PHP ===
Use plain PHP with PDO and cURL, matching the style the project already has. No framework and no Composer package unless the project already uses one. Use prepared statements, hash_equals() for the signature check and file_get_contents('php://input') for the raw webhook body.

=== WHAT I WANT BACK ===
1. A short summary of how the existing payment / deposit flow works today.
2. The list of files you will change or add — and nothing else.
3. The complete final content of every changed or added file (no "..." placeholders).
4. Any SQL migration needed.
5. The exact file and keys where I put my API key and webhook secret.
6. The exact webhook URL I must add in the AIA PAYMENT GETWAY dashboard.
7. A test checklist: successful payment, expired payment, page refresh on the callback, the webhook arriving twice.

The same prompt as a plain-text address — give it to an assistant that can open links: https://anamasiha.71i.site/docs.php?prompt=1&stack=generic&way=popup

Your own screen In-site checkout

Add "checkout": "direct" to create-order. The payment window opens at once and the answer carries everything your screen needs.

checkout: direct
curl -X POST https://anamasiha.71i.site/api/create-order \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 149,
    "receiving_account_id": 12,
    "order_id": "ORD-1001",
    "customer_name": "Rahim",
    "checkout": "direct"
  }'
{
  "status": "success",
  "data": {
    "order_id": "ORD-1001",
    "token": "8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "payment_url": "https://anamasiha.71i.site/pay/8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "checkout": "direct",
    "upi_url": "upi://pay?pa=shop@upi&pn=Your%20Shop&am=149.00&tr=ORD-1001&tn=ORD-1001&cu=INR",
    "amount_to_pay": 149,
    "payee_name": "Your Shop",
    "upi_id": "shop@upi",
    "seconds_left": 300,
    "pay_before": "2026-01-15 10:35:00",
    "status_url": "https://anamasiha.71i.site/api/payment-status?token=8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "upi_apps": [
      { "id": "gpay", "name": "Google Pay",
        "android": "intent://pay?pa=shop@upi&pn=Your%20Shop&am=149.00&tr=ORD-1001&tn=ORD-1001&cu=INR#Intent;scheme=upi;package=com.google.android.apps.nbu.paisa.user;end",
        "ios": "gpay://upi/pay?pa=shop@upi&pn=Your%20Shop&am=149.00&tr=ORD-1001&tn=ORD-1001&cu=INR" },
      { "id": "phonepe", "name": "PhonePe", "android": "intent://pay?…package=com.phonepe.app;end", "ios": "phonepe://pay?…" },
      { "id": "paytm", "name": "Paytm", "android": "intent://pay?…package=net.one97.paytm;end", "ios": "paytmmp://pay?…" },
      { "id": "bhim", "name": "BHIM", "android": "intent://pay?…package=in.org.npci.upiapp;end", "ios": null }
    ]
  }
}
// "order" = the data object your server got in step 1 (never send the API key to the screen)

// 1. QR code — draw order.upi_url with any QR library
new QRCode(document.getElementById('qr'), order.upi_url);

// 2. phones — one button per app: a tap opens THAT app with the amount filled in
var iPhone = /iPhone|iPad|iPod/.test(navigator.userAgent);
order.upi_apps.forEach(function (app) {
  var link = iPhone ? app.ios : app.android;      // null = this app has no link on an iPhone
  if (!link) return;
  var a = document.createElement('a');
  a.href = link;
  a.textContent = app.name;
  document.getElementById('apps').appendChild(a);
});

// 2b. "Any UPI app" — Android shows the phone's own list of UPI apps
document.getElementById('upiBtn').href = order.upi_url;

// 3. the amount to show: order.amount_to_pay

// 4. wait for the payment — the held request can return when the gateway records paid status
async function waitForPayment() {
  for (;;) {
    const s = (await (await fetch(order.status_url + '&wait=1')).json()).data;
    if (s.payment_status === 'success') return showThankYou(s);   // then confirm on your server (step 3)
    if (s.payment_status === 'failed')  return showExpired();
    await new Promise(function (ok) { setTimeout(ok, s.next_poll_ms); });
  }
}
waitForPayment();
FieldTypeWhat to do with it
upi_urlrequiredstringDraw it as a QR code. You may also use it behind your own generic UPI action; AntoPay’s hosted checkout intentionally shows only the explicit app buttons selected by the platform owner.
upi_appsrequiredarrayOne ready-made link per selected app — id, name, android, ios. Put a button per app under the QR: on Android use android, and on an iPhone use ios (null means no button there). A tap opens that app with the amount filled in. Use the links as given; do not add an “Other” button when matching AntoPay’s hosted checkout.
amount_to_payrequirednumberThe exact amount to show and pay. AntoPay does not add balancing paise; an exact-amount collision is paused instead of being assigned by guesswork.
payee_namerequiredstringThe name the customer will see in his UPI app.
upi_idrequiredstring | nullMay be shown for typing by hand. null = this account can only be paid through the QR / link.
seconds_leftrequiredintegerTime left to pay. Show a countdown; at 0 offer a new order.
status_urlrequiredstringAsk it for the result — see Live status. No API key needed.

Not paid in time? The order turns failed. Create a new order with a new order_id for the next try.

Mobile apps

An app can be unpacked, so the API key must never be inside it. The app talks to your backend; your backend talks to us.

  1. App → your backend: “start a payment of ₹149”. The backend calls create-order with "checkout": "direct" and passes upi_url, amount_to_pay, seconds_left and status_url to the app.
  2. App: opens the UPI app with upi_url and shows the QR as a second way. For one button per app, take the package name out of the android link of upi_apps (the text between package= and ;) and start Intent(ACTION_VIEW, Uri.parse(upi_url)).setPackage(…); on an iPhone open the ios link.
  3. WebView apps: a WebView cannot open links that start with intent: or upi: by itself. Hand them to the system in shouldOverrideUrlLoading (Intent.parseUri → startActivity), otherwise the app buttons of the payment page do nothing inside your app.
  4. App: asks status_url (no key) — also every time it comes back to the foreground.
  5. App → your backend: “confirm order ORD-1001”. The backend calls check-status and delivers.
in the app
// "order" comes from YOUR backend (it called create-order with "checkout": "direct")

// open the payer's UPI app
try {
    startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(order.upiUrl)))
} catch (e: ActivityNotFoundException) {
    showQr(order.upiUrl)                       // no UPI app on this phone: show the QR instead
}

// when the user comes back from the UPI app
override fun onResume() {
    super.onResume()
    lifecycleScope.launch {
        val s = api.liveStatus(order.statusUrl + "&wait=1")        // GET, no API key
        if (s.paymentStatus == "success") backend.confirm(order.orderId)   // your server calls check-status
    }
}
// "order" comes from YOUR backend (it called create-order with "checkout": "direct")

QrImageView(data: order.upiUrl, size: 240);                 // package: qr_flutter

await launchUrl(Uri.parse(order.upiUrl),                    // package: url_launcher
    mode: LaunchMode.externalApplication);

Future<void> waitForPayment() async {
  while (mounted) {
    final r = await http.get(Uri.parse('${order.statusUrl}&wait=1'));
    final s = jsonDecode(r.body)['data'];
    if (s['payment_status'] == 'success') return confirmOnBackend(order.orderId);
    if (s['payment_status'] == 'failed') return showExpired();
    await Future.delayed(Duration(milliseconds: s['next_poll_ms']));
  }
}

iPhone: iOS cannot always open a UPI app from a link, so keep the QR visible. Simplest of all: open payment_url in the phone’s browser or a web view — that works in every app and on every plan.

Live status In-site checkout

GET/api/payment-status?token=TOKEN&wait=1

For the screen that shows the payment. It needs no API key — the order’s token is the permission — so a browser or an app may call it. With wait=1 the request stays open and may return when the gateway records the payment; provider and network latency still apply.

FieldTypeDescription
tokenrequiredstringdata.token of the order (already inside status_url).
waitoptionalboolean1 = hold the request (up to about 15 seconds) until the payment is known.
answer.json
{
  "status": "success",
  "data": {
    "payment_status": "success",
    "order_id": "ORD-1001",
    "amount": 149,
    "currency": "INR",
    "utr": "412345678901",
    "paid_at": "2026-01-15 10:31:42",
    "seconds_left": 0,
    "redirect_url": "https://yourshop.com/thank-you?order_id=ORD-1001&token=8fK2…",
    "next_poll_ms": 0
  }
}

While payment_status is pending, wait next_poll_ms milliseconds and ask again. Stop at success or failed.

This address tells the screen what to show. Your server still confirms with the webhook or check-status before it delivers.

Authentication

Send your API key in the X-API-Key header of every request. Authorization: Bearer <key> works as well.

headers
X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json

Keep the key on your server. Never put it in HTML, JavaScript, a mobile app or a public repository. If a key leaks, regenerate it in the dashboard — the old one stops working immediately.

Get the key under API Keys. Configure India UPI under India UPI for INR orders; configure a wallet and receiver phone under Bangladesh Wallets for BDT orders. Request bodies can be JSON or ordinary form fields. Responses are always JSON.

Test your key

GET/api/me

The first call of every integration: it tells whether the key is right, which country-specific payment methods are ready, and whether a global issue blocks new orders. Nothing is created.

Test the key
curl https://anamasiha.71i.site/api/me \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
{
  "status": "success",
  "data": {
    "ready": true,
    "problems": [],
    "currency_ready": {"INR": true, "BDT": false},
    "currency_problems": {"INR": [], "BDT": ["No Bangladesh wallet with a linked receiver phone is ready."]},
    "bangladesh_ready": false,
    "notes": [],
    "merchant": "My Shop",
    "plan": "Pro",
    "in_site_checkout": true,
    "accounts_connected": 1,
    "receiving_accounts": [{"id": 12, "provider": "paytm", "provider_name": "Paytm", "upi_id": "shop@paytm", "display_name": "My Shop"}],
    "providers": ["paytm"],
    "webhooks": 1,
    "currency": "INR",
    "max_amount": 25000,
    "default_expiry_minutes": 5,
    "api_base": "https://anamasiha.71i.site/api",
    "popup_script": "https://anamasiha.71i.site/assets/js/antopay.js"
  }
}
FieldMeaning
readytrue — at least one currency is ready and no global blocker prevents orders. false — read problems.
currency_readyWhether the method and plan are ready for each country: INR means India UPI; BDT means Bangladesh wallets. Check the matching currency before creating an order. Global blockers remain in problems.
currency_problemsCountry-specific account/setup or plan-access messages, keyed by INR and BDT.
bangladesh_readyWhether Bangladesh wallet setup and plan access are ready for BDT orders.
problemsGlobal blockers (maintenance, plan limits, etc.) and a general no-method warning if neither currency is ready. Country-specific setup messages are in currency_problems.
notesThings that work but should be looked at (no webhook yet, in-site checkout not in the plan …).
in_site_checkoutWhether the popup and "checkout": "direct" are part of the plan.
receiving_accountsIndia accounts available now: each item has id, provider, UPI ID and display name. Send exactly one item’s id as receiving_account_id for every INR order.
max_amountThe largest single payment the plan accepts.

Create order

POST/api/create-order

Creates a payment and returns the payment page for it.

Body parameters

FieldTypeDescription
amountrequirednumberAmount in the currency selected for this order: rupees for INR (the default) or taka for BDT. Greater than 0 and up to 500,000; two decimals.
receiving_account_idrequired for INRintegerRequired for an INR order; leave it out for BDT. Choose one id from data.receiving_accounts returned by GET /api/me. The payment link remains pinned to that account and never falls over to another UPI ID.
order_idrequiredstringYour own unique reference, up to 100 characters. Used to look the order up later.
customer_namerequiredstringYour customer’s real name (or user name). Shown on the payment page, on the receipt and in your dashboard, and sent back to you unchanged. A filler such as Customer, User or Guest is accepted, but then no name is shown.
customer_imageoptionalstringYour customer’s profile picture: a full https:// link to a picture, up to 500 characters. Shown small and round beside the name on the payment page and on the receipt; without it the page shows the initials of the name. A link that cannot be used is left out and data.notes says so — the order is created all the same. new in 4.6.0
currencyoptionalstringINR (default — an India UPI checkout) or BDT (a Bangladesh wallet checkout). Each link shows one country’s payment methods only. BDT needs a wallet number and a linked receiver phone under Bangladesh Wallets. The response, webhook and check-status carry the same currency; for a wallet payment utr is the TrxID.
callback_urloptionalstringWhere the customer’s browser goes after paying. Must start with http:// or https://.
checkoutoptionalstring"direct" = also return what your own screen needs. Leave it out for the payment page and the popup.
customer_mobileoptionalstringCustomer phone number, digits only. The payment page shows it with the middle hidden (98•••••210).
descriptionoptionalstringShort note shown on the payment page (up to 500 characters).
expiry_minutesoptionalintegerHow long the payment stays open. Default 5. Use 0 for no expiry. expiry_hours is accepted too.
is_reusableoptionalbooleanAllow the same link to be paid more than once. Default false.

Request

Create an order
curl -X POST "https://anamasiha.71i.site/api/create-order" \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 499,
    "receiving_account_id": 12,
    "order_id": "ORD-1001",
    "customer_name": "Rahim Uddin",
    "callback_url": "https://yourshop.com/thank-you"
  }'
<?php
$ch = curl_init('https://anamasiha.71i.site/api/create-order');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'amount'        => 499,
        'receiving_account_id' => 12, // choose an id returned by GET /api/me
        'order_id'      => 'ORD-' . time(),
        'customer_name' => 'Rahim Uddin',
        'callback_url'  => 'https://yourshop.com/thank-you',
    ]),
]);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);

if (($res['status'] ?? '') === 'success') {
    header('Location: ' . $res['data']['payment_url']); // send the customer to the checkout
    exit;
}
echo $res['error'] ?? 'Could not create the order';
const res = await fetch('https://anamasiha.71i.site/api/create-order', {
  method: 'POST',
  headers: { 'X-API-Key': 'anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    amount: 499,
    receiving_account_id: 12, // choose an id returned by GET /api/me
    order_id: 'ORD-' + Date.now(),
    customer_name: 'Rahim Uddin',
    callback_url: 'https://yourshop.com/thank-you',
  }),
});
const json = await res.json();

if (json.status === 'success') {
  // send the customer to the checkout
  console.log(json.data.payment_url);
}
import time
import requests

res = requests.post(
    "https://anamasiha.71i.site/api/create-order",
    headers={"X-API-Key": "anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
    json={
        "amount": 499,
        "receiving_account_id": 12,  # choose an id returned by GET /api/me
        "order_id": f"ORD-{int(time.time())}",
        "customer_name": "Rahim Uddin",
        "callback_url": "https://yourshop.com/thank-you",
    },
    timeout=15,
).json()

if res.get("status") == "success":
    print(res["data"]["payment_url"])  # send the customer to the checkout

Response 201 Created

response.json
{
  "status": "success",
  "message": "Order created successfully",
  "data": {
    "payment_url": "https://anamasiha.71i.site/pay/8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "order_id": "ORD-1001",
    "token": "8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "amount": 499,
    "currency": "INR",
    "receiving_account_id": 12,
    "customer_name": "Rahim Uddin",
    "expires_at": "2026-01-15 10:35:41",
    "created_at": "2026-01-15 10:30:41"
  }
}

Save order_id on your side, then show the payment: popup, redirect to data.payment_url, or your own screen.

An order that is not paid within its time (at most 15 minutes after the payment was shown) is marked failed.

India and Bangladesh: separate account pages and checkouts

Connect India UPI under India UPI Accounts. Connect bKash, Nagad, Rocket or Upay and link the receiver phone under Bangladesh Wallets. A payment link has one currency and one country: INR links show UPI; BDT links show Bangladesh wallets. They never mix payment methods on the same checkout.

The response, webhook and check-status preserve the currency you created the order with. For a wallet payment, paid_currency is BDT, payment_method names the wallet and utr is the TrxID.

An order in ৳

Send "currency": "BDT". The payment page then starts with your own wallet number instead of a QR: the customer sends the money in his wallet app and types the TrxID; the order is confirmed after the matching wallet SMS reaches this site and the customer claims its TrxID. Set it up under Bangladesh Wallets (add a wallet number, then link the receiver phone). Everything else is the same — payment_url, the popup, check-status, the signed webhook.

An order in taka
curl -X POST "https://anamasiha.71i.site/api/create-order" \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 1250,
    "currency": "BDT",
    "order_id": "ORD-1002",
    "customer_name": "Karim Uddin",
    "callback_url": "https://yourshop.com/thank-you"
  }'
  • The answer, check-status and the webhook carry "currency": "BDT"; for a wallet payment utr is the TrxID, payment_method the wallet (bKash, Nagad, Rocket, Upay), customer_mobile the payer's wallet number when you sent none.
  • A ৳ order stays open 15 minutes by default (expiry_minutes changes it).
  • "checkout": "direct" is not available for ৳ (answer 422). Without a wallet number and a linked phone the answer is 409 cannot_start.
  • The amount the customer sends must be exactly the amount the page shows, and one TrxID pays one order.

Check status

POST/api/check-status

Returns the current state of an order — from your server, with the API key. GET with ?order_id=… works too. If the order is still pending, this call also triggers a fresh verification, so it is safe to poll every few seconds.

FieldTypeDescription
order_idrequiredstringThe order_id you sent when creating the order.

Request

Check an order
curl "https://anamasiha.71i.site/api/check-status?order_id=ORD-1001" \
  -H "X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
<?php
$ch = curl_init('https://anamasiha.71i.site/api/check-status?order_id=' . urlencode($orderId));
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['X-API-Key: anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'],
]);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);

if (($res['data']['payment_status'] ?? '') === 'success') {
    // paid — deliver the order. Bank reference: $res['data']['utr']
}
const res = await fetch('https://anamasiha.71i.site/api/check-status?order_id=' + encodeURIComponent(orderId), {
  headers: { 'X-API-Key': 'anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' },
});
const { data } = await res.json();

if (data.payment_status === 'success') {
  // paid — deliver the order. Bank reference: data.utr
}
import requests

data = requests.get(
    "https://anamasiha.71i.site/api/check-status",
    params={"order_id": order_id},
    headers={"X-API-Key": "anto_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
    timeout=15,
).json()["data"]

if data["payment_status"] == "success":
    pass  # paid — deliver the order. Bank reference: data["utr"]

Response 200 OK

response.json
{
  "status": "success",
  "data": {
    "order_id": "ORD-1001",
    "amount": 499,
    "original_amount": 499,
    "currency": "INR",
    "paid_amount": 499,
    "paid_currency": "INR",
    "exchange_rate": null,
    "payment_status": "success",
    "customer_name": "Rahim Uddin",
    "customer_mobile": null,
    "payer_name": "RAHIM UDDIN",
    "utr": "430112345678",
    "payment_method": "UPI",
    "provider": "fampay",
    "gateway_txn_id": "12",
    "paid_at": "2026-01-15 10:31:07",
    "payment_url": "https://anamasiha.71i.site/pay/8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
    "callback_url": "https://yourshop.com/thank-you",
    "expires_at": "2026-01-15 10:35:41",
    "created_at": "2026-01-15 10:30:41"
  }
}

Payment status values

payment_statusMeaning
pendingNot paid yet — the customer has not completed the payment.
successPaid and verified. utr holds the bank reference, paid_at the time and payer_name the name on the bank receipt (null when the bank gave none). customer_name stays the name you sent.
failedThe payment window ran out or the link expired without a payment.

amount and original_amount. AntoPay keeps the requested amount and does not add balancing paise. If another open order already uses that exact amount, the new payment window is paused instead of assigning amount-only evidence by guesswork. amount is the order amount reported by the gateway; original_amount is what you asked for — compare original_amount with your own order. For BDT orders, paid_amount and paid_currency describe the wallet receipt — details.

Return to your site

When a payment is confirmed on the payment page or in the popup, the customer’s browser is sent to your callback_url with two query parameters:

redirect
https://yourshop.com/thank-you?order_id=ORD-1001&token=8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv

A redirect is not proof of payment — anybody can type that address. On your callback page read order_id, call /api/check-status from your server and deliver only when payment_status is success.

Errors

Errors use ordinary HTTP status codes with a small JSON body:

error.json
{
  "error": "Duplicate order_id",
  "details": "An order with this order_id already exists"
}
200Request succeeded
201Order created
400Body is not valid JSON
401API key missing, wrong or disabled
403In-site checkout is not part of the plan (plan_embed)
404No order with that order_id / token
405Wrong HTTP method
409order_id was used, the payment cannot start, or the exact amount is already open (amount_in_use)
422A field is missing or invalid
429A limit of your plan is reached — see code below
500Something failed on our side — retry
503Platform is under maintenance

A 409 without a code means the order already exists — do not create it again; call check-status. With amount_in_use, no new order was created: wait for the other exact-amount window to close, then retry the same order_id.

Plan limits

Every plan has its own limits. When create-order would pass one of them, nothing is created and the answer carries a code your software can act on. Your current usage is on the Plan page.

HTTPcodeMeaning
429plan_ordersAll transactions of the current period are used. Counted: paid orders and orders whose payment is still open — an order that was never paid gives its place back.
429plan_dailyThe transactions of today are used. Resets at midnight.
429plan_volumeThe amount would pass the total your plan may collect in one period.
429plan_linksOnly for is_reusable: every open payment link of the plan is in use.
422plan_amountThe amount is above the largest single payment of your plan.
403plan_embedYour plan has the payment page only. Leave checkout out and send the customer to payment_url.
409cannot_startOnly for "checkout": "direct": the payment could not be opened (for example no payment account is connected). Nothing was created — the same order_id can be sent again.
409amount_in_useAnother live INR order has the same exact amount. No order was created; retry the same order_id after that payment window closes.

Webhooks

A webhook is a POST request we send to your server when something happens to a payment, so you do not have to poll. Add your endpoint under Webhooks in the dashboard; it shows the secret used to sign every request.

Events

EventSent when
payment.successA payment was verified. This is the one every integration needs.
payment.failedThe payment window ran out without a payment.

Request headers

HeaderValue
X-Webhook-EventThe event name, for example payment.success.
X-Webhook-SignatureLower-case hex HMAC-SHA256 of the raw request body, keyed with your endpoint’s secret.
X-Webhook-TimestampUnix time when the request was sent.
X-Webhook-Testtrue — only on test deliveries sent from the dashboard.

Payload

payment.success
{
  "event": "payment.success",
  "status": "success",
  "order_id": "ORD-1001",
  "amount": "499.00",
  "original_amount": "499.00",
  "currency": "INR",
  "paid_amount": "499.00",
  "paid_currency": "INR",
  "exchange_rate": null,
  "customer_name": "Rahim Uddin",
  "customer_mobile": null,
  "payer_name": "RAHIM UDDIN",
  "utr": "430112345678",
  "payment_method": "UPI",
  "provider": "fampay",
  "gateway_txn_id": "12",
  "paid_at": "2026-01-15 10:31:07",
  "payment_url": "https://anamasiha.71i.site/pay/8fK2mQx7Lr0aTz5Wc1Yb9Ne4Hd6Sj3Uv",
  "callback_url": "https://yourshop.com/thank-you",
  "expires_at": "2026-01-15 10:35:41",
  "created_at": "2026-01-15 10:30:41",
  "timestamp": 1768451467,
  "data": {
    "order_id": "ORD-1001",
    "amount": 499,
    "original_amount": 499,
    "currency": "INR",
    "paid_amount": 499,
    "paid_currency": "INR",
    "exchange_rate": null,
    "payment_status": "success",
    "utr": "430112345678",
    "paid_at": "2026-01-15 10:31:07"
  }
}

The same values are available at the top level and inside data; use whichever is more convenient.

Responding

  • Answer with any 2xx status within 8 seconds. Do slow work (e-mails, fulfilment) after you have answered.
  • The same event can reach you more than once. Make your handler idempotent: if the order is already marked paid, answer 200 and do nothing.
  • Every delivery, with your server’s response, is listed in the dashboard — where you can also send a test event.
  • For anything involving money, confirm with /api/check-status before you credit.

Verify the signature

Compute the HMAC-SHA256 of the raw request body (before any JSON parsing) with your endpoint secret and compare it to X-Webhook-Signature using a constant-time comparison.

Webhook receiver
<?php
// webhook.php — receives payment events
$secret  = 'whsec_your_webhook_secret';
$payload = file_get_contents('php://input');
$sent    = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';

if (!hash_equals(hash_hmac('sha256', $payload, $secret), $sent)) {
    http_response_code(401);
    exit('Invalid signature');
}

$event = json_decode($payload, true);
if ($event['event'] === 'payment.success') {
    // Mark $event['order_id'] as paid. Keep this idempotent:
    // the same event can be delivered more than once.
}
http_response_code(200);
echo 'OK';
const express = require('express');
const crypto = require('crypto');
const app = express();

// the raw body is needed to verify the signature
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const expected = crypto.createHmac('sha256', 'whsec_your_webhook_secret').update(req.body).digest('hex');
  const sent = req.get('X-Webhook-Signature') || '';
  if (expected.length !== sent.length || !crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(sent))) {
    return res.status(401).send('Invalid signature');
  }

  const event = JSON.parse(req.body);
  if (event.event === 'payment.success') {
    // mark event.order_id as paid (keep it idempotent)
  }
  res.send('OK');
});

app.listen(3000);
import hashlib
import hmac
from flask import Flask, request

app = Flask(__name__)
SECRET = b"whsec_your_webhook_secret"

@app.post("/webhook")
def webhook():
    expected = hmac.new(SECRET, request.data, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, request.headers.get("X-Webhook-Signature", "")):
        return "Invalid signature", 401

    event = request.get_json()
    if event["event"] == "payment.success":
        pass  # mark event["order_id"] as paid (keep it idempotent)
    return "OK"

Go-live checklist

  • A payment account is connected and its Test button in the dashboard reports success.
  • The API key lives only in server-side configuration — not in a page, not in an app.
  • You create your local order before calling create-order, and order_id is unique.
  • Your server confirms with the webhook or check-status; it never trusts the redirect, the popup or the screen alone.
  • Your webhook verifies X-Webhook-Signature and answers within 8 seconds.
  • Crediting is idempotent — a refreshed page or a webhook that arrives twice never pays out twice.
  • You made one real small payment end to end and saw it in Transactions.

Try the live demo