Webhooks
Qirsh tells your store about payments by POSTing signed JSON to the project's webhook URL. Set the URL under the project's Settings, Webhook in the dashboard (or WEBHOOK_URL in single-store mode). The signing secret is on the same card (WEBHOOK_SECRET in single-store mode).
Events
| Event | When | What your store does |
|---|---|---|
invoice.confirming |
A matching transfer is on-chain but not yet solidified | Nothing, or show "confirming". Don't ship |
invoice.paid |
The payment is final (solidified), or a person settled the invoice in the dashboard | Check the amount, then fulfil once |
invoice.expired |
The invoice reached expires_at unpaid |
Release stock or cancel the order |
invoice.swept |
Forwarder mode: the funds moved from the deposit address to the project wallet | Accounting only. Never fulfil on it |
ping |
Someone pressed Send test event, or called POST /api/v1/webhooks/test |
Verify the signature and answer 2xx |
An invoice.paid can follow an invoice.expired for the same invoice: a transfer sent before the deadline but detected after it still settles the invoice. A simulated payment also sends a real invoice.paid.
Answer 2xx to event types you don't know. New types may be added.
Payload
{
"id": "evt_8wKq0b1Lr2mN3pQ4sT5uV6",
"type": "invoice.paid",
"created_at": "2026-12-04T07:04:10.150Z",
"data": {
"invoice": {
"id": "inv_Luonp2fQ0b8rR1cS9yZ5w08",
"object": "invoice",
"status": "paid",
"order_id": "ORDER-1001",
"amount": "49.9",
"amount_due": "49.907423",
"amount_paid": "49.907423",
"settled_manually": false,
"tx_id": "7c2d0b5e4f1a...",
"tx_url": "https://tronscan.org/#/transaction/7c2d0b5e4f1a...",
"metadata": { "customer_id": 42 }
}
}
}data.invoice is the full invoice object at the time of the event, shortened here. A ping carries data: { "project_id": "prj_..." } instead.
Forwarder invoices with a network fee
When the operator charges a network fee on a forwarder project, the invoice in every event carries it:
{
"id": "inv_Luonp2fQ0b8rR1cS9yZ5w08",
"status": "paid",
"order_id": "ORDER-1001",
"amount": "49.9",
"amount_due": "51.4",
"amount_paid": "51.4",
"network_fee": { "amount": "1.5", "payer": "customer", "collector": "TCo11ector..." },
"amount_net": "49.9",
"deposit_mode": "forwarder"
}The rules do not change. Fulfil on invoice.paid only, and compare amount_paid with your own price for the order (here 49.90), not with amount_due: when the customer pays the fee, amount_due includes it. amount_net is what reached the project wallet, for your books. The later invoice.swept event adds sweep.amount_swept (to the wallet) and sweep.fee_paid (to the collector). It is for accounting and never triggers fulfilment. In unique-amount mode and without a fee, network_fee is null.
Headers
| Header | Value |
|---|---|
Content-Type |
application/json |
User-Agent |
Qirsh-Webhooks/1.0 |
Qirsh-Signature |
t=<unix seconds>,v1=<hex signature> |
Qirsh-Event-Id |
The event id, same as id in the body |
Verifying signatures
v1 = hex( HMAC_SHA256( webhook_secret, "<t>.<raw request body>" ) )To verify:
- Read the raw request body as bytes, before any JSON parsing.
- Split the header on
,and each part on the first=. Taketandv1. - Reject the request if
tis more than 300 seconds away from your clock. This stops replays. - Compute the HMAC over
t, a., and the raw body, with the project's webhook secret. - Compare it with
v1in constant time. Reject on mismatch with400. - Only then parse the JSON.
Node.js
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyQirsh(rawBody, header, secret, toleranceSeconds = 300) {
if (!header) return false;
const parts = Object.fromEntries(header.split(",").map((kv) => kv.trim().split("=", 2)));
const t = Number(parts.t);
if (!Number.isInteger(t) || !parts.v1) return false;
if (Math.abs(Math.floor(Date.now() / 1000) - t) > toleranceSeconds) return false;
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
const given = Buffer.from(parts.v1, "hex");
return given.length === expected.length && timingSafeEqual(given, expected);
}With the SDK:
import { constructWebhookEvent } from "qirsh-sdk";
// Throws QirshError (code "invalid_signature") on a bad or stale signature.
const event = constructWebhookEvent(rawBody, req.headers["qirsh-signature"], process.env.QIRSH_WEBHOOK_SECRET!);PHP
function qirsh_verify(string $raw, ?string $header, string $secret, int $tolerance = 300): bool {
if (!$header) return false;
parse_str(str_replace(',', '&', $header), $p);
if (!isset($p['t'], $p['v1']) || !ctype_digit($p['t'])) return false;
if (abs(time() - (int)$p['t']) > $tolerance) return false;
$expected = hash_hmac('sha256', $p['t'] . '.' . $raw, $secret);
return hash_equals($expected, $p['v1']);
}
$raw = file_get_contents('php://input');
$ok = qirsh_verify($raw, $_SERVER['HTTP_QIRSH_SIGNATURE'] ?? null, getenv('QIRSH_WEBHOOK_SECRET'));Python
import hashlib, hmac, time
def verify_qirsh(raw: bytes, header: str | None, secret: str, tolerance: int = 300) -> bool:
if not header:
return False
try:
parts = dict(p.strip().split("=", 1) for p in header.split(","))
t = int(parts["t"])
except (KeyError, ValueError):
return False
if abs(time.time() - t) > tolerance:
return False
expected = hmac.new(secret.encode(), f"{t}.".encode() + raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts.get("v1", ""))A worked example
Use this to test your code. With the tolerance check turned off (the timestamp is in the past), your function must accept it.
Secret:
whsec_test_0123456789abcdef0123456789Body (exact bytes, no trailing newline):
{"id":"evt_test","type":"ping","created_at":"2026-01-01T00:00:00.000Z","data":{"project_id":"prj_test"}}Header:
Qirsh-Signature: t=1767225600,v1=eea70955f9375b77428ff23dadb317e98613176cfaf656aa182d2064230831fcCheck it from a shell:
printf '%s' '1767225600.{"id":"evt_test","type":"ping","created_at":"2026-01-01T00:00:00.000Z","data":{"project_id":"prj_test"}}' \
| openssl dgst -sha256 -hmac 'whsec_test_0123456789abcdef0123456789'
# SHA2-256(stdin)= eea70955f9375b77428ff23dadb317e98613176cfaf656aa182d2064230831fcIf one space or key order differs, the signature differs. That is why you must verify the raw bytes.
Getting the raw body
| Framework | How |
|---|---|
| Express | express.raw({ type: "application/json" }) on the webhook route, registered before app.use(express.json()). req.body is a Buffer |
| Next.js (App Router) | const raw = await req.text() in the route handler. Don't call req.json() first |
| Next.js (Pages Router) | export const config = { api: { bodyParser: false } } and read the stream |
| Laravel | $request->getContent(), header $request->header('Qirsh-Signature'). Put the route in routes/api.php or exclude it from CSRF |
| Django | request.body, header request.headers.get("Qirsh-Signature"). Mark the view @csrf_exempt |
| Flask | request.get_data() |
| FastAPI | await request.body(). Take request: Request, not a Pydantic model |
Exclude the webhook route from CSRF protection, session auth and any middleware that rewrites the body.
Delivery and retries
- A
2xxresponse within 10 seconds counts as delivered. Anything else (another status, a timeout, a connection error) is a failure. - Redirects are not followed. A
301or302counts as a failure, so use the final URL. - Failed deliveries are retried after 10 s, 30 s, 2 min, 10 min, 30 min, 1 h, 3 h, 6 h, 12 h and 24 h (about 47 hours in all). After the last attempt the event is marked
failed. - Retries use the project's current webhook URL and secret. If you fix the endpoint or rotate the secret, queued retries pick up the change.
- Events sit in an outbox in the database, so they survive restarts.
pingtest events are sent once and not stored or retried.
Answer quickly. If fulfilment is slow, record the event and do the work in a background job.
Duplicates and ordering
The same event can arrive more than once, for example when your server processed it but the response was lost, or someone retried it from the dashboard or the API. Events can also arrive out of order after retries. So:
- Make the handler idempotent. Use conditional updates (
... WHERE status <> 'paid'), or store processed event ids (id, also inQirsh-Event-Id) and skip repeats. - Decide from the invoice in the payload (
data.invoice.status,amount_paid), not from the order in which events arrive. A lateinvoice.confirmingmust not move a paid order back. - If in doubt, fetch the invoice with
GET /api/v1/invoices/{id}from your server.
Webhook URL rules
For projects managed in the dashboard, the gateway refuses webhook URLs that resolve to localhost, private networks (10/8, 172.16/12, 192.168/16, 100.64/10), link-local or other non-public addresses. The check runs at each delivery, after DNS resolution. This stops project users from pointing the gateway at services on its own network.
For local development the operator can set ALLOW_PRIVATE_WEBHOOKS=true. The single-store project from .env is trusted and may use any URL. Otherwise, expose your local store through a tunnel (see Testing).
Webhook URLs must be http(s). Use HTTPS in production.
The dashboard webhook log
The project's Webhooks tab lists recent events with their status, attempts and last result (HTTP status or error). From there you can:
- Retry now on an event that is pending or failed. It is queued for delivery right away. To redeliver an event that was already delivered (for example to test idempotency), call
POST /api/v1/webhooks/:id/retry, which accepts any event. - Send test event, which sends a signed
pingand shows the result right away.
The same is available through the API: GET /api/v1/webhooks, POST /api/v1/webhooks/:id/retry, POST /api/v1/webhooks/test.
Rotating the secret
In Settings, Webhook, press Rotate. The new secret takes effect at once for new deliveries and queued retries, and the old one stops working. Update your store's QIRSH_WEBHOOK_SECRET at the same time. Deliveries that fail in between are retried, so a short gap loses nothing.
In single-store mode, change WEBHOOK_SECRET in .env (24 characters or more, for example openssl rand -hex 32) and restart the gateway.