Reference
Webhooks
Find out when a payment is confirmed, and check that the message really came from Switro.
Set up webhooks
Open Settings, then API. Add a public https address on your server, then save it. Webhooks cannot reach localhost.

Your secret is created when Switro sends your first webhook. Make one devnet payment, then reload the page to see it. It starts with whsec_. Your server can safely refuse this first webhook.
Devnet and mainnet have different secrets
Set the address for your whole account here. A webhook address saved on one payment link is not used.
What Switro sends
Switro sends a POST request when a payment is confirmed:
Content-Type: application/json
Switro-Webhook-Id: WEBHOOK_ID
Switro-Signature: t=1764500000,v1=SIGNATURE{
"event": "payment.confirmed",
"account_id": "ACCOUNT_ID",
"mode": "devnet",
"payment_id": "PAYMENT_ID",
"checkout_id": "CHECKOUT_ID",
"payment_link_id": null
}Switro-Webhook-Id stays the same if Switro sends the webhook again.
A webhook does not include the amount
payment_id to get the payment from the API, then check it.Check the signature
This works with Node.js, and needs nothing else:
import { createHmac, timingSafeEqual } from "node:crypto";
const MAX_AGE_SECONDS = 5 * 60;
/**
* Returns the event if the webhook is from Switro, or null if it is not.
*
* @param {Uint8Array | string} body The raw body, exactly as it was received
* @param {string | null | undefined} header The Switro-Signature header
* @param {string} secret The whole webhook secret, including "whsec_"
* @param {number} [now] The current time in seconds, for tests
*/
export function verifySwitroWebhook(body, header, secret, now = Date.now() / 1000) {
// Without a secret, anyone could create a valid signature.
if (!secret) throw new Error("The Switro webhook secret is not set");
const match = /^t=(\d{1,12}),v1=([0-9a-f]{64})$/.exec(header ?? "");
if (!match) return null;
const [, timestamp, signature] = match;
if (Math.abs(now - Number(timestamp)) > MAX_AGE_SECONDS) return null;
const expected = createHmac("sha256", secret).update(`${timestamp}.`).update(body).digest();
if (!timingSafeEqual(expected, Buffer.from(signature, "hex"))) return null;
try {
return JSON.parse(Buffer.from(body).toString("utf8"));
} catch {
return null;
}
}The checkout sample shows it working. In another language:
- Get the raw body, before anything changes or parses it.
- Get
tandv1fromSwitro-Signature. - Refuse it if
tis more than 5 minutes before or after the current time. - Make an HMAC-SHA256 of
t, a full stop and the raw body, as small-letter hex. The key is the whole secret, includingwhsec_. - Compare it with
v1, using a constant-time function. If they are different, answer400.
Never turn this check off
Mark the order as paid
- Check the signature.
- Save the payment ID, then answer
204. Do the remaining steps in a background job. - Get the payment from the API. If that fails, try again later.
- Find your order with the
checkout_idorpayment_link_idfrom the API, not from the webhook. - Check that
statusisconfirmed, and that the amount and network match the order. - In one database transaction, save the unique payment ID and mark the order as paid. Deliver the order only once.
- If another payment has already paid for that order, contact the customer. They may need a refund.
If a webhook is missed
- Switro waits up to 8 seconds for an answer. Any
2xxmeans that you received it. - After a timeout,
408,429or5xx, it tries again after about 2 seconds, then 10. That is up to three times in total. - It does not try again after any other answer, including a redirect.
Don't rely only on webhooks
payments:read. For store orders, check paid on each unpaid order.