Skip to Content

Webhooks

Get notified when payments, refunds and subscriptions change, and verify the signature.

When something happens, such as a payment being paid, we send a POST with JSON to your webhook URL. Treat a webhook as a trigger, and always verify its signature.

Setting the webhook URL

Each app has one webhook URL per mode (test and live).

  1. In the dashboard, pick test or live mode.
  2. Open Developer, pick the app, then the Webhook tab.
  3. Enter the URL and click Simpan URL.

URL rules:

  • It must be https. http is allowed only in test mode.
  • It must point to a public address. Private, loopback and internal network addresses are refused when saved and when we connect.

Once saved, the dashboard shows the signing secret (whsec_...) once. Keep it on your server. Owners and admins can show it again with Tampilkan secret (this is logged).

  • Saving a new URL makes a new secret. Events still waiting go to the new URL, signed with the new secret.
  • Every time a URL is saved, we send a webhook.test event to it.
  • GET /v1/webhooks shows the active URL for your API key's app and mode (without the secret). See Get the webhook endpoint.

Events

EventWhendata
payment.paidA payment is paid. Can come after payment.expired when paid late (paid_late: true).The payment
payment.expiredA payment expired unpaid.The payment
refund.succeededA refund succeeded.The refund
refund.failedA refund failed.The refund
invoice.createdA recurring invoice was issued. See Recurring billing.A payment with subscription
subscription.pausedA subscription was paused.The subscription
subscription.resumedA subscription was resumed.The subscription
subscription.cancelledA subscription was cancelled.The subscription
subscription.completedA subscription's last invoice was issued.The subscription
webhook.testA URL was saved, or you asked for a test event. Answer 2xx and ignore it.A short message

data is the object as it was when the event happened. For the current state, read it through the API, for example Get a payment.

Ignore event types you don't know yet. We may add new ones.

What a webhook looks like

Request
POST /hooks/piti HTTP/1.1
Content-Type: application/json
User-Agent: LayerbeatPay-Webhooks/1
LayerbeatPay-Signature: t=1764472542,v1=5f2b6c...e91a
Body (formatted, shortened)
{
  "id": "evt_xxxxxxxx",
  "object": "event",
  "type": "payment.paid",
  "mode": "test",
  "created_at": "2026-11-30T03:15:42Z",
  "data": {
    "id": "pay_xxxxxxxx",
    "object": "payment",
    "app_id": "app_xxxxxxxx",
    "mode": "test",
    "reference": "INV-1042",
    "method": "qris",
    "status": "paid",
    "currency": "IDR",
    "amount": 150000,
    "fee": 1050,
    "total": 150000,
    "net": 148950,
    "fee_payer": "merchant",
    "paid_late": false,
    "paid_at": "2026-11-30T03:15:40Z",
    "source": "api",
    "subscription": null
  }
}

On the wire the body is compact JSON with no spaces. The full payment object is in Create a payment.

Verifying the signature

The LayerbeatPay-Signature header looks like t=<unix seconds>,v1=<hex>. v1 is an HMAC-SHA256 keyed with your webhook secret, over the text t + "." + body.

  1. Read t and v1 from the header.
  2. Refuse it if t is more than 5 minutes away from your server's clock.
  3. Compute HMAC-SHA256(secret, t + "." + raw body) as lowercase hex.
  4. Compare it with v1 using a constant-time comparison.

Use the raw body exactly as received. Don't parse and re-serialise the JSON: the result can differ and the signature won't match. Each delivery attempt is signed again with a new t, so retries still pass the 5-minute check.

server.js (Express)
import crypto from 'node:crypto';
import express from 'express';

const secret = process.env.WEBHOOK_SECRET; // whsec_...
const app = express();

// express.raw: req.body is a Buffer with the raw body
app.post('/hooks/piti', express.raw({ type: 'application/json' }), (req, res) => {
  const parts = {};
  for (const p of (req.get('LayerbeatPay-Signature') || '').split(',')) {
    const [k, v] = p.trim().split('=', 2);
    parts[k] = v;
  }
  const t = Number(parts.t);
  if (!Number.isInteger(t) || !parts.v1 || Math.abs(Date.now() / 1000 - t) > 300) {
    return res.status(400).send('bad signature');
  }
  const expected = crypto.createHmac('sha256', secret)
    .update(parts.t + '.')
    .update(req.body)
    .digest('hex');
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
    return res.status(400).send('bad signature');
  }

  const event = JSON.parse(req.body.toString('utf8'));
  // Skip if event.id was already handled, then act on event.type.
  res.sendStatus(200);
});

app.listen(3000);

Answering

  • Answer with a 2xx status within 10 seconds. Anything else counts as failed and is retried.
  • We don't follow redirects. A 3xx answer counts as failed.
  • Store the event and answer at once. Do slow work in the background.

Retries

A failed delivery is tried again after 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours, 12 hours and 24 hours, each counted from the previous attempt. After 9 attempts the delivery is marked failed. You can send it again through the API or the dashboard.

While an app is switched off, its webhooks are held, not failed, and sent in order once the app is on again.

Order and duplicates

  • Events are sent in the order they happened. If one delivery fails and waits for a retry, later events are still sent, so an older event can arrive after a newer one.
  • Delivery is at least once. The same event can arrive more than once, for example when your answer is lost on the way. Record the event ids you have handled and skip duplicates.
  • A paid payment never goes back to unpaid. When in doubt about order, read the current state through the API.

Events in the API

GET /v1/eventsList events, newest first, with their delivery. Filter by type, delivery_status (pending, delivered, failed) and payment_id (that payment's events and its refunds').
GET /v1/events/{id}One event.
POST /v1/events/{id}/redeliverSend it again to the URL active now, with a fresh retry schedule. An event still waiting is left as it is.
POST /v1/webhooks/testSend a webhook.test event now, signed like every event.

Each event has delivery: status, attempts, last_status_code, last_error, delivered_at and next_attempt_at. delivery is null when nothing was sent to the active URL.

An API key sees only its app's events. In the dashboard, the Webhook menu shows the delivery log for all apps, with a button to resend.

Possible error codes:

  • 404 no_webhook: GET /v1/webhooks, but no URL is set for this app and mode.
  • 409 no_webhook: a test event or a resend, but no URL is set.
  • 409 compat_active: a test event while a Xendit or Duitku compatibility mode is on.

See Errors.

Test event

Click Kirim event uji on the app's Webhook tab, or call POST /v1/webhooks/test. Its data:

webhook.test data
{
  "object": "webhook_test",
  "endpoint_id": "we_xxxxxxxx",
  "message": "Tes webhook dari Layerbeat Pay. Balas 2xx dan abaikan isinya."
}

Compatibility modes

When the Xendit or Duitku compatibility mode is on for an app and mode, it replaces that app's webhook. We send Xendit- or Duitku-style callbacks instead of these webhooks, and there is no test event. Turning the compatibility mode off doesn't bring the webhook back: save the webhook URL again on the Webhook tab.