JamiDev

Webhooks

Signed HTTP notifications for orders, benefits, failed checkouts, subscriptions and payouts, with automatic retries.

Webhooks tell your server when something happens: an order is paid, a license key is issued, a checkout fails, a subscription renews, a payout settles. Each delivery is a signed POST with a JSON body. Verify the signature, act on the event, reply 2xx.

Register an endpoint

In Automation → Webhooks, add your URL and pick the events to receive. You get a secret for that endpoint. It's shown once; save it as JAMI_WEBHOOK_SECRET.

Endpoints belong to one organization

A sandbox organization and a production one each need their own endpoint. Events from one organization never reach another's endpoints.

Events

EventSent whendata
order.createdA payment is confirmed and the order is created.The order
order.completedThe order is final. Today it's sent right after order.created for every order.The order
benefit.grantedA benefit was granted for a paid order, one event per benefit.The grant
checkout.session.expiredA session ended without an order: the payment failed or was canceled, or 30 minutes passed. For a payment link, only when the link expires.sessionId, failure
withdrawal.paidA withdrawal reached the destination account.The withdrawal
withdrawal.failedA withdrawal was rejected or its payout failed. A failed payout can be retried and later send withdrawal.paid.The withdrawal
subscription.createdA payer approved a subscription and its first period was paid.The subscription, plus charge
subscription.renewedA renewal, or a retry of a failed one, was paid.The subscription, plus charge
subscription.payment_failedA renewal try failed. nextRetryAt is null on the last try.The subscription, plus charge and nextRetryAt
subscription.updatedA cancel was scheduled for the end of the period, or a scheduled cancel was undone.The subscription, plus change and changedBy
subscription.canceledThe subscription ended, for any reason. No more charges.The subscription

Fulfil on order.completed. Every order, benefit and session event carries data.sessionId, the same id createCheckout returned, so you can match an event to the checkout you started without storing anything else.

Subscription charges create orders too, but they don't send order.created or order.completed. Handle the subscription.* events instead, and match them on data.id (sub_…) or data.customerExternalId. Endpoints you registered before subscriptions existed don't receive these events until you tick them.

Payload

Every delivery has the same envelope:

order.completed
{
  "id": "6710c2e8b1a2f0012ab34c90",
  "type": "order.completed",
  "created": "2026-10-16T09:30:00.000Z",
  "livemode": true,
  "data": {
    "orderId": "6710c2e8b1a2f0012ab34c11",
    "sessionId": "6710c2e8b1a2f0012ab34c00",
    "productId": "6710c2e8b1a2f0012ab34c22",
    "customerId": "6710c2e8b1a2f0012ab34c33",
    "customerEmail": "buyer@example.com",
    "customerExternalId": "user_42",
    "amount": 15000,
    "currency": "ETB",
    "status": "paid",
    "metadata": { "campaign": "launch" },
    "description": null,
    "paidAt": "2026-10-16T09:29:58.000Z"
  }
}
  • id is unique per event. Use it to ignore duplicates.
  • livemode is false for sandbox organizations.
  • amount is what the buyer paid, in santim.
  • customerExternalId is the customer.externalId you passed to createCheckout, or null.
  • metadata is the product's and checkout link's metadata merged with the metadata you passed to createCheckout (yours wins on a conflict).
  • description is set for custom-amount checkouts and null for product checkouts. For custom amounts, productId is an internal id; match on sessionId or metadata instead.

Verify the signature

Each delivery has two headers:

X-JamiDev-Signature: t=1792139400,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
X-JamiDev-Event: order.completed

v1 is the hex HMAC-SHA256 of "{t}.{raw body}" with your endpoint's secret. jami.webhooks.verify checks it with a constant-time compare, rejects timestamps more than 5 minutes old, and returns the typed event. Verification needs the raw body: if your framework parses JSON first and you re-serialize it, the signature won't match.

