Skip to content
Shared

Verify and test webhooks

Check the signature over the raw body, the five-minute window, duplicates and out-of-order delivery, then test your receiver with Send test event, Resend and the delivery detail.

A webhook is how you learn an invoice is paid, so your receiver is the most important code in the integration. It has five jobs:

  1. Verify the signature over the raw body.
  2. Reject stale deliveries (older than five minutes).
  3. Survive duplicates: the same event can arrive twice.
  4. Survive disorder: events can arrive out of order.
  5. Answer 2xx fast, or you will be sent it again.

Then test all five without paying anything: Send test event, Resend, and the delivery detail.

Every delivery carries X-Intents-Signature: t=<unix seconds>,v1=<hex>, where v1 is HMAC-SHA256(secret, "<t>.<raw body>") with your endpoint’s whsec_… secret. Use the helper:

import { verifyWebhook, WebhookSignatureError } from "@intents-fi/sdk";
const event = await verifyWebhook(rawBody, headers, process.env.INTENTS_WEBHOOK_SECRET);

It throws WebhookSignatureError (answer 400) and otherwise returns the typed event. The signature covers the exact bytes we sent, so read the body before anything parses it:

Framework Raw body
Next.js (App Router) await request.text()
Express express.raw({ type: "application/json" }) on the route, before express.json(); req.body is a Buffer
Hono await c.req.text()
PHP file_get_contents('php://input') (intents-php)

A body parsed and re-serialised has different bytes and never verifies. reason tells you which check failed: raw_body_required and signature_mismatch are the usual ones while you build.

t is signed too, so a captured delivery cannot be replayed under a new timestamp. Anything more than five minutes from your clock is rejected with timestamp_out_of_tolerance. If every delivery fails that way, your server’s clock is wrong; fix NTP rather than widening the window.

The same event can reach you more than once: a retry after your endpoint timed out, or a Resend from the dashboard, which re-sends the same event id on purpose. Both are genuine, so verifyWebhook accepts both. Your fulfilment has to make the second one harmless:

async function markPaid(orderId: string) {
const order = await db.orders.get(orderId);
if (order.status === "paid") return; // already shipped: do nothing
await db.orders.update(orderId, { status: "paid" });
await ship(order);
}

Or record event.id and skip one you have seen.

invoice.paid can land before invoice.processing, because a retry can arrive after a later event. Treat event.data.status as the truth and event.type as the reason you were woken, and never move an order backwards.

Any 2xx is a success. Anything else, or no answer in five seconds, is retried: 8 attempts over about 23 hours. Do slow work after you answer, or queue it. Answer 2xx for event types you don’t handle, too.

Webhooks in the dashboard › your endpoint › pick an event type › Send test event. We deliver it now, signed with the endpoint’s real secret, and show you the body we sent and what your endpoint answered.

  • On a test-mode endpoint it is a sample invoice in the state you picked, marked sample: true, with evt_test_ / inv_test_ ids and a sample_… reference. Your receiver should verify it, answer 2xx and ship nothing: isTestEvent(event) is true.
  • On a live-mode endpoint it is the webhook.test ping, which carries no invoice.

From code, with a test key: POST /v0/webhooks/{id}/test with { "type": "invoice.paid" }, or sdk.webhooks.test(id, { type }). A live key gets TEST_MODE_ONLY.

Every row in the delivery log has Resend: the same event, to the same endpoint, now, with the same event id. It is a real duplicate, so use it after a test payment to check that your order ships once.

Click an event in the log to see, for its latest attempt:

  • the request body exactly as we signed and sent it,
  • the response status and body your endpoint returned (the first 2 KB),
  • how long it took, when, and the error if there was no answer.

That is usually enough to see why a delivery failed: a 400 with signature_mismatch from your own handler means a parsed body; a timeout means slow work before the answer.

  • Signature verified over the raw body; 400 when it fails
  • Sample events acknowledged and ignored
  • A resent invoice.paid ships nothing twice
  • Status read from event.data.status
  • 2xx within five seconds, for every type

See Webhooks for the event types and payloads, and the examples for receivers that do all of the above.