> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.transxact.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.transxact.io/_mcp/server.

# Verifying webhooks

Outbound webhooks (like `checkout_session.succeeded`) are signed with
HMAC-SHA256 over `timestamp.payload`, carried in the `Transxact-Signature`
header. Verify this signature before trusting a webhook body — otherwise
anything that can reach your endpoint's URL can forge a fake payment
notification.

Add endpoints, reveal their signing secrets and send a signed `webhook.test`
event from the **Webhooks** section of your dashboard (Business accounts
only). Endpoints must be `https://`.

## Several endpoints

You can add up to five endpoints for each mode, for example a staging server
beside production, or an accounting tool that only wants paid events. Each
endpoint has its own URL, its own signing secret, the events it wants, and an
on/off switch. A Test mode endpoint only hears Test mode events and a Live
mode endpoint only hears Live mode ones; the `mode` field on the Checkout
Session in the payload says which.

An event is sent to every endpoint that wants it, each as its own delivery
with its own `id` (`evt_…`), signed with that endpoint's secret. Verify each
request with the secret of the endpoint it was sent to.

Rotating a secret replaces it at once, with no overlap. To change over
without a gap, add a second endpoint with the new secret, move your traffic
across, then delete the old one.

Verification also rejects any request where the signed `timestamp` is more
than 5 minutes old. The HMAC signature itself never expires on its own, so
without this tolerance window a captured valid webhook call would be
replayable indefinitely.

## With the Node SDK

`@transxact/node/webhooks` exports `verifyWebhookSignature`, which does all
of the below, including the 5-minute check:

```typescript
import { verifyWebhookSignature } from "@transxact/node/webhooks";

// Express: keep the raw body for this route.
app.post("/webhooks/transxact", express.raw({ type: "application/json" }), (req, res) => {
  const rawBody = req.body.toString("utf8");
  const ok = verifyWebhookSignature(
    rawBody,
    req.header("Transxact-Signature") ?? "",
    process.env.TRANSXACT_WEBHOOK_SECRET!,
  );
  if (!ok) return res.status(400).end();

  const event = JSON.parse(rawBody);
  // ...handle event.type, skipping ids you've already handled
  res.status(200).end();
});
```

## With the PHP SDK

`transxact/transxact` has the same check, with the same 5-minute window, as
`Transxact\Webhooks::verifySignature`:

```php
<?php

use Transxact\Webhooks;

$rawBody = file_get_contents('php://input');
$ok = Webhooks::verifySignature(
    $rawBody,
    $_SERVER['HTTP_TRANSXACT_SIGNATURE'] ?? '',
    (string) getenv('TRANSXACT_WEBHOOK_SECRET'),
);
if (!$ok) {
    http_response_code(400);
    exit;
}

$event = json_decode($rawBody, true);
// ...handle $event['type'], skipping ids you've already handled
http_response_code(200);
```

## Verifying manually

The `Transxact-Signature` header carries `t=<timestamp>,v1=<hmac>`, where
`timestamp` is milliseconds since epoch and `hmac` is the hex-encoded
HMAC-SHA256 of `` `${timestamp}.${rawPayload}` `` using your webhook signing
secret (from the dashboard's Webhooks section):

```typescript
import { timingSafeEqual, createHmac } from "node:crypto";

function verifyWebhookSignature(
  rawPayload: string,
  header: string,
  secret: string,
): boolean {
  const parts = Object.fromEntries(
    header.split(",").map((part) => part.split("=", 2) as [string, string]),
  );
  const { t: timestamp, v1: signature } = parts;
  if (!timestamp || !signature) return false;
  if (Math.abs(Date.now() - Number(timestamp)) > 5 * 60 * 1000) return false;

  const expected = createHmac("sha256", secret)
    .update(`${timestamp}.${rawPayload}`)
    .digest("hex");

  return (
    signature.length === expected.length &&
    timingSafeEqual(Buffer.from(signature), Buffer.from(expected))
  );
}
```

Always pass the raw request body, exactly as received — re-serializing JSON
before verifying can change byte-for-byte content and produce a signature
mismatch even for a genuine webhook.

## Receiving webhooks while you develop

Endpoints must be public `https://` URLs, so a server on `localhost` can't
receive them directly. Run a tunnel, such as
`cloudflared tunnel --url http://localhost:3000` or `ngrok http 3000`, add its
`https://` address as an endpoint, and press **Send test** to check
the whole path before you take a test payment.

## Retries and duplicate events

Every event carries an `id` (`evt_…`). Answer with any `2xx` status to
acknowledge it. Anything else, or no answer within 10 seconds, and we retry
the same event, with the same `id`, after 15 minutes, then 45 minutes, 2, 3,
6 and 12 hours — about a day in all — before giving up.

Delivery is at least once: a retry or a manual resend can reach you more than
once, so record the `id`s you've handled and skip repeats. Each retry is
signed afresh, so its `timestamp` is always current.

The **Webhooks** section of your dashboard lists recent deliveries, which
endpoint each went to, whether it got them, and has a **Resend** button for
sending one again straight away. A resend goes to that delivery's own
endpoint. If an endpoint is switched off or deleted when a retry comes, the
delivery ends as failed without a request; switch the endpoint back on and
resend it.