> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gochameleon.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify payment webhooks

> Authenticate events before updating your orders.

Configure an active webhook endpoint in your organization's dashboard and save its signing secret on your server. Use a publicly reachable HTTPS URL; private and loopback destinations are blocked.

## Events and headers

The current payment events are `payment.confirmed`, `payment.underpaid`, and `payment.failed`.

| Header | Meaning |
| - | - |
| `GoChameleon-Event` | Event type |
| `GoChameleon-Delivery-Id` | Delivery identifier |
| `GoChameleon-Signature` | `t=<unix_timestamp>,v1=<hex_hmac_sha256>` |

The JSON body contains `id`, `type`, `created`, `livemode`, and `data`. Payment data includes `intent_id`, `status`, `asset`, `chain`, `amount`, `amount_listed`, `credited_amount`, `reference`, `metadata`, and transaction details.

## Verify the raw bytes

The signature covers the timestamp, a period, and the **exact raw HTTP body**. Do not parse and re-serialize JSON before verification. Use the endpoint's signing secret, not your API key.

```python theme={null}
import hashlib
import hmac
import time


def verify_webhook(secret: str, signature: str, raw_body: bytes) -> bool:
    if not secret or not signature:
        return False
    parts = {}
    for part in signature.split(","):
        key, _, value = part.partition("=")
        parts[key.strip()] = value.strip()
    try:
        timestamp = int(parts["t"])
    except (KeyError, ValueError):
        return False
    if abs(time.time() - timestamp) > 300:
        return False
    signed = f"{timestamp}.".encode() + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))
```

For Django, pass `request.body` and `request.headers.get("GoChameleon-Signature", "")`. Reject invalid signatures before processing. Keep your server clock synchronized.

## Process reliably

1. Verify the signature, then parse JSON.
2. Check `livemode` matches the integration environment.
3. Match `data.intent_id` to a payment stored on your order. Verify the expected asset, amount, and confirmed status before fulfilling.
4. Persist the event and order update atomically, or durably enqueue the event, before returning a successful 2xx response.
5. Deduplicate retries using the event `id` or delivery ID. Also enforce once-only fulfillment per payment/order: manual replays and separate endpoints can produce new event IDs for the same payment.

Failed deliveries are retried. Your handler must tolerate duplicate events. Use the authenticated Retrieve a payment endpoint to reconcile any uncertain result.

## Node.js / Express verification

```javascript theme={null}
const crypto = require('node:crypto');

function verifySignature(rawBody, signatureHeader, secret) {
  if (!Buffer.isBuffer(rawBody) || typeof signatureHeader !== 'string' ||
      typeof secret !== 'string' || !secret) return false;

  const parts = signatureHeader.split(',').map(part => part.trim());
  const timestamps = parts.filter(part => part.startsWith('t='));
  if (timestamps.length !== 1) return false;
  const timestamp = timestamps[0].slice(2);
  if (!/^\d+$/.test(timestamp)) return false;

  const seconds = Number(timestamp);
  const now = Math.floor(Date.now() / 1000);
  // Reject stale events and timestamps too far in the future.
  if (!Number.isSafeInteger(seconds) || Math.abs(now - seconds) > 300) {
    return false;
  }

  const expected = crypto.createHmac('sha256', secret)
    .update(timestamp + '.')
    .update(rawBody)
    .digest();

  return parts.filter(part => part.startsWith('v1=')).some(part => {
    const signature = part.slice(3);
    if (!/^[a-fA-F0-9]{64}$/.test(signature)) return false;
    return crypto.timingSafeEqual(expected, Buffer.from(signature, 'hex'));
  });
}
```

In Express, register your webhook route with `express.raw({ type: "application/json" })` **before** any JSON body parser. Pass the resulting Buffer to `verifySignature`, then parse JSON only after verification succeeds.

## Replay a missed event

Inspect delivery history in the dashboard Webhooks page. The **Replay a webhook** API reference queues a fresh delivery to every active endpoint for a `confirmed`, `underpaid`, or `failed` payment. Pending and expired payments are not replayable.

```bash theme={null}
curl --fail-with-body -X POST \
  "$GOCHAMELEON_API_URL/api/v1/payments/manage/intents/PAYMENT_ID/replay-webhook/" \
  -H "Authorization: Bearer $GOCHAMELEON_SECRET_KEY"
```

Set the environment variables as shown in the [quickstart](https://docs.gochameleon.xyz/quickstart.md) and replace `PAYMENT_ID`. A successful replay returns HTTP 202 with `event`, `queued`, and `delivery_ids`. It does not perform a new payment.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.