BetterRewardsDocs
Open app
Browse guides

Webhooks

Get a signed payout.confirmed request when a partner is paid, to update your own systems.

2 min read · For companies

Optional. When you mark a payout paid, betterrewards can tell your own systems: show "paid" in your product, or keep your books in sync. Add an endpoint under Integrations → Outbound webhooks (owner only).

Integrations → Outbound webhooks: the Add endpoint form, an endpoint with Send test and Show signing secret, and recent deliveries

1. Add an endpoint

  1. Under Add endpoint, enter an https URL on your system and an optional description, and click Create.
  2. Click Show signing secret and store it in your system's environment, for example BETTERREWARDS_WEBHOOK_SECRET.
  3. Click Send test. A payout.confirmed delivery marked test: true arrives within seconds, and Recent deliveries shows your endpoint's response.

2. The request

POST to your endpoint
Content-Type: application/json
BetterRewards-Signature: t=1795270000,v1=5f0c…
Idempotency-Key: evt_…

{
  "id": "evt_…",
  "type": "payout.confirmed",
  "created": 1795270000,
  "data": {
    "payout_id": "pay_…",
    "batch_id": "pob_…",
    "partner_id": "ptr_…",
    "partner_external_id": "acct-42",
    "currency": "usd",
    "amount": 1500,
    "reference": "bank-transfer-0001",
    "paid_at": 1795270000
  }
}

amount is in minor units: 1500 is 15.00 USD. partner_external_id is the id you set on the partner, to match them in your system.

3. Verify the signature

The signature is an HMAC-SHA256 of "<t>.<raw body>" with the signing secret, in hex. Check it against the exact bytes you received, before parsing the JSON, and reject timestamps more than 5 minutes away.

verify.ts (Node 20+, Bun, Deno, Workers)
export async function verifyBetterRewards(rawBody: string, header: string, secret: string) {
  const parts = Object.fromEntries(header.split(",").map((part) => part.split("=", 2)));
  const timestamp = Number(parts.t);
  if (!parts.v1 || Math.abs(Date.now() / 1000 - timestamp) > 300) return false;

  const key = await crypto.subtle.importKey(
    "raw",
    new TextEncoder().encode(secret),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["sign"],
  );
  const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${timestamp}.${rawBody}`));
  const expected = [...new Uint8Array(mac)].map((b) => b.toString(16).padStart(2, "0")).join("");
  if (expected.length !== parts.v1.length) return false;
  let diff = 0;
  for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ parts.v1.charCodeAt(i);
  return diff === 0;
}
app/api/betterrewards/route.ts (Next.js)
export async function POST(request: Request) {
  const body = await request.text();
  const ok = await verifyBetterRewards(
    body,
    request.headers.get("BetterRewards-Signature") ?? "",
    process.env.BETTERREWARDS_WEBHOOK_SECRET!,
  );
  if (!ok) return new Response("bad signature", { status: 400 });
  const event = JSON.parse(body);
  // Deduplicate on request.headers.get("Idempotency-Key") or event.data.payout_id.
  return new Response(null, { status: 204 });
}

Delivery and retries

  • Answer with any 2xx to acknowledge. The payout is already paid when the event is sent; your answer does not change it.
  • Anything else, or no answer within 10 seconds, is retried: after 30 seconds, then doubling up to 6 hours, 24 attempts in all (about 3.5 days).
  • Deliveries can repeat. Deduplicate on Idempotency-Key or payout_id.
  • The signing secret is derived from AUTH_SECRET: rotating AUTH_SECRET rotates it.