API docs
Base URL: your server, e.g. https://gateway.example.com. Every request needs your secret key:
Authorization: Bearer sk_test_… (test mode, fake money) Authorization: Bearer sk_live_… (live mode)
Keep secret keys on your server. Never put them in a browser or an app.
1. Create a payment
POST /v1/payments
Content-Type: application/json
Idempotency-Key: order-1042-try-1 (optional, recommended)
{
"amount": 499.50, // rupees, max 2 decimals
"reference": "ORDER-1042", // your order id, once per mode
"description": "Annual plan",
"success_url": "https://yourshop.com/thanks?order=1042",
"cancel_url": "https://yourshop.com/cart",
"notify_url": "https://yourshop.com/payment-webhook", // optional, overrides the dashboard URL
"metadata": { "customer_id": "77" }
}
Response 201:
{
"id": "pay_8k2…", "object": "payment", "livemode": false, "status": "pending",
"amount": 499.5, "currency": "NPR", "reference": "ORDER-1042",
"checkout_url": "https://…/pay/pay_8k2…",
"qr": { "image": "data:image/…", "payload": "…" },
"expires_at": "2026-11-27T10:15:00Z", …
}
Then either redirect the customer to checkout_url, or show qr.image on your own page.
2. Get told when it's paid
We confirm every payment with the provider ourselves, then POST an event to your webhook URL:
X-Saancho-Event-Id: evt_…
X-Saancho-Signature: t=1764230000,v1=5f1c…
{ "id": "evt_…", "type": "payment.succeeded", "livemode": false, "data": { …payment… } }
Event types: payment.succeeded, payment.failed, payment.expired, payment.canceled, test.ping.
Always verify the signature with your whsec_ secret (dashboard → Webhooks):
// Node.js
import crypto from "node:crypto";
function verify(secret, header, rawBody) {
const p = Object.fromEntries(header.split(",").map((x) => x.split("=")));
if (Math.abs(Date.now() / 1000 - Number(p.t)) > 300) return false; // older than 5 min
const want = crypto.createHmac("sha256", secret).update(`${p.t}.${rawBody}`).digest("hex");
return crypto.timingSafeEqual(Buffer.from(want), Buffer.from(p.v1 || ""));
}
// PHP
function verify($secret, $header, $rawBody) {
parse_str(str_replace(',', '&', $header), $p);
if (abs(time() - (int)$p['t']) > 300) return false;
$want = hash_hmac('sha256', $p['t'] . '.' . $rawBody, $secret);
return hash_equals($want, $p['v1'] ?? '');
}
Answer with any 2xx. Otherwise we retry 6 more times over about 9 hours. The same event can arrive twice, so use data.id to mark an order paid only once.
3. Other calls
GET /v1/payments/{id} → the payment (use it to double-check before delivering)
GET /v1/payments?status=succeeded&limit=50
POST /v1/payments/{id}/cancel → only while pending
Statuses
pending → succeeded | failed | expired | canceled. A finished payment never changes again.
If the customer pays a different amount, the payment becomes failed with failure_reason: "amount_mismatch". Check it by hand.
Errors
{ "error": { "code": "invalid_amount", "message": "…" } }
Common codes: invalid_key 401, duplicate_reference 409, idempotency_conflict 409, provider_not_connected 409, live_disabled 403, rate_limited 429.
Testing
With an sk_test_ key, open the checkout_url and use Simulate paid / failed / wrong amount. Webhooks fire just like live. Test mode also accepts http://localhost webhook URLs.