{"object":"doc","slug":"webhooks","title":"Webhooks: register, verify, retry","summary":"Register an HTTPS endpoint (an empty filter means payment events only; billing events are opt-in), verify the ZeroPoint-Signature header in ten lines, handle retries and out-of-order events, catch up from the event list, and rotate secrets without downtime.","tags":["guide","webhooks","events","security"],"body":"# Webhooks\n\n## 1. Register\n\n```\nPOST /v1/webhooks\n{\"url\":\"https://api.acme.test/zeropoint/webhook\",\"event_types\":[\"payment.succeeded\",\"payment.failed\",\"refund.succeeded\"]}\n```\nThis call requires an `Idempotency-Key` header, like every POST that creates something. Register each URL once per environment: `GET /v1/webhooks` (the `list_webhooks` tool) lists what exists, and every event is delivered once per active endpoint, so a URL registered twice receives everything twice. The `register_webhook` tool answers with a `warning` and `existing_endpoint_ids` when an active endpoint already posts to that URL. Response `201` includes `secret` (starts with `whsec_`), shown exactly once. The URL must be `https` on a public host; `localhost`, private addresses, multicast addresses, translation addresses that wrap a private one (NAT64, IPv4-mapped, 6to4, Teredo) and any IPv6 address outside global unicast space (`2000::/3`) are rejected with `webhook_url_invalid`. So is a host name that does not resolve within 3 seconds (`did not resolve in time`); if the message says the name could not be looked up right now, the resolver was busy and the same request will work in a few seconds. We look your host name up at most about once a minute, so allow a minute for a DNS change to take effect. While you have no receiver yet, `POST /sandbox/webhook-sink` on the hosted service accepts anything and answers 200.\n\nWhat `event_types` subscribes to:\n\n| `event_types` | Receives |\n|---|---|\n| empty or left out | Every payment event (the list at the end of this guide). No billing event, now or later. |\n| `[\"*\"]` | Every event type, payment and billing, including types added later. `\"*\"` must be the only entry. |\n| a list of names | Exactly those types. Up to 50 names. |\n\nBilling events (checkout, invoice, subscription, customer and payment method events) are opt-in: they go only to endpoints that list them or use `[\"*\"]`. An endpoint registered with no types gets no billing event and no error, so a Stripe-style integration that registers an endpoint with no types and waits for `invoice.paid` waits forever. Name the types, or use `[\"*\"]`. `billing-webhooks` lists them and what each carries.\n\nUse a separate endpoint for billing events. Pauses are per endpoint (section 5), so a bug in a billing handler that makes it answer non-2xx would also delay the payment events sharing that endpoint.\n\n## 2. What arrives\n\n```\nPOST <your url>\nZeroPoint-Signature: t=1757100000,v1=5f3c...\nZeroPoint-Event-Id: evt_01j...\nZeroPoint-Delivery-Id: dlv_01j...\nContent-Type: application/json\n\n{\"object\":\"event\",\"id\":\"evt_01j...\",\"created\":1757100000,\"livemode\":false,\"type\":\"payment.succeeded\",\"merchant_id\":\"mch_01j...\",\"data\":{\"object\":{\"object\":\"payment\",\"id\":\"pay_01j...\",\"state\":\"succeeded\",\"...\":\"...\"}},\"api_version\":\"2026-09-05\"}\n```\n`data.object` is the full object as it looked when the event fired. A payment object always has a `partial_approval` field: `null` unless the processor approved the sale for less than was asked, then `processor_transaction_id`, `approved_amount_cents`, `requested_amount_cents`, `reversed` and `reversed_at` (see the payment states guide). Answer any `2xx` within 10 seconds; do slow work after responding. The 10 seconds is one deadline for the whole exchange (looking up your host name, connecting, TLS, sending the event, and receiving your status line and headers), not a pause allowed between bytes: a receiver that has not finished its response headers by then is recorded as `timed out after 10s`, however much it had sent. Only the status code is used; the response body is never read. Aim for well under 5 seconds: a `2xx` that takes 5 seconds or longer is delivered, but counts against the endpoint exactly like a failure when it comes to pausing it (section 5).\n\n## 3. Verify the signature\n\nThe signed payload is `\"{t}.{raw_body}\"`, the digest is HMAC-SHA256 hex with your secret, and `t` must be within 5 minutes of now.\n\nPython:\n```python\nimport hmac, hashlib, time\n\ndef verify(header: str, body: bytes, secret: str) -> bool:\n    parts = dict(p.split(\"=\", 1) for p in header.split(\",\"))\n    ts = int(parts[\"t\"])\n    if abs(time.time() - ts) > 300:\n        return False\n    expected = hmac.new(secret.encode(), f\"{ts}.\".encode() + body, hashlib.sha256).hexdigest()\n    return any(hmac.compare_digest(expected, v) for k, v in\n               (p.split(\"=\", 1) for p in header.split(\",\")) if k == \"v1\")\n```\n\nNode:\n```js\nconst crypto = require(\"crypto\");\nfunction verify(header, rawBody, secret) {\n  const parts = header.split(\",\").map(p => p.split(\"=\"));\n  const t = parts.find(([k]) => k === \"t\")[1];\n  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;\n  const expected = crypto.createHmac(\"sha256\", secret).update(`${t}.`).update(rawBody).digest(\"hex\");\n  return parts.filter(([k]) => k === \"v1\").some(([, v]) =>\n    v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));\n}\n```\nUse the raw request body bytes, not a re-serialized JSON object.\n\n## 4. Prove it works\n\n```\nPOST /v1/webhooks/{webhook_id}/test\n```\nDelivers one `webhook.test` event right now, waits up to 5 seconds for your answer (`/test` and `/verify` use a shorter deadline than the 10 seconds a normal delivery gets), and returns the delivery with `status: delivered` or `failed` plus `response_status` and `last_error`. A delivered signed event is what `integration_checklist` counts as the legacy `webhook_verified` milestone, recorded on the endpoint so it outlives the 30-day delivery history. That name is retained for compatibility: it proves delivery only. The step's `evidence` reports `signed_test_delivered`, `receiver_signature_validation: not_recorded` and `business_effect_deduplication: not_observed`. Neither this milestone nor a successful `/test` call proves that your receiver rejects bad signatures.\n\nSample billing events, test mode only. Send `/test` a body with `event_type` and `merchant_id` to get one sample of a billing type instead of `webhook.test` (the `send_sample_event` tool is the same call):\n\n```\nPOST /v1/webhooks/{webhook_id}/test\n{\"event_type\":\"invoice.paid\",\"merchant_id\":\"mch_01j...\"}\n```\nThe sample is the documented payload of that type, with `\"sample\": true` beside `data.object`, your test merchant as `merchant_id`, and ids that exist nowhere (a prefix and 26 zeros, so a GET answers 404). It goes to this endpoint only, and only if the endpoint subscribes to the type; otherwise the answer is `400 parameter_invalid` and nothing is sent. A live key gets `403 live_mode_unavailable`. Samples share the budget below and count toward the sandbox's daily event ceiling. A sample also appears in `GET /v1/events`, so a handler that acts on events should skip any event whose `data.sample` is true. A sample proves your parsing, never your business effects: for those, drive the real flow in the sandbox.\n\n```\nPOST /v1/webhooks/{webhook_id}/verify\n```\nRuns the scorecard (the `verify_webhook` tool is the same call) and returns a `webhook_scorecard` with `passed` and four checks:\n\n| check | Your receiver must |\n|---|---|\n| `signed_event_delivered` | Answer 2xx to a correctly signed `webhook.test` event |\n| `responds_fast` | Answer within 5 seconds (do slow work after responding) |\n| `replay_accepted` | Answer 2xx again when the same `ZeroPoint-Event-Id` arrives a second time, and ignore the repeat |\n| `bad_signature_rejected` | Answer a non-2xx (401 is conventional) to a delivery whose signature does not verify |\n\nThe scorecard names both deliveries: `delivery_id` is the signed send and `replay_delivery_id` is the repeat of the same event id (null when the first delivery failed or was not fast). When the first send fails or takes 5 seconds or longer the run stops there: `replay_accepted` and `bad_signature_rejected` come back `passed: false` with a `detail` saying they were not run, so fix that first and run verify again. Both appear in `GET /v1/webhooks/{webhook_id}/deliveries`, so two `webhook.test` rows with one event id are one scorecard run, not a bug; the bad-signature probe does not appear, because it is not an event. The hosted `/sandbox/webhook-sink` passes the first three checks only: it answers 200 to everything, including the bad signature. Neither `/test` nor `/verify` takes an `Idempotency-Key`, and neither does `/redeliver` below: each is a deliberate fresh attempt, not a request you would ever want replayed from a cache.\n\n`/test` and `/verify` wait for your receiver, so they are limited. One run at a time per account, and only a few across the whole service at once (some of those are kept for live-mode keys). In any 10 minutes: at most 10 runs per endpoint and 30 per account, test and verify together, one verify being one run; and at most 30 seconds, per account, of runs waiting on your receiver, so a receiver that answers in 100 ms never notices this and one that takes 5 seconds uses it up in six sends. Past any of these the answer is `429 rate_limited` with a `Retry-After` header and nothing was sent: wait that many seconds and call again. The `verify_webhook` tool has the same limits; its error message carries the seconds to wait.\n\n## Developing locally\n\nZeroPoint never delivers to `localhost`, a private address or plain `http`: that refusal protects the service and stays on. Three ways to run your receiver on your own machine, test mode only:\n\n1. The listen helper in the `zeropoint.node.subscriptions` snippet (`listen.mjs`, `get_snippet`). Register an endpoint at a public URL you own, or at the hosted `/sandbox/webhook-sink`, keep its `whsec_` secret, and run `listen({apiBase, apiKey, secret, webhookId, forwardTo: 'http://localhost:3000/webhooks/zeropoint'})` beside your app. Every 2 seconds it reads that endpoint's new deliveries (`GET /v1/webhooks/{webhook_id}/deliveries`) and each event (`GET /v1/events/{event_id}`), and posts it to your local URL with the same body bytes and the same `ZeroPoint-Signature`, `ZeroPoint-Event-Id` and `ZeroPoint-Delivery-Id` headers a delivery has, signed with your secret on your machine. Your real verification code runs unchanged. ZeroPoint shows a secret once, when you register or rotate the endpoint, and no route reads it back; the helper uses the one you already hold. It refuses a `zp_live_` key, an `http://` API base other than this machine, and a non-loopback target, never follows a redirect from your receiver, and does not rebuild the Stripe view of an endpoint with `stripe_compatible_payload`.\n2. A tunnel: any HTTPS tunnel to your machine gives you a public HTTPS URL to register. Deliveries then arrive for real, with retries, and `verify_webhook` scores your receiver.\n3. Polling instead of a receiver: `GET /v1/events` (MCP `list_events`) with `types` and `since` returns the same events with `data.object`; apply each `event.id` once. Use it to catch up, or while you have no receiver.\n\nOn a test clock, events are delivered a few seconds after `get_test_clock` reports `ready` (see `test-billing-with-test-clocks`).\n\n## 5. Retries and idempotency\n\nA non-2xx or a timeout is retried on one of two schedules. Which one is fixed when the delivery is created, and `GET /v1/webhooks/{webhook_id}/deliveries` shows each delivery's `attempt` and `next_attempt`:\n\n| Delivery | Retried after each failure | Attempts | Dead at the latest |\n|---|---|---|---|\n| Payment events, and every delivery in test mode | 1, 5 and 15 minutes | 4 attempts, the last 21 minutes after the first | 24 hours after it was created |\n| Billing events delivered to a live endpoint | 1, 5 and 15 minutes, then 1, 3, 6, 12, 24 and 24 hours | 10 attempts, the last 70 hours 21 minutes after the first | 72 hours after it was created |\n\nPayment events, and every delivery in test mode, keep the short schedule: a payment usually has an API answer behind it, test endpoints are often left unanswered, and test events are deleted after 14 days. A billing event (a renewal, a cancellation) often has no request behind it, so in live mode it gets about 3 days, as at Stripe. Billing events are opt-in (section 1), so an endpoint that does not list them never sees this schedule. After the last attempt the delivery is `dead`. The same event can arrive more than once: store `ZeroPoint-Event-Id` (or `id`) and ignore repeats. Inspect attempts with `GET /v1/webhooks/{webhook_id}/deliveries`, and resend one with `POST /v1/deliveries/{delivery_id}/redeliver` after fixing your receiver.\n\nDelivery order is not guaranteed, between endpoints or within one: a retry, a redelivery or a pause can put a later event ahead of an earlier one. Never order by arrival, and not by `created` either: it is whole seconds, and one change can write several events in the same second.\n\nWhat is ordered is the ledger. `GET /v1/events` and the `list_events` tool list events newest first in event id order, and for billing events id order is the order they were written: events written together in one change are listed in the order written, and a later change's events come after. Use the list, not arrival order, when order matters.\n\nHow to handle events that arrive late or out of order:\n\n1. Deduplicate by event id, and only by event id. Run each event's handler once per `id`, whatever else the event says.\n2. Billing events carry `data.object_version`, a number per object that rises with each change. Use it only to decide whether to replace your stored copy of the object: replace it when the event's `object_version` is greater than or equal to the one you stored, and keep your copy when it is lower. Never use it to skip a handler. One change can send two events for one object with the same `object_version` (`invoice.paid` and `invoice.payment_succeeded`, `invoice.payment_failed` and `invoice.voided`, `invoice.payment_failed` and `invoice.marked_uncollectible`), and a rule that drops an event whose version is not higher than the last one loses the second event of each pair.\n3. Decide access and plan from your stored copy after step 2, not from the `data.object` of the event in hand. A late `customer.subscription.updated` showing `active` must not give access back after a newer `customer.subscription.deleted` was stored. Event-specific actions, such as sending a receipt on `invoice.paid`, run once per event id.\n4. Or, when order matters, read the current object from the API instead of trusting the event's copy.\n\nCatching up. A delivery that dies is not sent again on its own, so a receiver that was down for longer than its retry window misses those events. Every event stays in `GET /v1/events`, on either schedule and after its delivery is `dead`, so that list is the catch-up path: poll it every few minutes and on startup, and pass each event through the same handler, deduplicated by id. Set `since` to the newest `created` you have handled minus 300, and repeat `types` once per type you handle:\n\n```\n/v1/events?since=1797381700&types=invoice.paid&types=customer.subscription.deleted\n```\n`types` takes up to 50 names and cannot be combined with `type`. Page to the end: pass `next_cursor` as `cursor` until `has_more` is false. Keep the 300-second overlap: `since` compares `created`, which is set when an event is written, not when its change is saved, so an event can show up in the list a moment after a later one, and a poll that starts exactly at the newest `created` it saw could miss it. The overlap also covers whole-second `created` values and your own clock. Reading an event twice costs nothing, because the handler deduplicates by id.\n\nDeliveries are sent a few per endpoint and per account at a time, taking turns between accounts and endpoints, live mode first with a share of every pass kept for test mode, so a backlog or a slow receiver on one endpoint does not hold up another.\n\nPauses. After three strikes in a row on one endpoint, a strike being a failed attempt or a `2xx` that took 5 seconds or longer, sending to it pauses for 1 minute, then 5, then 15 for as long as the strikes continue. While it is paused, its due deliveries are postponed to the end of the pause without using an attempt; `next_attempt` shows the postponed time. When the pause ends one delivery is sent as a probe:\n\n- A prompt `2xx` ends the pause. The postponed deliveries go out straight away, a few per pass.\n- A slow `2xx` is delivered, and the pause starts again. Nothing else is charged.\n- A failure starts the pause again and counts as a failed attempt for every delivery of that endpoint that was due, not only the one that was sent: each uses one of its attempts and takes its next retry delay, with `last_error` beginning `not sent: endpoint paused after repeated failures`. A delivery that is not yet due is not charged. A delivery is only ever `dead` after all its attempts (4, or 10 on the long schedule) counted this way or made for real, or at a limit below.\n\nLive billing deliveries have their own pauses, kept apart from the endpoint's payment deliveries: a billing handler that keeps failing never pauses or charges payment deliveries, and the other way round. In test mode billing deliveries are on the short schedule and share the endpoint's pauses with payment events. When our service restarts it forgets pauses, so until an endpoint answers again it gets one live billing delivery per pass; the rest wait, uncharged.\n\nWhat this means for timing on the short schedule: a retry is never sooner than the 1, 5, 15 minute schedule, and can be later. Against an endpoint that never answers, the deliveries that were first to fail are `dead` 21 minutes after they were first due, exactly as the schedule says; a backlog queued behind them is `dead` one pause later, at 36 minutes; and the worst case for any delivery, one that becomes due just after a probe has failed, is 60 minutes (four pauses of 15). Nothing waits longer than that for a dead endpoint. On the long schedule a retry is likewise never sooner than its step and can be up to one pause (15 minutes) later; against an endpoint that never answers a live billing delivery is `dead` about 70 hours 21 minutes after it was first due, and never later than 72 hours after it was created.\n\nAge limit. A delivery still not delivered 24 hours after it was created (72 hours on the long schedule) is marked `dead` with `last_error` beginning `not delivered within 24 hours` (or `not delivered within 72 hours`; any earlier error follows it), however many attempts it has used. In practice it applies to a queue behind a receiver that keeps being paused for slow answers without ever failing. A `dead` delivery, from this or from its last attempt, can still be sent again with `redeliver`, and the event stays in `GET /v1/events`.\n\nBacklog limit. One endpoint holds at most 10,000 live billing deliveries waiting to be sent. Past that, the oldest are marked `dead` with `last_error` beginning `backlog limit`. Nothing is deleted: their events stay in `GET /v1/events`.\n\nWhen live billing deliveries die, you hear about it without polling. The delivery list shows each one with `status: dead`, and we email your account's contact email with the endpoint URL, how many billing events died and their event ids, once per endpoint per day at most while more die. Fetch the events from `GET /v1/events` with `types` (catching up, above) and redeliver from the console or with `POST /v1/deliveries/{delivery_id}/redeliver`.\n\nGetting back after you fix a receiver: any prompt `2xx` from it ends the pause, and a successful `POST /v1/webhooks/{webhook_id}/test` is the quick way to produce one. Deliveries the pause had postponed then go out at once; deliveries that have already failed, or were charged for a failed probe, keep their own retry time (`next_attempt`), or you can `redeliver` them.\n\n`redeliver` answers `429 rate_limited` with `Retry-After`, and queues nothing, while the endpoint already has 10 or more deliveries waiting for their first attempt. If the endpoint is paused, `Retry-After` is the rest of the pause and the message says so; a successful `/test` ends the pause sooner. Otherwise it is a few seconds: let the queue go out, then redeliver.\n\n### Code written for Stripe's webhooks\n\nTwo switches per endpoint, both off unless you set them on `POST /v1/webhooks` or\n`PATCH /v1/webhooks/{webhook_id}`:\n\n- `stripe_signature_header: true`: every delivery also carries `Stripe-Signature` with the\n  same value as `ZeroPoint-Signature`, so Stripe's `webhooks.constructEvent` verifies it\n  with your `whsec_` secret. `ZeroPoint-Signature` is always sent. Leave it off for a URL\n  that also receives real Stripe deliveries while you migrate.\n- `stripe_compatible_payload: true`: a checkout session whose payment is still being\n  confirmed is delivered with `payment_status: \"unpaid\"` and\n  `zeropoint_payment_status: \"processing\"`, so a handler copied from Stripe grants nothing\n  early. The signature covers the bytes sent.\n\n## 6. Rotate the secret\n\n`POST /v1/webhooks/{webhook_id}/rotate-secret` (requires an `Idempotency-Key` header, like every POST that creates something) returns a new secret. For 24 hours deliveries carry two `v1=` values, one per secret, so update your receiver at your own pace. `PATCH /v1/webhooks/{webhook_id}` with `{\"active\": false}` pauses deliveries; `DELETE /v1/webhooks/{webhook_id}` removes the endpoint.\n\n## Event types\n\nPayment events, sent to an endpoint with an empty `event_types`: `payment.processing`, `payment.succeeded`, `payment.failed`, `payment.canceled`, `payment.expired`, `payment.reversed_late`, `payment.needs_attention`, `refund.succeeded`, `refund.failed`, `terminal.online`, `terminal.offline`, `merchant.state_changed`, `webhook.test`. `GET /v1/events` lists the ledger for reconciliation.\n\nBilling events, sent only to endpoints that list them or use `[\"*\"]`: `checkout.session.completed`, `checkout.session.expired`, `invoice.paid`, `invoice.payment_succeeded`, `invoice.payment_failed`, `invoice.upcoming`, `invoice.voided`, `invoice.marked_uncollectible`, `customer.subscription.created`, `customer.subscription.updated`, `customer.subscription.deleted`, `payment_method.attached`, `payment_method.detached`, `customer.created`, `customer.updated`, `customer.deleted`. You can subscribe to each name now; a type arrives once the feature that produces it is available in your account. `billing-webhooks` covers the payloads, the Stripe mapping and the differences from Stripe.\n\n`payment.reversed_late` and `refund.succeeded` each have two producers: your own actions (a late tap on a terminal, a refund you called), and our background reconciliation, which polls the processor independently every five minutes and can raise the same events for something it found with no call of yours behind it. Both look the same on the wire; your handler does not need to know which one fired them. `refund.succeeded` carries an `origin` field (`api` or `external`) if you want to tell them apart anyway. `payment.needs_attention` is reconciliation-only: a discrepancy it found but would not act on alone. The reconciliation guide covers all of this in full.\n\n`refund.failed` is not always final. Read `data.object.failure_code`: with `processor_unverified` the refund's outcome at the processor is unknown, not refused, and the same refund id can later produce `refund.succeeded` or a second `refund.failed` with a definite code. Do not refund by other means on a `processor_unverified` event; retry the same request with the same `Idempotency-Key` or contact support. Every other refund `failure_code` (`processor_rejected`, `not_settled`, `processor_not_connected`, `operator_confirmed_not_processed`) is final. The refunds-and-voids guide has the table.","updated":1795275945}