> For the complete documentation index, see [llms.txt](https://kollect.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kollect.gitbook.io/docs/webhook-overview/payload-and-verification.md). Agents can also search and read this documentation through its [MCP server](https://kollect.gitbook.io/docs/~gitbook/mcp).

# Payload and verification

This page documents the **JSON body** Kollect POSTs to your `webhookUrl` and how to verify the signature headers.

## HTTP request

| Property          | Value                                                                                                                                                                                         |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Method            | `POST`                                                                                                                                                                                        |
| `Content-Type`    | `application/json`                                                                                                                                                                            |
| Signature headers | `x-kollect-signature` (raw hex) **and** `x-kollect-signature-v2` (`sha256=<hex>` prefixed) — both sent on every request, same underlying signature, two formats. Verify whichever you prefer. |

## Payload fields

| Field              | Type           | Description                                                                                                            |
| ------------------ | -------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `eventId`          | string         | UUID, unique per logical event and **stable across delivery retries**. Use this to dedupe — delivery is at-least-once. |
| `paymentId`        | string         | UUID of the Kollect payment (`id`).                                                                                    |
| `paymentReference` | string         | Smart Contract payment reference.                                                                                      |
| `invoiceId`        | string         | Invoice document id (string form of Mongo `_id`).                                                                      |
| `invoiceNumber`    | string         | Human-readable invoice number.                                                                                         |
| `status`           | string         | Payment status after update (`success` or `failed`).                                                                   |
| `event`            | string         | Upstream event: `payment.confirmed` or `payment.failed`.                                                               |
| `transactionHash`  | string \| null | On-chain transaction hash when applicable; `null` on some failure paths.                                               |
| `amount`           | string         | Amount stored on the payment record (string).                                                                          |
| `currency`         | string         | Payment currency (e.g. `USDC-mainnet`).                                                                                |
| `interface`        | string         | Integration surface — always `kollect-server` for this webhook, since delivery is gated on it.                         |
| `timestamp`        | string         | ISO 8601 timestamp when the payload was constructed.                                                                   |

## Example payload

```json
{
  "eventId": "9c3b6f2a-1d4e-4b8a-9f0a-2e6d7c1a5b3f",
  "paymentId": "550e8400-e29b-41d4-a716-446655440000",
  "paymentReference": "0xabc...",
  "invoiceId": "64a1b2c3d4e5f6789012345",
  "invoiceNumber": "INV-1001",
  "status": "success",
  "event": "payment.confirmed",
  "transactionHash": "0xdef...",
  "amount": "51.24",
  "currency": "USDC-mainnet",
  "interface": "kollect-server",
  "timestamp": "2025-03-23T12:00:00.000Z"
}
```

## Signature algorithm

Kollect computes:

```
signature = HMAC_SHA256_hex( signingSecret, JSON.stringify(payload) )

x-kollect-signature:    signature
x-kollect-signature-v2: `sha256=${signature}`
```

The HMAC key is your **`signingSecret`**. The message is the **JSON string** of the payload object as produced by Kollect's serializer for that request. Both headers carry the same underlying signature — `x-kollect-signature-v2` exists so the `sha256=` prefix is explicit and is the format the platform is standardizing on; `x-kollect-signature` (unprefixed) is kept for backward compatibility.

### Verification strategies

1. **Preferred:** Read the **raw request body bytes** as received on the socket, compute HMAC over those bytes, and compare to the signature header. This avoids JSON normalization differences.
2. **Alternative:** Parse JSON, then `JSON.stringify` with a serializer that matches Kollect's output. This is fragile if key order or spacing differs; prefer raw bytes.

### Comparison

Use **constant-time** comparison (e.g. `crypto.timingSafeEqual` on equal-length buffers in Node.js) to reduce timing side channels.

## Node.js example

```javascript
const crypto = require("crypto");

function verifyKollectWebhook(rawBodyBuffer, signatureHex, signingSecret) {
  const expected = crypto
    .createHmac("sha256", signingSecret)
    .update(rawBodyBuffer)
    .digest("hex");
  const a = Buffer.from(expected, "hex");
  const b = Buffer.from(String(signatureHex || ""), "hex");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

// If verifying against x-kollect-signature-v2, strip the "sha256=" prefix first:
function verifyKollectWebhookV2(rawBodyBuffer, headerValue, signingSecret) {
  const hex = String(headerValue || "").replace(/^sha256=/, "");
  return verifyKollectWebhook(rawBodyBuffer, hex, signingSecret);
}
```

### Idempotent processing <a href="#idempotent-processing" id="idempotent-processing"></a>

Delivery is **at-least-once** — retries on timeout/non-2xx can redeliver the same event. Your handler should **upsert** order state keyed by **`eventId`** (preferred) or `paymentId`, and ignore duplicate notifications if already processed.
