Receiving webhooks

Cassia POSTs to your registered endpoint whenever an invoice changes state.

Event types

invoice.paid
tx detected, not yet finalized.
invoice.confirmed
block-finalized. Money-good.
invoice.underpaid
tx detected, amount < expected.
invoice.expired
TTL elapsed without matching tx.
webhook.ping
synthetic, only from test endpoint.

Timing

invoice.paid typically arrives 1–10 seconds after the customer broadcasts. invoice.confirmed arrives 10–60 seconds later (depends on chain finality — see Chains & tokens for per-chain numbers). invoice.expired fires shortly after the 60-minute TTL elapses if no matching transaction was seen.

Payload

JSON
{
  "event": "invoice.paid",
  "invoice_id": "19dac332-1bd7-7c7d-bdce-fb0bebcfa772",
  "amount": "10",
  "received": "10",
  "chain": "eip155:56",
  "token": "USDT",
  "tx_hash": "0x1234..."
}

Numeric amounts are strings in webhook bodies — decimal strings such as "10" or "49.99", not zero-padded (test events are the exception and send "100.00"). Parse them as decimals and round to 6 decimal places before comparing. REST responses are the other way round: GET /api/invoices/:id returns amount and received as JSON numbers. Normalise before comparing the two. The signing timestamp lives in the X-Cassia-Timestamp header, not in the body.

Eventamountreceivedtx_hash
invoice.paidSupportedSupportedSupported
invoice.underpaidSupportedSupportedNot supported
invoice.confirmedNot supportedNot supportedNot supported
invoice.expiredNot supportedNot supportedNot supported

Confirmed deliberately doesn’t re-send the transaction details — by the time it fires, you’ve already seen the same tx_hash on invoice.paid. If you need it later, fetch GET /api/invoices/{id}.

Test events (sent by POST /api/webhooks/:id/test) carry an extra timestamp and metadata: { test: true } in the body, and use a friendly chain: 'ethereum' string rather than the CAIP-2 gid (eip155:1). Don’t strict-parse the chain field on test events.

Signature verification

Every request includes:

X-Cassia-Signature: sha256=<hex>
HMAC-SHA256 of {timestamp}.{raw_body} with your signing_secret.
X-Cassia-Timestamp: <unix_seconds>
when Cassia signed.

Verify before trusting the payload. Reject if verification fails OR timestamp is >5 minutes old (replay protection).

import crypto from 'node:crypto';

function verify(rawBody, timestamp, signatureHeader, secret) {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex');
  const received = signatureHeader.replace(/^sha256=/, '');
  return crypto.timingSafeEqual(
    Buffer.from(expected),
    Buffer.from(received),
  );
}

When to grant access

IMPORTANT: when to grant access.

Webhooks are delivered at-least-once — your handler must be idempotent. Always grant on invoice.confirmed (final), not on invoice.paid (which can revert). Always check received === amount for underpaid events.

You usually see two events for the same payment: invoice.paid (tx detected) then invoice.confirmed (finalized).

  • Grant on invoice.paid for low-value, reversible-effort flows — TG bot subscriptions, digital goods under ~$50, SaaS trials. Faster UX; reorg risk is real but small and loss is capped.
  • Grant on invoice.confirmed for high-value or irreversible fulfillment — physical goods, payments above ~$200, account top-ups unlocking large spend. Extra seconds/minutes are cheap insurance against a reorg that can’t be undone.
  • Never grant on invoice.underpaid without first checking received.

Retry policy

Failed deliveries (non-2xx or timeout >10s) are retried at [0, 30s, 2min, 10min, 1hr] — five attempts over ~75 min. After that, terminal; visible under GET /api/webhook-deliveries?status=failed. Replay with POST /api/webhooks/:id/redeliver-failed.

Idempotency

Cassia sends at most one webhook per (event, invoice_id), but may redeliver that same webhook more than once. Dedupe on (event, invoice_id) at your side — X-Cassia-Timestamp is regenerated on every delivery attempt, so it never matches a retry. Don’t trust TCP success — trust your own idempotency key.

Respond fast, process later

Return 200 OK as soon as you’ve verified the signature and persisted the raw payload. Do slow work (DB writes, Telegram, business logic) asynchronously. A slow handler consumes your request budget and makes retries redundant for you.

Updated . For integration help, email [email protected]

From signup to payment setup in 7 minutes

Start accepting
payments today
on 5 blockchains.

Create accountRead documentation