Webhooks

Get notified of payments, refunds and payouts as they happen.

Add an HTTPS endpoint in the dashboard (Developers → Webhooks) or with POST /v1/webhook_endpoints. Each endpoint has its own signing secret, can subscribe to all event types or a chosen few, and can listen to test mode, live mode or both.

The request

For every matching event, Klink Pay sends a POST with a JSON body (the event) and a Klink-Signature header:

POST https://your-site/webhooks/klink-pay
Content-Type: application/json
Klink-Signature: t=1795773672,v1=5f2c8e…

{
  "id": "evt_2Bc4De6Fg8Hi0Jk2Lm4No6",
  "object": "event",
  "type": "payment.succeeded",
  "livemode": false,
  "created_at": "2026-11-27T10:01:12Z",
  "data": {
    "object": {
      "id": "pay_4Nq7xY2mKc8vTz1aB3dE9f",
      "object": "payment",
      "livemode": false,
      "status": "succeeded",
      "amount": 15200,
      "currency": "MMK",
      "method": "mmqr",
      "reference": "order-1001",
      "bank_reference": "KP7GQ2M9XW4T",
      "description": "Table 4",
      "checkout_url": "https://checkout.klinkpay.net/c/pay_4Nq7xY2mKc8vTz1aB3dE9f",
      "qr_payload": "00020101021226…6304A1B2",
      "redirect_url": null,
      "customer_phone": null,
      "return_url": "https://shop.example.com/orders/1001",
      "metadata": {
        "order_id": "1001"
      },
      "failure_reason": null,
      "expires_at": "2026-11-27T10:15:00Z",
      "succeeded_at": "2026-11-27T10:01:12Z",
      "created_at": "2026-11-27T10:00:00Z",
      "amount_refunded": 0,
      "fees": {
        "provider": 76,
        "klink": 304,
        "total": 380
      },
      "net": 14820,
      "payment_link": null
    }
  }
}

Event types

TypeWhen
payment.succeededThe customer paid. Fulfil the order.
payment.failedThe bank declined or the payment failed.
payment.expiredNobody paid before expires_at.
payment.canceledYou canceled the payment.
refund.pendingA refund was created and is being processed.
refund.succeededThe refund was completed.
refund.failedThe refund could not be completed.
payout.createdA payout to your bank account was prepared.
payout.paidThe payout was transferred to your bank.
payout.canceledA prepared payout was canceled.

Verifying signatures

The header is t=<unix timestamp>,v1=<signature>, where the signature is the hex HMAC-SHA256 of <t>.<raw body> keyed with your endpoint's secret. To verify:

  1. Read the raw request body, before any JSON parsing (re-serialised JSON won't match).
  2. Split the header on , and take t and v1.
  3. Compute HMAC-SHA256(secret, t + "." + body) as lowercase hex.
  4. Compare it with v1 in constant time.
  5. Reject the request if t is more than 5 minutes from now, to stop replays.
import crypto from "node:crypto";
import express from "express";

const app = express();
const SECRET = process.env.KLINK_PAY_WEBHOOK_SECRET;
const TOLERANCE_SECONDS = 300;

// Use the raw body: the signature covers the exact bytes we sent.
app.post("/webhooks/klink-pay", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("Klink-Signature") ?? "";
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
  const t = Number(parts.t);
  const body = req.body.toString("utf8");

  const expected = crypto.createHmac("sha256", SECRET).update(`${t}.${body}`).digest("hex");
  const given = Buffer.from(parts.v1 ?? "", "hex");
  const valid =
    given.length === expected.length / 2 &&
    crypto.timingSafeEqual(given, Buffer.from(expected, "hex")) &&
    Math.abs(Date.now() / 1000 - t) <= TOLERANCE_SECONDS;
  if (!valid) return res.status(400).send("bad signature");

  const event = JSON.parse(body);
  // Deduplicate by event.id, then hand off to a queue and answer quickly.
  if (event.type === "payment.succeeded") {
    markOrderPaid(event.data.object.reference);
  }
  res.sendStatus(200);
});

Responding and retries

Answer with any 2xx status within a few seconds. Do the slow work (emails, fulfilment) after responding, e.g. in a queue. A non-2xx answer, a timeout or a connection error is retried after:

AttemptDelay after the previous attempt
230 seconds
32 minutes
410 minutes
530 minutes
61 hour
73 hours
86 hours
912 hours
1024 hours

After the last retry the delivery is marked failed. You can see every delivery, its HTTP status and error in the dashboard, and send it again with Retry.

Duplicates and order

  • The same event can arrive more than once (e.g. if your 200 got lost). Store the event id and skip ids you have handled.
  • Events can arrive out of order. Use data.object.status, or fetch the object with the API, rather than assuming the order.
  • Check livemode if one endpoint receives both modes.

Rotating the secret

Rotate an endpoint's secret in the dashboard if it may have leaked. The new secret is shown once; update your server straight away, because deliveries are signed with the new secret from then on.

Missed something while your server was down? List recent events with GET /v1/events.