Webhooks
Events about your payments, orders and refunds, posted to your server, signed.
On this page
Endpoints#
An endpoint is an HTTPS URL on your server and the events it subscribes to. Create one on the Webhooks page of your dashboard, live or test. Endpoints are settings: the API reads them but makes and changes none, because whoever holds a key could otherwise send every later payment event, and its buyer's email, somewhere else.
The page shows the endpoint's signing secret (whsec_...) once you confirm it's you: keep it,
it is what you verify each delivery with. GET /api/v1/m/webhooks lists your endpoints
and every event one can subscribe to (available_events). Every endpoint call is under Webhooks in the
API reference. A merchant keeps at most 20 endpoints in live mode and 20 in test mode.
Test and live mode#
An endpoint has the mode of the key that made it; one made on the dashboard's Webhooks page is live. Each
event goes only to endpoints of its own mode, so simulate_payment sends payment.received
to test endpoints. Account events (merchant.plan_changed) and on-chain payments are live only.
Events#
| Event | When | data |
|---|---|---|
order.created | An order is made | The order |
order.updated | An order's status changes: paid, cancelled, expired, refunded, shipped | The order |
invoice.created, invoice.paid, invoice.expired | A bitcoin invoice is made, paid, or runs out unpaid | The invoice |
payment.received | A payment is recorded: bitcoin, card, cash, a bank transfer | The payment, with order_id and invoice_id |
payment.confirmed | A payment is final (a Lightning one at once, an on-chain one at its confirmations) | The payment |
payment.flagged | A payment came in for an order that was closed or paid already, and is to be refunded | The payment, with flag_reason |
payment.disputed | A card payment is disputed at its processor | The payment |
refund.created | A refund is recorded, made at once or waiting for approval | The refund (below) |
refund.updated | A refund's status changes: made (completed), cancelled, failed | The refund |
invoice.payment_detected, onchain_payment.held, onchain_payment.reversed | On-chain: a payment seen, one held for your decision, one that left the chain | The invoice or the on-chain payment |
merchant.plan_changed | Your plan changes | Your account and plan |
PrivaPaid: media_key.rotated is sent when a channel's media key is rotated, with the key, never its material.
available_events also lists the subscription.* events, which fire only for a merchant with customer subscriptions.
The payload#
Each delivery is a POST with a JSON body: the event's own id, its name,
livemode, when it happened, and data.
This is payment.received for a Lightning payment:
{
"id": "43372824-c11e-474d-8e2c-c389033cc8d3",
"event": "payment.received",
"livemode": false,
"created_at": "2026-11-16T19:11:19Z",
"data": {
"id": "a937d3b9-be8b-4db6-bb56-7a3868bd3f7a",
"order_id": "e8da24c6-dca4-4da7-8d29-aa6e1e174c05",
"order_number": "ORD-C815383054A988AA",
"invoice_id": "fb31556a-a2c0-406b-99ca-f65958711346",
"amount_sats": 9720,
"payment_method": "lightning",
"preimage": "c48a2c367eb57bfc00c752682694a6a5aef59b8bc2fdd44327fcc804231684cf",
"metadata": { "pos_sale_id": "1042" },
"order_total_amount_cents": 972,
"order_currency": "usd",
"confirmed_at": "2026-11-16T19:11:19Z",
"created_at": "2026-11-16T19:11:19Z"
}
}
data.id is the payment's id. data.metadata is the order's own metadata, as whoever made the order sent it,
so you can match the payment to your sale without another call. data.order_total_amount_cents and
data.order_currency are what the order comes to in the merchant's currency: check them against what you meant to
charge before you deliver. The payload does not carry the order's items, its status or the customer: read them with
GET /api/v1/m/orders/:id. Some kinds of payment add fields of
their own: a bank transfer its rail, amount_cents and currency, for instance.
A refund's event has the same envelope:
{
"id": "4f0c7b8e-1d2a-4c55-9a77-2f3e1b6d9c10",
"event": "refund.created",
"livemode": true,
"created_at": "2026-11-07T18:02:30Z",
"data": {
"id": "b3c4d5e6-...",
"status": "completed",
"kind": "refund",
"refund_method": "cash",
"amount_cents": 1299,
"currency": "usd",
"order_id": "e2a9c072-...",
"order_number": "ORD-C1A6B85074F5890B",
"sale_id": "e2a9c072-...",
"refund_sale_id": "b3c4d5e6-...",
"payment_id": "120be4e9-...",
"location_id": "92f0...",
"line_items": [{ "sale_item_id": "7a1e...", "qty": 1 }],
"refunded_at": "2026-11-07T18:02:30Z",
"made_at": "2026-11-07T18:02:30Z",
"created_at": "2026-11-07T18:02:30Z"
}
}
A refund's order_id is null once its order has been deleted, six months after its sale;
order_number and sale_id still name what it refunds. Amounts are in the
currency's minor unit. A refund's reason and notes are never sent.
Verifying a delivery#
Each delivery carries these headers:
X-SatsRail-Signature | t=<unix seconds>,v1=<hex>: the HMAC-SHA256, keyed with your endpoint's secret, of the timestamp, a full stop and the raw body |
X-Webhook-Timestamp | When it was sent, in unix seconds (the same t) |
X-Webhook-Event | The event |
X-Webhook-Delivery-ID, X-Idempotency-Key | The delivery, the same on every attempt |
X-Webhook-Signature | Deprecated: the HMAC-SHA256 of the body alone, kept while integrations move to X-SatsRail-Signature |
To verify one: split X-SatsRail-Signature into t and v1, compute
the HMAC-SHA256 of t + "." + raw body with your secret, compare it with v1 in
constant time, and refuse the delivery when t is more than five minutes from your clock.
Sign the body exactly as it arrived, before any JSON parsing. The timestamp is what keeps a recorded
delivery from being replayed later: the old X-Webhook-Signature covers the body alone, so a
delivery signed only by it can be sent again at any time. A header that can't be read is refused too:
the samples below answer false to anything malformed, never an exception.
require "openssl"
def satsrail_delivery?(secret, header, raw_body, tolerance: 300)
parts = header.to_s.split(",").filter_map { |part| part.strip.split("=", 2) if part.include?("=") }.to_h
t = Integer(parts["t"].to_s, 10, exception: false)
v1 = parts["v1"].to_s
return false unless t && !v1.empty? && (Time.now.to_i - t).abs <= tolerance
expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{t}.#{raw_body}")
expected.bytesize == v1.bytesize && OpenSSL.fixed_length_secure_compare(expected, v1)
endconst crypto = require("crypto");
function satsrailDelivery(secret, header, rawBody, tolerance = 300) {
const parts = new Map(
String(header ?? "").split(",").map((part) => part.trim().split("=", 2)).filter((pair) => pair.length === 2)
);
const t = Number(parts.get("t"));
const v1 = Buffer.from(parts.get("v1") ?? "");
if (!Number.isInteger(t) || v1.length === 0 || Math.abs(Date.now() / 1000 - t) > tolerance) return false;
const expected = Buffer.from(crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex"));
return expected.length === v1.length && crypto.timingSafeEqual(expected, v1);
}Answers, retries and duplicates#
Answer with any 2xx status within ten seconds. Anything else, or no answer, is a failure, and the
delivery is tried again with the same body, the same payload id and the same
X-Idempotency-Key:
- Payment, invoice, refund, paid-order and on-chain events are tried again 30 seconds after a failure, then twice as long each time, every hour at most, for three days. After three days of failures a delivery is tried no more: it stays on the dashboard's Webhooks page, where you can send it again, and an endpoint that took nothing in all that time is switched off and its owner emailed.
-
order.created, the otherorder.updatedevents,media_key.rotatedandmerchant.plan_changedare tried three times: at once, 30 seconds and 5 minutes later.
Delivery is at least once: a delivery your server took can still arrive again (a timeout after you
answered, a retry from the dashboard). Store the payload id (or
X-Idempotency-Key) in the same transaction as what you do with the event, and answer 2xx
to one you have seen without doing it again.
An endpoint switched off#
You can switch an endpoint off and on from its page. SatsRail switches one off itself, emails you, and sets disabled_at, when:
- ten deliveries in a row of the events tried three times failed every attempt within a day, or
- it took nothing for three days while a payment event was being retried.
While an endpoint is off, every event it subscribes to is kept for it and sent once it is switched on again. A delivery already given up on after three days is not: send it again from the Webhooks page.