API reference
Webhooks
JagPay calls your server when a payment is paid or a payout settles, so you don't have to poll. Every request is signed so you can trust it.
Setup#
- Pass a
webhook_url(https) when you create a payment or payout. Each one can point to a different URL. - Copy your webhook signing secret from Settings → Webhooks → Reveal and store it on your server, e.g.
JAGPAY_WEBHOOK_SECRET. One secret per project. - Verify the
JagPay-Signatureheader on every request (below), then respond with any2xxwithin 10 seconds.
Every delivery is a POST with a JSON body and these headers:
POST /hooks/jagpay HTTP/1.1Content-Type: application/jsonUser-Agent: JagPay-Webhooks/1.0JagPay-Event: payment.paidJagPay-Delivery: evt_Qm3x9T2kLp7Vw4RbJagPay-Signature: t=1764151920,v1=6f1d2c…9ab0| Header | Value |
|---|---|
JagPay-Event | The event name, e.g. payment.paid. |
JagPay-Delivery | Delivery ID (evt_…), the same as id in the body. Stays the same across retries: use it to deduplicate. |
JagPay-Signature | t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>" with your webhook secret> |
Events#
The body is { id, event, created_at, data }. data is the full payment or payout object, the same as the API returns.
| Event | When | data |
|---|---|---|
payment.paid | A payment is fully paid (or you accepted an underpaid / late one) and credited to your balance. | Payment, plus tx_hashes |
payout.sent | A payout (or refund) with a webhook_url is confirmed on-chain. | Payout with tx_hash |
payout.failed | A payout failed on-chain. Payouts and settlements are re-credited (minus the network fee); failed refunds are held for manual handling. | Payout |
payment.paid
{ "id": "evt_Qm3x9T2kLp7Vw4Rb", "event": "payment.paid", "created_at": "2026-11-26T10:12:00.000Z", "data": { "payment_id": "pay_8kQ2mZx7LrT4bW9e", "order_id": "order_4821", "order_name": "Annual plan", "notes": null, "status": "paid", "pricing_currency": "USD", "amount_usd": "250", "fee_usd": "1.25", "accepted_currencies": [ "BSC_USDT", "ETH_USDT", "TRON_USDT" ], "testnet": false, "fee_payer": "customer", "currency": "BSC_USDT", "amount": "250", "fee": "1.25", "pay_amount": "251.25", "received_amount": "251.25", "net_amount": "250", "address": "0x8f3A6b2C91d4E5f708A1b2C3d4E5f6A7b8C992c1", "payment_url": "https://www.jagpay.io/pay/pay_8kQ2mZx7LrT4bW9e", "success_url": "https://shop.example/thanks", "cancel_url": "https://shop.example/cart", "webhook_url": "https://shop.example/hooks/jagpay", "refund_address": null, "expires_at": "2026-11-26T11:00:00.000Z", "paid_at": "2026-11-26T10:12:00.000Z", "created_at": "2026-11-26T10:00:00.000Z", "tx_hashes": [ "0x5e1c0b7a2f3d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789ab" ] }}payout.sent
{ "id": "evt_Rk8w2N5pXc1Lm7Ts", "event": "payout.sent", "created_at": "2026-11-26T10:12:00.000Z", "data": { "payout_id": "po_2Hk9sLq4Xv7Bn1Cz", "kind": "payout", "payment_id": null, "status": "sent", "currency": "BSC_USDT", "address": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F", "amount": "1200", "fee": "6", "gas_fee": "0.12", "total": "1206.12", "tx_hash": "0x9a8b7c6d5e4f30211fedcba9876543210fedcba9876543210fedcba98765432", "order_id": "supplier-0091", "notes": "November invoice", "webhook_url": "https://shop.example/hooks/jagpay", "created_at": "2026-11-26T10:00:00.000Z", "updated_at": "2026-11-26T10:04:00.000Z" }}payout.failed
{ "id": "evt_Hn4q8V2sMb6Zp3Wy", "event": "payout.failed", "created_at": "2026-11-26T10:12:00.000Z", "data": { "payout_id": "po_2Hk9sLq4Xv7Bn1Cz", "kind": "payout", "payment_id": null, "status": "failed", "currency": "BSC_USDT", "address": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F", "amount": "1200", "fee": "6", "gas_fee": "0.12", "total": "1206.12", "tx_hash": null, "order_id": "supplier-0091", "notes": "November invoice", "webhook_url": "https://shop.example/hooks/jagpay", "created_at": "2026-11-26T10:00:00.000Z", "updated_at": "2026-11-26T10:04:00.000Z" }}Verify signatures#
Compute HMAC-SHA256(secret, "<t>.<raw body>") and compare it to v1 with a constant-time comparison. Reject requests whose t is more than 5 minutes old to block replays.
import crypto from "node:crypto";import express from "express";function verifyWebhook(rawBody, header, secret, toleranceSeconds = 300) { const parts = Object.fromEntries(header.split(",").map((p) => p.trim().split("="))); const timestamp = Number(parts.t); if (!parts.v1 || !Number.isInteger(timestamp)) return false; if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) return false; // replayed or stale const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex"); const a = Buffer.from(parts.v1, "hex"); const b = Buffer.from(expected, "hex"); return a.length === b.length && crypto.timingSafeEqual(a, b);}const app = express();// Use the raw body: the signature covers the exact bytes we sent.app.post("/hooks/jagpay", express.raw({ type: "application/json" }), async (req, res) => { const raw = req.body.toString("utf8"); if (!verifyWebhook(raw, req.get("JagPay-Signature") ?? "", process.env.JAGPAY_WEBHOOK_SECRET)) { return res.status(400).send("invalid signature"); } const event = JSON.parse(raw); // Deliveries can repeat: skip events you've already handled. if (await alreadyProcessed(event.id)) return res.sendStatus(200); if (event.event === "payment.paid") await fulfilOrder(event.data.order_id); if (event.event === "payout.sent") await markPayoutDone(event.data.payout_id, event.data.tx_hash); if (event.event === "payout.failed") await alertTeam(event.data.payout_id); res.sendStatus(200); // any 2xx within 10 seconds counts as delivered});Verify against the raw body
Parse the JSON only after verifying. Re-serializing a parsed body changes the bytes and the signature won't match.Retries#
We send each event right away. If your endpoint doesn't return a 2xx within 10 seconds (or redirects), we retry after 1, 2, 5, 15 and 30 minutes, then 1, 2, 4, 8 and 12 hours: 11 attempts over about a day. After that the delivery is marked failed.
- Deliveries are at-least-once: the same event can arrive more than once. Deduplicate on
id/JagPay-Delivery. - Events can arrive out of order. If you need the latest state, retrieve the payment or payout.
- Missed one? Resend it from the dashboard or with
POST /api/v1/payments/:id/webhooks/resend/POST /api/v1/payouts/:id/webhooks/resend. - Rotating the secret (Settings → Webhooks → Rotate) takes effect immediately; deploy the new secret first.
