Skip to content

Docs

Webhooks

Add an https endpoint in the dashboard. You get a whsec_… secret once.

Events

invoice.paid
data.object is the invoice, with payment.
invoice.underpaid
The invoice, with the short payment.
invoice.expired
The invoice.
pay_intent.paid
Any exact widget or invoice payment.
webhook.test
Sent from the dashboard.
http
POST /webhooks/stabletally HTTP/1.1
Content-Type: application/json
User-Agent: Stabletally-Webhooks/1.0
Stabletally-Signature: t=1795417601,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
Stabletally-Event-Id: evt_3n8w5q0zr2k7c1m9x4tb
Stabletally-Event-Type: invoice.paid

{"id":"evt_3n8w5q0zr2k7c1m9x4tb","object":"event","type":"invoice.paid","created":1795417601,"livemode":true,"data":{"object":{"id":"inv_7kq3m9x2abcd4efg","object":"invoice","status":"paid", "...": "..."}}}

Verify the signature

Stabletally-Signature: t=<unix>,v1=<hex>

v1 = HMAC-SHA256 of t + "." + body, keyed with your full whsec_… secret. Use the raw body, compare in constant time, reject timestamps older than 5 minutes.

verify.js
import crypto from 'node:crypto';

/**
 * Verifies a Stabletally webhook. rawBody must be the exact bytes we sent (before JSON.parse).
 * Header: Stabletally-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, `${t}.${rawBody}`)>
 */
export function verifyStabletallySignature(rawBody, header, secret, toleranceSec = 300) {
  if (!header) return false;
  let t = NaN;
  const signatures = [];
  for (const part of header.split(',')) {
    const [key, value] = part.split('=');
    if (key === 't') t = Number(value);
    if (key === 'v1' && /^[0-9a-f]{64}$/.test(value)) signatures.push(value);
  }
  if (!Number.isFinite(t) || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - t) > toleranceSec) return false; // replay protection

  const expected = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  return signatures.some((s) => crypto.timingSafeEqual(Buffer.from(s, 'hex'), expected));
}

Express

server.js
import express from 'express';

const app = express();

// Raw body for this route only: the signature covers the exact bytes.
app.post('/webhooks/stabletally', express.raw({ type: 'application/json' }), (req, res) => {
  const raw = req.body.toString('utf8');
  const ok = verifyStabletallySignature(raw, req.get('Stabletally-Signature'), process.env.STABLETALLY_WEBHOOK_SECRET);
  if (!ok) return res.status(400).send('bad signature');

  const event = JSON.parse(raw);
  // Events can arrive more than once: dedupe on event.id.
  if (event.type === 'invoice.paid') {
    const invoice = event.data.object;
    // fulfil(invoice.metadata.orderId, invoice.payment.txHash)
  }
  res.sendStatus(200); // any 2xx within 10 s = delivered
});

Next.js

route.ts
// app/api/webhooks/stabletally/route.ts (Next.js App Router)
export async function POST(req: Request) {
  const raw = await req.text();
  if (!verifyStabletallySignature(raw, req.headers.get('stabletally-signature'), process.env.STABLETALLY_WEBHOOK_SECRET!)) {
    return new Response('bad signature', { status: 400 });
  }
  const event = JSON.parse(raw);
  // handle event.type …
  return new Response('ok');
}

Delivery and retries

A 2xx within 10 s counts as delivered. Otherwise up to 8 attempts: 1 min, 5 min, 15 min, 1 h, 3 h, 6 h, 12 h (~22 h). Each retry is re-signed with your current secret.

Events may repeat or arrive out of order: dedupe on id and treat GET /v1/invoices/:id as the source of truth.