# Settlement event

A payment was credited to your wallet

Outbound POST to the HTTPS callback registered by the merchant.

One `POST` to your webhook URL per settled payment, with `User-Agent: Cadmos-Webhooks/1`. The body is one settlement, as in the list.

Verify the signature against the exact bytes received, and refuse a timestamp more than 300 seconds from your clock:

```js
const { createHash } = require('crypto');
const { verifyMessage } = require('ethers');

// rawBody: the exact bytes received. signers: the addresses from GET /v1/external-auth/webhook-signers.
function verifyCadmosWebhook(rawBody, headers, signers) {
  const timestamp = headers['x-cadmos-timestamp'];
  if (!/^\d+$/.test(timestamp) || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  try {
    const digest = createHash('sha256').update(rawBody).digest('hex');
    const message = `${timestamp}.${JSON.parse(rawBody).id}.${digest}`;
    return signers.includes(verifyMessage(message, headers['x-cadmos-signature']));
  } catch {
    return false;
  }
}
```

Delivery is at least once: answer 2xx only after storing the payment, and drop an `id` you already have. Any other answer, a redirect (never followed) or no answer within 10 seconds is retried: 1 minute later, doubling up to 1 hour, until 3 days after the settlement. The settlements list has everything a webhook missed.

## Parameters

- `X-Cadmos-Timestamp` (string, header, required, pattern ^\d+$). Unix seconds when this attempt was sent.
- `X-Cadmos-Signature` (string, header, required, pattern ^0x[0-9a-fA-F]{130}$). EIP-191 signature over `<X-Cadmos-Timestamp>.<id>.<sha256 hex of the body>`.

## Request body

`application/json`

[Settlement](https://cadmospay.com/developers/schemas/settlement.md)

- `id` (string, required, pattern ^0x[0-9a-fA-F]{64}$). The payment's on-chain transfer id. Unique: drop one you already have.
- `linkUuid` (string, required, format uuid). Ignore a link you do not know: it was made in the app.
- `externalReference` (string or null, required). Your reference, `null` for a link made in the app.
- `asset` (string, required, one of USDC, USDT, CUSD). What arrived: `CUSD` for a cash payment.
- `gross` (string, required, pattern ^\d+$). An integer string of 6-decimal units: `"100000000"` is 100.000000.
- `gatewayFee` (string or null, required, pattern ^\d+$). An integer string of 6-decimal units: `"100000000"` is 100.000000.
- `appliedRateBps` (integer or null, required). 
- `netCusd` (string, required, pattern ^\d+$). What your wallet was credited.
- `settledAt` (string or null, required, format date-time). 
- `settlement` (object, required). 
- `settlement.chain` (string, required, one of arbitrum). 
- `settlement.txHash` (string or null, required). The transaction that credited your wallet.
- `whishCashIn` (string or null, required). The Whish cash-in behind a cash payment; `null` for crypto.
- `destination` (string, required, one of cadmos_wallet). Always your Cadmos wallet.

```json
{
  "id": "0x5f2c0c3d2b1a09f8e7d6c5b4a39281706f5e4d3c2b1a09f8e7d6c5b4a3928170",
  "linkUuid": "0b6f5a8e-1c2d-4e3f-9a8b-7c6d5e4f3a2b",
  "externalReference": "order-42",
  "asset": "USDT",
  "gross": "100000000",
  "gatewayFee": "500000",
  "appliedRateBps": 50,
  "netCusd": "99500000",
  "settledAt": "2026-11-17T10:00:00.000Z",
  "settlement": {
    "chain": "arbitrum",
    "txHash": "0xdfd1a5041e8abc7c9b2f6a0e1d3c5b7a9f8e6d4c2b0a1f3e5d7c9b8a6f4e2d0c"
  },
  "whishCashIn": null,
  "destination": "cadmos_wallet"
}
```

## Responses

### 2XX

Stored. Any other answer is retried.