server.ts
import express from 'express';
import { Jami, JamiSignatureError } from 'jami-sdk';

const jami = new Jami({ token: process.env.JAMI_TOKEN! });
const app = express();

app.post('/webhooks/jami', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = await jami.webhooks.verify({
      payload: req.body.toString('utf8'),
      signature: req.header('x-jamidev-signature') ?? '',
      secret: process.env.JAMI_WEBHOOK_SECRET!,
    });
  } catch (err) {
    if (err instanceof JamiSignatureError) return res.sendStatus(400);
    throw err;
  }

  if (event.type === 'order.completed') {
    await fulfil(event.data.sessionId, event.id);
  }
  res.sendStatus(200);
});
app/api/webhooks/jami/route.ts
import { Jami, JamiSignatureError } from 'jami-sdk';

const jami = new Jami({ token: process.env.JAMI_TOKEN! });

export async function POST(req: Request) {
  let event;
  try {
    event = await jami.webhooks.verify({
      payload: await req.text(),
      signature: req.headers.get('x-jamidev-signature') ?? '',
      secret: process.env.JAMI_WEBHOOK_SECRET!,
    });
  } catch (err) {
    if (err instanceof JamiSignatureError) return new Response('bad signature', { status: 400 });
    throw err;
  }

  if (event.type === 'order.completed') {
    await fulfil(event.data.sessionId, event.id);
  }
  return new Response(null, { status: 200 });
}
src/index.ts
import { Hono } from 'hono';
import { verifyWebhookSignature, JamiSignatureError } from 'jami-sdk';

const app = new Hono<{ Bindings: { JAMI_WEBHOOK_SECRET: string } }>();

app.post('/webhooks/jami', async (c) => {
  let event;
  try {
    event = await verifyWebhookSignature({
      payload: await c.req.text(),
      signature: c.req.header('x-jamidev-signature') ?? '',
      secret: c.env.JAMI_WEBHOOK_SECRET,
    });
  } catch (err) {
    if (err instanceof JamiSignatureError) return c.text('bad signature', 400);
    throw err;
  }

  if (event.type === 'order.completed') {
    await fulfil(event.data.sessionId, event.id);
  }
  return c.body(null, 200);
});

verifyWebhookSignature is the standalone function behind jami.webhooks.verify. It needs no API token, and runs on Cloudflare Workers and other edge runtimes.

Without the SDK

Any language works. In Node:

import crypto from 'node:crypto';

function verifyJamiSignature(rawBody: string, header: string, secret: string): boolean {
  const t = /(?:^|,)\s*t=(\d+)/.exec(header)?.[1];
  const v1 = /(?:^|,)\s*v1=([a-f0-9]{64})/.exec(header)?.[1];
  if (!t || !v1) return false;
  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false; // replay guard

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

Delivery and retries

  • Reply with any 2xx within 10 seconds. Anything else, including a timeout, is a failure.
  • Failures are retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours, up to 5 attempts in total.
  • The Webhooks page lists every delivery with its response code and a Resend button.
  • Retries and resends reuse the event id, so the same event can arrive more than once. Record the ids you've processed and skip repeats.

Do slow work (emails, file generation) after replying, in a queue or background job.

Test it locally

  • Use a tunnel such as cloudflared tunnel --url http://localhost:3000 and register the public URL in your sandbox organization, then run a sandbox checkout.
  • Or have the MCP server sign a test event and POST it to your local route: ask your agent to "send a test order.completed to http://localhost:3000/api/webhooks/jami".

Checklist

  • The handler verifies the raw body and returns 400 on JamiSignatureError.
  • Processed event ids are stored; repeats are acknowledged and skipped.
  • Orders are fulfilled on order.completed, matched by data.sessionId.
  • If you sell subscriptions, access follows subscription.* events, not order.*.
  • checkout.session.expired shows the buyer a message based on failure.code.
  • The handler replies within 10 seconds.
  • Production has its own endpoint and secret.

On this page