# K-LINK Pay documentation > All K-LINK Pay docs in one Markdown file, generated from the same source as https://docs.klinkpay.net. Links are relative to https://docs.klinkpay.net. ## AGENTS Short rules for coding agents (Claude Code, Cursor and others) integrating with K-LINK Pay. - Base URL: `https://api.klinkpay.net/v1`. JSON in and out (`Content-Type: application/json`). Call the API from servers only, never from a browser or a mobile app. - Auth: send `Authorization: Bearer `. Secret keys start with `kp_test_` (test mode) or `kp_live_` (live mode); restricted keys start with `rk_test_` or `rk_live_` and only have the permissions they were given. Keys are created in the dashboard (https://app.klinkpay.net) under Developers, API keys, and are shown once. Read the key from an environment variable; never write it into code. - Test first: test keys work as soon as the account exists and never move real money. A test payment's hosted checkout has Simulate payment and Simulate failure buttons, and webhooks are sent as in live mode. - Amounts: integers in the currency's smallest unit (`1300` is SGD 13.00; `15200` is MMK 15,200 because MMK has no decimals). `currency` is a three-letter ISO 4217 code of one of the account's currency accounts. A live payment in a currency whose account is not active returns `403 currency_not_active`. - Take a payment: `POST /v1/payments` with `amount`, `currency` and your own `reference`. The response has `qr_payload` (draw it as a QR code) and `checkout_url` (the hosted checkout). A payment starts `pending` and ends `succeeded`, `failed`, `expired` or `canceled`. - Never mark an order paid because the customer came back from the checkout. Mark it paid from the `payment.succeeded` webhook, or by reading the payment with `GET /v1/payments/{id}`, after checking `amount`, `currency` and `reference` against the order. - Idempotency: send an `Idempotency-Key` header on every POST. A repeat with the same key and body returns the saved response; the same key with a different body returns `409 idempotency_conflict`. - Pagination: lists return `{"object": "list", "data": [...], "has_more": true}`, newest first. `limit` is 1 to 100 (default 20); page with `starting_after` or `ending_before` and an object id. - Errors: `{"error": {"code": "snake_case_code", "message": "...", "param": "..."}}` with the HTTP status. Branch on `code`, never on `message`. Retry `429`, `500`, `502` and `503` with exponential back-off and the same `Idempotency-Key`; do not retry other `4xx` unchanged. - Webhooks: K-LINK Pay POSTs the event as JSON with a `Klink-Signature: t=,v1=` header, where hex is the HMAC-SHA256 of `"."` keyed with the endpoint's secret. Verify it on the raw body in constant time and reject a `t` more than 5 minutes old. Answer `2xx` within a few seconds and do slow work afterwards. The same event can arrive more than once: store the event `id` and skip ids already handled. - Versioning: send `Klink-Version` to pin the API version your code was written for. - Every docs page is also Markdown: add `.md` to its URL (`https://docs.klinkpay.net/quickstart.md`). All docs in one file: https://docs.klinkpay.net/llms-full.txt. --- # What is K-LINK Pay K-LINK Pay is a payments API for Southeast Asia, built for AI agents and messaging channels. Send a payment QR code or a payment link in the chat, and a signed webhook tells you when it is paid. ## What you can build - **Payments in a chat.** An AI agent on Messenger, WhatsApp, LINE, Viber, Instagram, Telegram or your web chat creates a payment with one tool call and sends the QR code or the checkout link in the conversation. See [AI agents](/guides/ai-agents.md). - **Payments in your own product.** Your server creates a payment for an order and shows the QR code, or sends the customer to the hosted checkout. See the [Quick start](/quickstart.md). - **Payment links.** A fixed-amount link you create in the dashboard or by API and paste anywhere. See [Payment links](/api/payment-links.md). ## How a payment works 1. Your server (or your agent's tool handler) calls `POST /v1/payments` with an amount, a currency and your own reference. 2. K-LINK Pay answers with a `qr_payload` to draw as a QR code and a `checkout_url` for the hosted checkout. 3. The customer pays from their banking or wallet app. 4. K-LINK Pay sends a signed `payment.succeeded` webhook to your server. Check the amount and reference against your order, then confirm it to the customer. ```bash curl https://api.klinkpay.net/v1/payments \ -H "Authorization: Bearer $KLINK_PAY_API_KEY" \ -H "Idempotency-Key: order-1001" \ -H "Content-Type: application/json" \ -d '{"amount": 15200, "currency": "MMK", "reference": "order-1001"}' ``` Amounts are integers in the currency's smallest unit, and each payment is in the currency of one of your currency accounts. See [Amounts and currencies](/concepts/currencies.md). ## Addresses you will use | What | Address | Used by | |---|---|---| | REST API | `https://api.klinkpay.net/v1` | Your server only. Never call it from a browser or a mobile app. | | Dashboard | `https://app.klinkpay.net` | You: API keys, payments, payouts, currencies and webhooks. | | Hosted checkout | `https://checkout.klinkpay.net` | Your customers, through the `checkout_url` of a payment. | | Docs | `https://docs.klinkpay.net` | You and your coding agent. | ## Start here | If you want to | Read | |---|---| | Take a first test payment in about ten minutes | [Quick start](/quickstart.md) | | Create and store API keys | [Authentication and keys](/authentication.md) | | Test without moving real money | [Test mode](/testing.md) | | Let an AI agent take payments in a conversation | [AI agents](/guides/ai-agents.md) | | Know when a payment is paid | [Webhooks](/guides/webhooks.md) | | Look up an endpoint | [API reference](/api.md) | ## For coding agents These docs are written to be read by coding agents such as Claude Code and Cursor as well as by people. - [llms.txt](/llms.txt) is the index of every page, with short rules for integrating. - [llms-full.txt](/llms-full.txt) is all the docs in one Markdown file. - Every page is also Markdown: add `.md` to its URL, for example `https://docs.klinkpay.net/quickstart.md`. - **Copy page** at the top of each page copies it as Markdown, ready to paste into a chat. A prompt you can give your agent: ```text Read https://docs.klinkpay.net/llms.txt, then add K-LINK Pay payments to this project: create a payment for an order, show the QR code or redirect to checkout_url, and mark the order paid from the payment.succeeded webhook after verifying its signature. Use test keys (kp_test_...) from the environment variable KLINK_PAY_API_KEY. ``` ## Related - [Quick start](/quickstart.md) - [API reference](/api.md) - [Errors](/concepts/errors.md) --- # Quick start Take your first QR payment in test mode in about ten minutes. Building an AI agent? See Using K-LINK Pay from an AI agent. K-LINK Pay is a REST API at `https://api.klinkpay.net/v1`. You create a payment from your server, show the customer a QR code (or send them to our hosted checkout), and we tell your server when it is paid with a signed webhook. Every amount is an integer in the currency's smallest unit: `1300` is SGD 13.00, and `15200` is MMK 15,200 because MMK has no decimals. See [Amounts and currencies](/concepts/currencies.md). > [!NOTE] > **Payment methods and currencies** K-LINK Pay takes QR payments on Southeast Asia's national QR standards, wallet push and cards. Each payment is in the currency of one of your currency accounts, and a currency works in live mode once its account is active. See [Amounts and currencies](/concepts/currencies.md). The examples on this page use `MMK`; send the currency of your own account. ## 1. Get a test key 1. [Sign up](https://app.klinkpay.net/signup) and set up two-factor sign-in. 2. Open **Developers → API keys** in the dashboard and create a **test** secret key. It starts with `kp_test_` and is shown once: store it as a secret on your server (e.g. `KLINK_PAY_SECRET_KEY`). > [!NOTE] > Test keys work from the moment you sign up. Live keys (`kp_live_`) can be created once your account has been reviewed and is `active`. See [Authentication](/authentication.md). ## 2. Create a payment Call [POST /v1/payments](/api/payments.md#create-a-payment) from your server with the amount and your own order reference. Send an [Idempotency-Key](/concepts/idempotency.md) so a retry never creates a second payment. ```bash curl https://api.klinkpay.net/v1/payments \ -H "Authorization: Bearer kp_test_…" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: order-1001" \ -d '{ "amount": 15200, "currency": "MMK", "reference": "order-1001", "description": "Table 4", "return_url": "https://shop.example.com/orders/1001" }' ``` ```javascript // Node 18+ (built-in fetch) const res = await fetch("https://api.klinkpay.net/v1/payments", { method: "POST", headers: { Authorization: `Bearer ${process.env.KLINK_PAY_SECRET_KEY}`, "Content-Type": "application/json", "Idempotency-Key": "order-1001", }, body: JSON.stringify({ amount: 15200, // smallest unit: MMK has no decimals, so this is MMK 15,200 currency: "MMK", reference: "order-1001", description: "Table 4", return_url: "https://shop.example.com/orders/1001", }), }); if (!res.ok) throw new Error((await res.json()).error.message); const payment = await res.json(); // Redirect the customer to payment.checkout_url, or draw payment.qr_payload as a QR code. ``` ```php true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ "Authorization: Bearer " . getenv("KLINK_PAY_SECRET_KEY"), "Content-Type: application/json", "Idempotency-Key: order-1001", ], CURLOPT_POSTFIELDS => json_encode([ "amount" => 15200, "currency" => "MMK", "reference" => "order-1001", "description" => "Table 4", "return_url" => "https://shop.example.com/orders/1001", ]), ]); $payment = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status >= 400) { throw new Exception($payment["error"]["message"]); } header("Location: " . $payment["checkout_url"]); ``` ```python import os import requests res = requests.post( "https://api.klinkpay.net/v1/payments", headers={ "Authorization": f"Bearer {os.environ['KLINK_PAY_SECRET_KEY']}", "Idempotency-Key": "order-1001", }, json={ "amount": 15200, "currency": "MMK", "reference": "order-1001", "description": "Table 4", "return_url": "https://shop.example.com/orders/1001", }, timeout=15, ) if not res.ok: raise RuntimeError(res.json()["error"]["message"]) payment = res.json() # Redirect to payment["checkout_url"], or render payment["qr_payload"] as a QR code. ``` The response is a [payment](/api/payments.md#the-payment-object) in status `pending`: ```json title="Response 200" { "id": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "object": "payment", "livemode": false, "status": "pending", "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": null, "created_at": "2026-11-27T10:00:00Z", "amount_refunded": 0, "fees": null, "net": null, "payment_link": null } ``` ## 3. Let the customer pay Pick one of two ways: - **Redirect to the hosted checkout.** Send the customer to `checkout_url`. It shows the amount, the QR, a countdown and the live status, and returns them to your `return_url` after a successful payment (with `payment_id` and `status` added to the query string). - **Show the QR yourself.** Draw `qr_payload` as a QR code (any QR library) in your app, on a screen at the counter, or as an image message in a chat. The customer scans it with a banking or wallet app that supports that QR standard. ```javascript title="Node.js: render qr_payload" import QRCode from "qrcode"; const svg = await QRCode.toString(payment.qr_payload, { type: "svg", margin: 1 }); // Put the SVG on your page; show payment.amount and a timer until payment.expires_at. // In a chat, render a PNG instead and send it as an image: see the AI agent guide. ``` > [!NOTE] > The customer's banking app shows **K-LINK** as the payee, because every payment goes through K-LINK's merchant account. The hosted checkout says "Pay via K-LINK Pay" so your customers aren't surprised. To push a payment request into the customer's mobile wallet app instead of showing a QR (the payer approves it in the app), create the payment with `"method": "ayapay_push"` and their `customer_phone`. ## 4. Handle the webhook Add an endpoint under **Developers → Webhooks** in the dashboard (or with the [API](/api/webhook-endpoints.md)) and keep its signing secret. When the payment succeeds we `POST` a `payment.succeeded` event to it. Verify the `Klink-Signature` header, then fulfil the order. Answer with a `2xx` quickly; anything else is retried. ```javascript 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); }); ``` ```php 300) { http_response_code(400); exit("bad signature"); } $event = json_decode($body, true); // Deduplicate by $event["id"]. if ($event["type"] === "payment.succeeded") { mark_order_paid($event["data"]["object"]["reference"]); } http_response_code(200); ``` ```python import hashlib import hmac import json import os import time from flask import Flask, abort, request app = Flask(__name__) SECRET = os.environ["KLINK_PAY_WEBHOOK_SECRET"].encode() @app.post("/webhooks/klink-pay") def klink_pay_webhook(): body = request.get_data() # raw bytes parts = dict(p.split("=", 1) for p in request.headers.get("Klink-Signature", "").split(",") if "=" in p) t = int(parts.get("t", "0")) expected = hmac.new(SECRET, f"{t}.".encode() + body, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, parts.get("v1", "")) or abs(time.time() - t) > 300: abort(400) event = json.loads(body) # Deduplicate by event["id"]. if event["type"] == "payment.succeeded": mark_order_paid(event["data"]["object"]["reference"]) return "", 200 ``` > [!WARNING] > **Trust the webhook, not the redirect** Customers can close the page before they are sent back to `return_url`, and anyone can open that URL. Mark an order paid only from a verified webhook, or by fetching the payment with [GET /v1/payments/:id](/api/payments.md#retrieve-a-payment). ## 5. Test it Open the `checkout_url` of a test payment. Test mode has **Simulate payment** and **Simulate failure** buttons instead of a real bank; your webhook receives the event as it would in live mode. See [Test mode](/testing.md). ## 6. Go live 1. In the dashboard, complete the onboarding checklist: business profile, documents, bank account, then **Submit for review**. 2. Once your account is `active`, create a live key and a live (or both-modes) webhook endpoint. 3. Swap `kp_test_` for `kp_live_` on your server. Successful payments are paid out to your bank account after your payout delay, on your payout schedule. --- # Authentication and keys Every request is authenticated with an API key in the Authorization header. ```bash curl https://api.klinkpay.net/v1/balance \ -H "Authorization: Bearer kp_test_…" ``` Keys are created in the dashboard under **Developers → API keys**. A key is shown once when it is created; store it in your server's secret store and never put it in a browser or mobile app. ## Kinds of keys | Prefix | Kind | Mode | Can do | |---|---|---|---| | `kp_test_…` | Secret | Test | Everything, against the sandbox | | `kp_live_…` | Secret | Live | Everything, real money | | `rk_test_…` | Restricted | Test | Only its permissions | | `rk_live_…` | Restricted | Live | Only its permissions | The mode of the key decides the mode of everything it creates and sees: a test key only sees test payments, refunds, events and payouts (`livemode: false`), a live key only live ones. ## Restricted keys Give a service only what it needs, e.g. a reporting job that may read payments and payouts but never create a refund. A restricted key that calls an endpoint outside its permissions gets `403 forbidden`. | Permission | Allows | |---|---| | `payments:read` | List and retrieve payments | | `payments:write` | Create and cancel payments | | `refunds:read` | List and retrieve refunds | | `refunds:write` | Create refunds | | `payment_links:read` | List and retrieve payment links | | `payment_links:write` | Create and deactivate payment links | | `events:read` | List and retrieve events | | `balance:read` | Retrieve the balance | | `payouts:read` | List and retrieve payouts | | `webhook_endpoints:read` | List webhook endpoints | | `webhook_endpoints:write` | Create and delete webhook endpoints | ## Live keys and account status - Test keys work from sign-up, whatever the account status. - Live keys only work once your account is `active` (reviewed and approved). Otherwise every live request returns `403` with code `account_not_active`. - A `restricted` account can still read with live keys but cannot create new payments. - A `suspended` account gets `403` for everything. ## Keeping keys safe - Revoke a key in the dashboard the moment you think it leaked; it stops working at once. - Use one key per server or service, with a label, so you can revoke one without touching the others. - The dashboard shows when each key was last used. > [!NOTE] > An invalid, missing or revoked key returns `401 unauthorized`. See [Errors](/concepts/errors.md). --- # Test mode Build and test your whole integration without moving real money. Every account has a test mode and a live mode, fully separated. Requests made with a test key (`kp_test_…` or `rk_test_…`) go to a sandbox bank instead of a real one, and every object they create has `livemode: false`. Test keys work from the moment you sign up, before your account is reviewed. ## What works the same - Payments, refunds, payment links, events and webhooks behave exactly as in live mode. - Refunds are requests in test mode too: a test refund is created with status `manual` and sends `refund.pending`. It is not refunded instantly; it stays `manual` until it is marked done, then sends `refund.succeeded`. - The hosted checkout shows a real, scannable-looking QR and polls for the status. - Webhooks are signed and retried the same way. A webhook endpoint can listen to test, live or both modes. - The balance and payouts are tracked separately for test mode. ## Simulating the customer Nobody can pay a test QR with a real banking app. Instead, the hosted checkout of a test payment (its `checkout_url`) shows a **Test mode** banner and two buttons: | Button | Result | Event | |---|---|---| | **Simulate payment** | Status becomes `succeeded`, fees and net are set | `payment.succeeded` | | **Simulate failure** | Status becomes `failed` | `payment.failed` | If you draw the QR yourself, open the payment's `checkout_url` in a browser to press the buttons. To test expiry, create a payment with a short `expires_in_minutes` and wait: it becomes `expired` and sends `payment.expired`. To test cancelling, call [cancel](/api/payments.md#cancel-a-payment). ```bash title="A payment that expires in 1 minute" curl https://api.klinkpay.net/v1/payments \ -X POST \ -H "Authorization: Bearer kp_test_…" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": 1000, "reference": "expiry-test", "expires_in_minutes": 1 }' ``` ## Going live Nothing in your code changes except the key. When your account is `active`, create a `kp_live_` key and a webhook endpoint for live mode (or one for both), and use them in production. > [!WARNING] > Never share test and live keys in the same environment variable across environments. Keep test keys in staging and live keys in production. --- # AI agents Let your AI agent send a payment QR code or a payment link inside the conversation, in whatever channel the customer is chatting on, and confirm the order once it's paid. K-LINK Pay has no special "agent API": your agent uses the same REST API as any server. You give the model a `create_payment` tool, your code calls [POST /v1/payments](/api/payments.md#create-a-payment), and the agent sends the payment into the chat: either the `qr_payload` rendered as a QR image, or the `checkout_url` (or a payment link). Because the result is an image or a link, it works in any channel that can show one: Facebook Messenger, WhatsApp, LINE, Viber, Instagram, Telegram, your own web chat. No channel-specific integration is needed. ## How the flow works 1. The customer confirms an order in the chat. The agent calls your `create_payment` tool. 2. Your tool handler looks up the order and calls `POST /v1/payments` with the order's total. The payment comes back with a `qr_payload` and a `checkout_url`. 3. The agent sends the payment in the conversation, in one of two ways:**A QR image.** Render `qr_payload` into a PNG and send it with the channel's image-message API. The customer scans it with their banking or wallet app, or saves it and picks it from their gallery to pay on the same phone.**A link.** Send the `checkout_url` or a payment link. The customer taps it and the mobile-first hosted checkout opens in the channel's in-app browser, with the QR, a save-image button and the live status. 4. K-LINK Pay sends a signed `payment.succeeded` webhook. Your server verifies it and the agent confirms the order in the same conversation. ## 1. Create a restricted key for the agent Don't give the agent's runtime your secret key. Create a [restricted key](/authentication.md#restricted-keys) under **Developers → API keys** with only the permissions it needs: | Permission | Why the agent needs it | |---|---| | `payments:write` | Create a payment for an order. | | `payments:read` | Check a payment's status when the customer asks "did it go through?" | | `payment_links:write` | Only if you use payment links instead of payments. | A restricted key can't refund, read payouts or change webhook endpoints; anything outside its permissions returns `403 forbidden`. Build with an `rk_test_…` key and switch to `rk_live_…` once your account is active. ## 2. Define the tool A JSON Schema function definition. Most LLM APIs accept this shape; some call the schema `parameters`, others `input_schema`. The model chooses _which order_ to charge; it never decides the price. ```json title="create_payment tool" { "name": "create_payment", "description": "Create a K-LINK Pay payment for the customer's confirmed order and return a checkout_url to send in this conversation. Call it only after the customer has confirmed the order and the total.", "parameters": { "type": "object", "properties": { "reference": { "type": "string", "description": "The id of the order being paid, e.g. order-1001." }, "amount": { "type": "integer", "description": "The total you quoted to the customer, in the smallest currency unit (1300 = SGD 13.00; MMK has no decimals, so 15200 = MMK 15,200). Checked against the order on the server." }, "description": { "type": "string", "description": "Short text shown on the checkout, e.g. 2 x Large milk tea." } }, "required": ["reference", "amount"] } } ``` ## 3. The full flow in Node.js Tool handlers for `create_payment` and `get_payment_status`, and the webhook that closes the loop. The conversation id goes into the payment's `metadata`, which comes back on every event, so the webhook knows which chat to reply in. ```javascript title="agent-payments.js" // agent-payments.js: Node 18+ (built-in fetch), Express for the webhook. import crypto from "node:crypto"; import express from "express"; const API = "https://api.klinkpay.net/v1"; // A restricted key with only payments:write and payments:read. // rk_test_… while you build, rk_live_… in production. const KEY = process.env.KLINK_PAY_AGENT_KEY; const WEBHOOK_SECRET = process.env.KLINK_PAY_WEBHOOK_SECRET; async function klinkPay(method, path, body, idempotencyKey) { const res = await fetch(API + path, { method, headers: { Authorization: `Bearer ${KEY}`, ...(body ? { "Content-Type": "application/json" } : {}), ...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}), }, body: body ? JSON.stringify(body) : undefined, }); const json = await res.json(); if (!res.ok) throw Object.assign(new Error(json.error.message), { code: json.error.code }); return json; } // 1. Tools you give the model (JSON Schema; rename "parameters" if your LLM API expects another key). export const tools = [ { name: "create_payment", description: "Create a payment for the customer's confirmed order and return a checkout_url to send in this conversation.", parameters: { type: "object", properties: { reference: { type: "string", description: "The id of the order being paid." }, amount: { type: "integer", description: "The total quoted to the customer, smallest currency unit." }, description: { type: "string", description: "Short text shown on the checkout." }, }, required: ["reference", "amount"], }, }, { name: "get_payment_status", description: "Check whether the customer's payment for an order has been paid.", parameters: { type: "object", properties: { reference: { type: "string", description: "The id of the order." } }, required: ["reference"], }, }, ]; // 2. Tool handlers. `convo` comes from your agent runtime, never from the model. export const handlers = { async create_payment({ reference, amount, description }, convo) { const order = await orders.get(reference, { conversation: convo.id }); if (!order) return { error: "unknown_order" }; if (order.status === "paid") return { error: "already_paid" }; // Never let the model set the price: compare with the order and charge the order's total. if (amount !== order.total) return { error: "amount_mismatch", total: order.total }; const payment = await klinkPay( "POST", "/payments", { amount: order.total, currency: "MMK", reference: order.id, description: description ?? order.summary, expires_in_minutes: 30, metadata: { conversation_id: convo.id, channel: convo.channel }, }, // Retries of the same tool call return the same payment instead of a second one. // Add an attempt number when you deliberately create a new payment (e.g. the last one expired). `${convo.id}:${order.id}:${order.paymentAttempt}`, ); await orders.update(order.id, { paymentId: payment.id }); return { checkout_url: payment.checkout_url, // send this link in the chat amount: payment.amount, currency: payment.currency, expires_at: payment.expires_at, }; }, async get_payment_status({ reference }, convo) { const order = await orders.get(reference, { conversation: convo.id }); if (!order?.paymentId) return { status: "no_payment" }; const payment = await klinkPay("GET", `/payments/${order.paymentId}`); return { status: payment.status }; // pending | succeeded | failed | expired | canceled }, }; // 3. The webhook closes the loop: verify it, then confirm in the same conversation. const app = express(); app.post("/webhooks/klink-pay", express.raw({ type: "application/json" }), async (req, res) => { const parts = Object.fromEntries((req.get("Klink-Signature") ?? "").split(",").map((p) => p.split("=", 2))); const t = Number(parts.t); const body = req.body.toString("utf8"); const expected = crypto.createHmac("sha256", WEBHOOK_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) <= 300; if (!valid) return res.status(400).send("bad signature"); const event = JSON.parse(body); res.sendStatus(200); // answer fast, then do the work if (await processedEvents.has(event.id)) return; // deliveries can repeat await processedEvents.add(event.id); const payment = event.data.object; const order = await orders.get(payment.reference); if (!order || payment.amount !== order.total) return; // not ours, or not the amount we expect if (event.type === "payment.succeeded") { await orders.update(order.id, { status: "paid" }); await channels.send(payment.metadata.conversation_id, `Payment received, thank you! Order ${order.id} is confirmed.`); } else if (event.type === "payment.expired" || event.type === "payment.failed") { await orders.update(order.id, { paymentAttempt: order.paymentAttempt + 1 }); await channels.send(payment.metadata.conversation_id, "That payment didn't go through. Shall I send you a new link?"); } }); app.listen(3000); // `orders`, `processedEvents` and `channels` are your own order store, dedup store and // messaging-channel client (Messenger, WhatsApp, LINE, Viber, Telegram, web chat, …). ``` ### Sending a payment link instead If your channel or agent platform can only share a URL, a [payment link](/api/payment-links.md) works too: a fixed-amount page that creates the payment when the customer presses Pay. Use `single_use: true` for one order. Payments made through a link carry its id in `payment_link`, so store the link id with the order. ```bash title="Create a single-use payment link" curl https://api.klinkpay.net/v1/payment_links \ -H "Authorization: Bearer rk_test_…" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: conv_8812:order-1001" \ -d '{ "amount": 15200, "description": "2 x Large milk tea", "single_use": true, "metadata": { "conversation_id": "conv_8812", "order_id": "order-1001" } }' # → { "id": "plink_…", "url": "https://checkout.klinkpay.net/l/plink_…", … } # Send "url" in the chat. Payments made through it carry "payment_link": "plink_…". ``` ### Send the QR as an image In channels that show images, turn `qr_payload` into a PNG with the `qrcode` npm package and send the buffer through the channel's image-message API. Send the `checkout_url` as a caption or a follow-up message too, so a customer who can't scan (they're on the same phone) can tap it instead. ```javascript title="send-payment-qr.js" import QRCode from "qrcode"; // After POST /v1/payments: `payment` is the created payment. async function sendPaymentInChat(convo, payment) { if (payment.qr_payload) { // A PNG Buffer, large enough to scan from a phone screen. const png = await QRCode.toBuffer(payment.qr_payload, { type: "png", width: 600, margin: 2 }); // Your channel client's image-message call (Messenger, WhatsApp, LINE, Viber, Telegram, web chat, …). await channels.sendImage(convo.id, png, { filename: `pay-${payment.id}.png`, caption: `Scan to pay with your banking or wallet app, or tap: ${payment.checkout_url}`, }); } else { // No QR for this method (e.g. wallet push): send the hosted checkout link. await channels.sendText(convo.id, `You can pay here: ${payment.checkout_url}`); } } // Some channels only take an image URL, not a file: upload the PNG to your own storage // first, or send the checkout_url / a payment link instead. ``` `qr_payload` is only set for QR payments; for wallet push it is `null`, so send the link. Don't crop or restyle the QR, and keep the quiet margin around it so banking apps can read it. ## Safety rules - **Use a restricted key.** `payments:write` and `payments:read` only. Keep the key on your server, never in a prompt or a client. - **Idempotency key = conversation + order id.** Agents retry: a tool call can time out, or the model can call the tool twice. Send `Idempotency-Key: :` so a retry returns the same payment instead of a second one. When you deliberately need a new payment for the same order (the last one expired), add an attempt number. See [Idempotency](/concepts/idempotency.md). - **Never let the model choose the amount freely.** Compute the amount on your server from the order. If the model passes an amount, only compare it with the order's total and refuse a mismatch; always charge the total from your own data. - **Only the webhook says "paid".** Verify the `Klink-Signature` header, check the amount and reference against your order, then tell the customer. Never trust a customer's "I paid" message, a screenshot, or the model's own belief. See [Verifying signatures](/guides/webhooks.md#verifying-signatures). - **Deduplicate events.** Webhooks can arrive more than once; store the event `id` so the agent doesn't confirm an order twice. - **Handle the other outcomes.** On `payment.expired` or `payment.failed`, let the agent offer a new link. Set `expires_in_minutes` to match how long a chat order should stay open. - **Keep refunds out of the agent.** Refunds are requests processed by K-LINK; start them from your dashboard or back office with a separate key, not from a model. ## Testing your agent With an `rk_test_…` key every payment is a test payment. Open its `checkout_url` and press **Simulate payment** or **Simulate failure**: your webhook gets the event exactly as in live mode, so you can test the whole conversation without moving real money. See [Test mode](/testing.md). > [!NOTE] > **Payment methods and currencies** K-LINK Pay takes QR payments on Southeast Asia's national QR standards, wallet push and cards. Each payment is in the currency of one of your currency accounts, and a currency works in live mode once its account is active. See [Amounts and currencies](/concepts/currencies.md). Every method uses the same API and webhooks, so the flow above stays the same. --- # 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](/api/webhook-endpoints.md). 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](/api/events.md), K-LINK Pay sends a `POST` with a JSON body (the event) and a `Klink-Signature` header: ```text title="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": 152, "total": 228 }, "net": 14972, "payment_link": null } } } ``` ## Event types | Type | When | |---|---| | `payment.succeeded` | The customer paid. Fulfil the order. | | `payment.failed` | The bank declined or the payment failed. | | `payment.expired` | Nobody paid before expires_at. | | `payment.canceled` | You canceled the payment. | | `refund.pending` | A refund was requested. K-LINK processes it to the payer (status manual). | | `refund.succeeded` | K-LINK refunded the payer and marked the refund done. | | `refund.failed` | The refund could not be completed. | | `payout.created` | A payout to your bank account was prepared. | | `payout.paid` | The payout was transferred to your bank. | | `payout.canceled` | A prepared payout was canceled. | ## Verifying signatures The header is `t=,v1=`, where the signature is the hex HMAC-SHA256 of `.` 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. ```javascript 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); }); ``` ```php 300) { http_response_code(400); exit("bad signature"); } $event = json_decode($body, true); // Deduplicate by $event["id"]. if ($event["type"] === "payment.succeeded") { mark_order_paid($event["data"]["object"]["reference"]); } http_response_code(200); ``` ```python import hashlib import hmac import json import os import time from flask import Flask, abort, request app = Flask(__name__) SECRET = os.environ["KLINK_PAY_WEBHOOK_SECRET"].encode() @app.post("/webhooks/klink-pay") def klink_pay_webhook(): body = request.get_data() # raw bytes parts = dict(p.split("=", 1) for p in request.headers.get("Klink-Signature", "").split(",") if "=" in p) t = int(parts.get("t", "0")) expected = hmac.new(SECRET, f"{t}.".encode() + body, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, parts.get("v1", "")) or abs(time.time() - t) > 300: abort(400) event = json.loads(body) # Deduplicate by event["id"]. if event["type"] == "payment.succeeded": mark_order_paid(event["data"]["object"]["reference"]) return "", 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: | Attempt | Delay after the previous attempt | |---|---| | 2 | 30 seconds | | 3 | 2 minutes | | 4 | 10 minutes | | 5 | 30 minutes | | 6 | 1 hour | | 7 | 3 hours | | 8 | 6 hours | | 9 | 12 hours | | 10 | 24 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. > [!NOTE] > Missed something while your server was down? List recent events with [GET /v1/events](/api/events.md). --- # Amounts and currencies Amounts are integers in the currency's smallest unit, and every payment is in the currency of one of your currency accounts. ## Amounts Every amount in the API is an integer in the smallest unit of its currency. There are no decimals and no floating point numbers, in requests or in responses. | Currency | Code | Decimals | `amount` | Means | |---|---|---|---|---| | Singapore dollar | `SGD` | 2 | `1300` | SGD 13.00 | | Thai baht | `THB` | 2 | `89000` | THB 890.00 | | Malaysian ringgit | `MYR` | 2 | `6200` | MYR 62.00 | | Philippine peso | `PHP` | 2 | `25000` | PHP 250.00 | | Cambodian riel | `KHR` | 2 | `2000000` | KHR 20,000.00 | | Lao kip | `LAK` | 2 | `5000000` | LAK 50,000.00 | | Brunei dollar | `BND` | 2 | `1300` | BND 13.00 | | US dollar | `USD` | 2 | `1000` | USD 10.00 | | Myanmar kyat | `MMK` | 0 | `15200` | MMK 15,200 | | Vietnamese dong | `VND` | 0 | `250000` | VND 250,000 | | Indonesian rupiah | `IDR` | 0 | `150000` | IDR 150,000 | To show an amount to a person, divide by 10 to the power of the decimals and format it yourself. Keep the integer for everything else: storing, comparing with your order, and sending back to the API. > [!WARNING] > Compare the `amount` and `currency` of a paid payment with your order before you fulfil it. `1300` in `SGD` and `1300` in `MMK` are very different sums. ## Currencies `currency` is a three-letter ISO 4217 code in upper case. One payment is in one currency; its refunds, fees and payout are in the same currency. ## Currency accounts Each currency has its own account with its own settlement bank account. You open currency accounts in the dashboard under **Currencies**. - Live payments work only in a currency whose account is **Active**. A live request in another currency returns `403 currency_not_active`. - Your balance and your payouts are kept per currency. A payout pays the balance of one currency to that currency's settlement bank account. - The payment methods a customer can use depend on the currency. K-LINK sets up the methods for each of your currency accounts. ```json title="HTTP 403" { "error": { "code": "currency_not_active", "message": "Your SGD account isn't active for live payments yet", "param": "currency" } } ``` ## Related - [Payments](/api/payments.md) - [Balance](/api/balance.md) - [Payouts](/api/payouts.md) - [Errors](/concepts/errors.md) --- # Errors Errors use HTTP status codes and a JSON body that says what went wrong. ```json title="HTTP 400" { "error": { "code": "invalid_request", "message": "amount must be a positive integer", "param": "amount" } } ``` - `code` is stable and meant for your code to check. - `message` is for people; its wording can change. - `param` is set when one request parameter is at fault. ## Codes | Code | Status | Meaning | |---|---|---| | `invalid_request` | 400 | A parameter is missing or invalid. `param` names it. | | `invalid_json` | 400 | The body is not valid JSON. | | `unauthorized` | 401 | No API key, or the key is invalid or revoked. | | `forbidden` | 403 | The key is not allowed to do this (e.g. a restricted key without the permission). | | `account_not_active` | 403 | A live key was used before the account is active. | | `currency_not_active` | 403 | A live payment was created in a currency whose account is not active. See [Amounts and currencies](/concepts/currencies.md). | | `not_found` | 404 | No such object (or it belongs to the other mode). | | `invalid_state` | 409 | The object is not in a state that allows this, e.g. refunding an unpaid payment. | | `idempotency_conflict` | 409 | The Idempotency-Key was used before with a different request. | | `rate_limited` | 429 | Too many requests. Back off and retry. | | `internal_error` | 500 | Something went wrong on our side. Safe to retry with the same Idempotency-Key. | | `provider_error` | 502 | The bank returned an error. | | `provider_unavailable` | 503 | The bank is not reachable right now. Retry later. | ## Retrying `429`, `500`, `502` and `503` are worth retrying with exponential back-off. Send the same `Idempotency-Key` on every retry of a POST so it can never be applied twice. `4xx` errors other than `429` will fail again until you change the request. --- # Pagination List endpoints return objects newest first, a page at a time, with cursor pagination. **Query parameters (every list endpoint)** | Field | Type | Description | |---|---|---| | `limit` | integer | How many objects to return, 1–100. Default 20. | | `starting_after` | string | An object id. Returns the objects after it in the list (older ones): the next page. | | `ending_before` | string | An object id. Returns the objects before it in the list (newer ones): the previous page. | ## The list object ```json { "object": "list", "data": [ { "id": "pay_…", "object": "payment", … }, … ], "has_more": true } ``` `has_more` is true when there are more objects beyond this page. ## Walking through every page ```javascript title="Node.js" let startingAfter; do { const url = new URL("https://api.klinkpay.net/v1/payments"); url.searchParams.set("limit", "100"); if (startingAfter) url.searchParams.set("starting_after", startingAfter); const page = await (await fetch(url, { headers: { Authorization: `Bearer ${key}` } })).json(); for (const payment of page.data) handle(payment); startingAfter = page.has_more ? page.data.at(-1).id : undefined; } while (startingAfter); ``` --- # Idempotency Retry a POST safely: the same Idempotency-Key never does the work twice. Networks fail. If your request to create a payment or a refund times out, you can't tell whether it was applied. Send an `Idempotency-Key` header on every POST (create payment, refund, payment link, webhook endpoint) and send the same key when you retry. ```bash curl https://api.klinkpay.net/v1/refunds \ -H "Authorization: Bearer kp_test_…" \ -H "Idempotency-Key: refund-order-1001-1" \ -H "Content-Type: application/json" \ -d '{"payment": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "amount": 5000}' ``` ## How it behaves - The first request with a key is processed normally and its response is saved. - A repeat with the same key and the same body returns the saved response without doing anything again. - A repeat with the same key but a different body or endpoint fails with `409 idempotency_conflict`. ## Choosing keys Use something unique per operation: a UUID, or a value from your own data like `order-1001` for the payment of order 1001. Never reuse a key for a different operation. --- # Versioning The API is versioned by date. The current version is 2026-11-27. Send `Klink-Version` to pin the version your code was written for. It is optional: without it you get the current version. Every response carries a `Klink-Version` header saying which version answered. ```bash curl https://api.klinkpay.net/v1/payments/pay_4Nq7xY2mKc8vTz1aB3dE9f \ -H "Authorization: Bearer kp_test_…" \ -H "Klink-Version: 2026-11-27" ``` ## What changes without a new version - New endpoints. - New optional request parameters. - New fields in responses and events (make your JSON parsing ignore unknown fields). - New event types (only sent to endpoints that listen to all events or that you subscribe). - New error codes and changes to error messages. Anything that could break working code (removing or renaming a field, changing a type) ships as a new dated version, announced in advance. ## Base URLs The API lives at `https://api.klinkpay.net/v1`. Integrations built for the earlier K-LINK payment portal at `https://pay.klinkcloud.com/v1` keep working: it serves the same API. See the [API reference](/api/payments.md). --- # API reference Every K-LINK Pay REST endpoint, grouped by resource, with its parameters, example requests and responses. ## Conventions - Base URL: `https://api.klinkpay.net`. All paths start with `/v1`. - Auth: `Authorization: Bearer $KLINK_PAY_API_KEY`. Test keys start with `kp_test_`, live keys with `kp_live_`. See [Authentication and keys](/authentication.md). - JSON in and out. Amounts are integers in the currency's smallest unit. See [Amounts and currencies](/concepts/currencies.md). - Errors are `{"error": {"code", "message", "param"}}` with the HTTP status. See [Errors](/concepts/errors.md). - Send an `Idempotency-Key` header on every `POST`. See [Idempotency](/concepts/idempotency.md). - Lists are newest first with cursor pagination. See [Pagination](/concepts/pagination.md). - Pin a version with the `Klink-Version` header. See [Versioning](/concepts/versioning.md). ```bash curl https://api.klinkpay.net/v1/payments?limit=3 \ -H "Authorization: Bearer $KLINK_PAY_API_KEY" ``` ## Resources | Resource | What it covers | Endpoints | |---|---|---| | [Payments](/api/payments.md) | A payment is one request for money from a customer, paid by scanning a QR code or approving it in a mobile wallet app. | 4 | | [Refunds](/api/refunds.md) | Request money back for a succeeded payment, in full or in part. | 3 | | [Events](/api/events.md) | Every change worth knowing about is recorded as an event and sent to your webhook endpoints. | 2 | | [Balance](/api/balance.md) | What K-LINK Pay holds for you, and when it will be paid out. | 1 | | [Payouts](/api/payouts.md) | Transfers of your available balance to your bank account. | 2 | | [Payment links](/api/payment-links.md) | A shareable page where customers pay a fixed amount, without any code on your side. | 4 | | [Webhook endpoints](/api/webhook-endpoints.md) | Manage the URLs that receive your webhooks from code. | 3 | ## Endpoints | Endpoint | What it does | |---|---| | `POST /v1/payments` | [Create a payment](/api/payments.md#create-a-payment) | | `GET /v1/payments/:id` | [Retrieve a payment](/api/payments.md#retrieve-a-payment) | | `GET /v1/payments` | [List payments](/api/payments.md#list-payments) | | `POST /v1/payments/:id/cancel` | [Cancel a payment](/api/payments.md#cancel-a-payment) | | `POST /v1/refunds` | [Create a refund](/api/refunds.md#create-a-refund) | | `GET /v1/refunds/:id` | [Retrieve a refund](/api/refunds.md#retrieve-a-refund) | | `GET /v1/refunds` | [List refunds](/api/refunds.md#list-refunds) | | `GET /v1/events/:id` | [Retrieve an event](/api/events.md#retrieve-an-event) | | `GET /v1/events` | [List events](/api/events.md#list-events) | | `GET /v1/balance` | [Retrieve the balance](/api/balance.md#retrieve-the-balance) | | `GET /v1/payouts/:id` | [Retrieve a payout](/api/payouts.md#retrieve-a-payout) | | `GET /v1/payouts` | [List payouts](/api/payouts.md#list-payouts) | | `POST /v1/payment_links` | [Create a payment link](/api/payment-links.md#create-a-payment-link) | | `GET /v1/payment_links/:id` | [Retrieve a payment link](/api/payment-links.md#retrieve-a-payment-link) | | `GET /v1/payment_links` | [List payment links](/api/payment-links.md#list-payment-links) | | `POST /v1/payment_links/:id/deactivate` | [Deactivate a payment link](/api/payment-links.md#deactivate-a-payment-link) | | `POST /v1/webhook_endpoints` | [Create a webhook endpoint](/api/webhook-endpoints.md#create-a-webhook-endpoint) | | `GET /v1/webhook_endpoints` | [List webhook endpoints](/api/webhook-endpoints.md#list-webhook-endpoints) | | `DELETE /v1/webhook_endpoints/:id` | [Delete a webhook endpoint](/api/webhook-endpoints.md#delete-a-webhook-endpoint) | ## Related - [Quick start](/quickstart.md) - [Webhooks](/guides/webhooks.md) - [Test mode](/testing.md) --- # Payments A payment is one request for money from a customer, paid by scanning a QR code or approving it in a mobile wallet app. Create a payment for every order. It starts `pending` and ends `succeeded`, `failed`, `expired` or `canceled`; each of those sends an [event](/guides/webhooks.md) (`payment.succeeded` and so on). ## The payment object | Field | Type | Description | |---|---|---| | `id` | string | Unique id, starts with `pay_`. | | `object` | string | Always `payment`. | | `livemode` | boolean | `true` for live mode, `false` for test mode. | | `status` | enum | `pending`, `succeeded`, `failed`, `expired` or `canceled`. Only `pending` can change. | | `amount` | integer | Amount in the currency's smallest unit: `1300` is SGD 13.00, `15200` is MMK 15,200. See [Amounts and currencies](/concepts/currencies.md). | | `currency` | string | Three-letter ISO 4217 code of the currency account the payment belongs to, such as `SGD`, `THB`, `MMK` or `MYR`. | | `method` | enum | `mmqr` (QR code scanned with any MMQR banking or wallet app) or `ayapay_push` (wallet push: the payer approves the payment in their mobile wallet app; requires `customer_phone`). K-LINK sets up other methods, such as other national QR standards and cards, for your account. | | `reference` | string | Your own reference, e.g. the order number. | | `bank_reference` | string | Short reference shown in the customer's banking app and on bank statements. | | `description` | string \| null | Shown to the customer on the checkout. | | `checkout_url` | string | Hosted checkout page for this payment. Redirect the customer here. | | `qr_payload` | string \| null | The QR string to render as a QR code yourself, e.g. as a PNG to send as an image in a chat. Set for QR payments. | | `redirect_url` | string \| null | For methods that hand the customer to another app, where to send them. | | `customer_phone` | string \| null | The customer's phone number for `ayapay_push`. | | `return_url` | string \| null | Where the hosted checkout sends the customer after a successful payment. | | `metadata` | object | Your own key–value data, returned as given. | | `failure_reason` | string \| null | Why the payment failed, when it did. | | `expires_at` | timestamp | After this the payment can no longer be paid and becomes `expired`. | | `succeeded_at` | timestamp \| null | When the payment succeeded. | | `created_at` | timestamp | When the payment was created. | | `amount_refunded` | integer | Total of refunds made on this payment. | | `fees` | object \| null | `{ provider, klink, total }`: the bank's fee and K-LINK Pay's fee. Set once the payment succeeded. | | `net` | integer \| null | `amount` minus `fees.total`: what you are paid out. Set once the payment succeeded. | | `payment_link` | string \| null | The `plink_` id when the payment was made through a [payment link](/api/payment-links.md). | ```json title="A succeeded payment" { "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": 152, "total": 228 }, "net": 14972, "payment_link": null } ``` ## Create a payment ```http POST /v1/payments ``` Send an [Idempotency-Key](/concepts/idempotency.md) header. Requires `payments:write` on restricted keys. Live keys only work for active accounts. **Body** | Field | Type | Required | Description | |---|---|---|---| | `amount` | integer | yes | In the smallest currency unit; a positive integer. | | `currency` | string | no | Three-letter ISO 4217 code of one of your currency accounts. In live mode the account must be active, or the request returns `403 currency_not_active`. Defaults to `MMK`. | | `method` | enum | no | `mmqr` (default) or `ayapay_push` (wallet push). K-LINK sets up other methods for your account. | | `reference` | string | yes | Your own reference for the payment, e.g. the order number. Search for it later with `?reference=`. | | `description` | string | no | Shown to the customer. | | `customer_phone` | string | no | Required for `ayapay_push`: the payer's wallet phone number to send the request to. | | `return_url` | string | no | HTTPS URL the hosted checkout returns the customer to after paying. `payment_id` and `status` are added to its query string. | | `expires_in_minutes` | integer | no | How long the payment can be paid. A default applies when omitted. | | `metadata` | object | no | Up to a few key–value pairs of your own. | ```bash curl https://api.klinkpay.net/v1/payments \ -H "Authorization: Bearer kp_test_…" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: order-1001" \ -d '{ "amount": 15200, "currency": "MMK", "reference": "order-1001", "description": "Table 4", "return_url": "https://shop.example.com/orders/1001" }' ``` ```javascript // Node 18+ (built-in fetch) const res = await fetch("https://api.klinkpay.net/v1/payments", { method: "POST", headers: { Authorization: `Bearer ${process.env.KLINK_PAY_SECRET_KEY}`, "Content-Type": "application/json", "Idempotency-Key": "order-1001", }, body: JSON.stringify({ amount: 15200, // smallest unit: MMK has no decimals, so this is MMK 15,200 currency: "MMK", reference: "order-1001", description: "Table 4", return_url: "https://shop.example.com/orders/1001", }), }); if (!res.ok) throw new Error((await res.json()).error.message); const payment = await res.json(); // Redirect the customer to payment.checkout_url, or draw payment.qr_payload as a QR code. ``` ```php true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ "Authorization: Bearer " . getenv("KLINK_PAY_SECRET_KEY"), "Content-Type: application/json", "Idempotency-Key: order-1001", ], CURLOPT_POSTFIELDS => json_encode([ "amount" => 15200, "currency" => "MMK", "reference" => "order-1001", "description" => "Table 4", "return_url" => "https://shop.example.com/orders/1001", ]), ]); $payment = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status >= 400) { throw new Exception($payment["error"]["message"]); } header("Location: " . $payment["checkout_url"]); ``` ```python import os import requests res = requests.post( "https://api.klinkpay.net/v1/payments", headers={ "Authorization": f"Bearer {os.environ['KLINK_PAY_SECRET_KEY']}", "Idempotency-Key": "order-1001", }, json={ "amount": 15200, "currency": "MMK", "reference": "order-1001", "description": "Table 4", "return_url": "https://shop.example.com/orders/1001", }, timeout=15, ) if not res.ok: raise RuntimeError(res.json()["error"]["message"]) payment = res.json() # Redirect to payment["checkout_url"], or render payment["qr_payload"] as a QR code. ``` ```json title="Response" { "id": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "object": "payment", "livemode": false, "status": "pending", "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": null, "created_at": "2026-11-27T10:00:00Z", "amount_refunded": 0, "fees": null, "net": null, "payment_link": null } ``` > [!NOTE] > For `ayapay_push` (wallet push), the customer gets a notification in their mobile wallet app and approves it there; `qr_payload` is `null`. You can still send them to `checkout_url`, which tells them to approve the payment in their wallet app. ## Retrieve a payment ```http GET /v1/payments/:id ``` Returns the payment. Use it to confirm the status from your server, e.g. when the customer comes back to `return_url`. ```bash title="Request" curl https://api.klinkpay.net/v1/payments/pay_4Nq7xY2mKc8vTz1aB3dE9f \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "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": 152, "total": 228 }, "net": 14972, "payment_link": null } ``` ## List payments ```http GET /v1/payments ``` **Query** | Field | Type | Description | |---|---|---| | `reference` | string | Only payments with this reference. | | `status` | enum | Only payments in this status. | | `limit` | integer | 1–100, default 20. See [Pagination](/concepts/pagination.md). | | `starting_after` | string | Cursor: a payment id. | | `ending_before` | string | Cursor: a payment id. | ```bash title="Request" curl https://api.klinkpay.net/v1/payments?reference=order-1001 \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "object": "list", "data": [ { "id": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "object": "payment", "livemode": false, "status": "pending", "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": null, "created_at": "2026-11-27T10:00:00Z", "amount_refunded": 0, "fees": null, "net": null, "payment_link": null } ], "has_more": false } ``` ## Cancel a payment ```http POST /v1/payments/:id/cancel ``` Cancels a `pending` payment so it can no longer be paid, e.g. when the customer changes their order. Returns the payment with status `canceled` and sends `payment.canceled`. A payment that is no longer pending returns `409 invalid_state`. ```bash title="Request" curl https://api.klinkpay.net/v1/payments/pay_4Nq7xY2mKc8vTz1aB3dE9f/cancel \ -X POST \ -H "Authorization: Bearer kp_test_…" \ -H "Idempotency-Key: $(uuidgen)" ``` ```json title="Response" { "id": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "object": "payment", "livemode": false, "status": "canceled", "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": null, "created_at": "2026-11-27T10:00:00Z", "amount_refunded": 0, "fees": null, "net": null, "payment_link": null } ``` --- # Refunds Request money back for a succeeded payment, in full or in part. A refund is a request: K-LINK processes the refund to the payer, then marks it done. Every refund is created with status `manual` and sends `refund.pending`. When K-LINK has refunded the payer it becomes `succeeded` and you receive `refund.succeeded`. Refunds are not instant, in live or test mode. The amount is deducted from your next [payout](/api/payouts.md) from the moment the refund is requested, so it can't be paid out to you as well. If refunds are more than the payout, the rest carries over to later payouts. ## The refund object | Field | Type | Description | |---|---|---| | `id` | string | Starts with `rf_`. | | `object` | string | Always `refund`. | | `livemode` | boolean | Test or live mode. | | `payment` | string | The id of the refunded payment. | | `amount` | integer | Refunded amount in the smallest currency unit. | | `currency` | string | Same as the payment. | | `status` | enum | `manual` (requested; K-LINK is processing the refund to the payer), then `succeeded` once K-LINK has refunded the payer, or `failed`. `pending` is part of the enum but new refunds start as `manual`. | | `reason` | string \| null | Your note on why. | | `created_at` | timestamp | When the refund was created. | ```json title="A refund" { "id": "rf_8Hk2Lm4Np6Qr8St0Uv2Wx4", "object": "refund", "livemode": false, "payment": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "amount": 5000, "currency": "MMK", "status": "manual", "reason": "Customer returned one item", "created_at": "2026-11-27T11:00:00Z" } ``` ## Create a refund ```http POST /v1/refunds ``` **Body** | Field | Type | Required | Description | |---|---|---|---| | `payment` | string | yes | Id of a `succeeded` payment. | | `amount` | integer | no | Defaults to what is left to refund. Can't exceed `amount − amount_refunded`. | | `reason` | string | no | Free text. | Returns the refund with status `manual` and sends `refund.pending`. Requires `refunds:write` on restricted keys. Refunding a payment that hasn't succeeded, or more than is left, returns `409 invalid_state` or `400 invalid_request`. ```bash title="Request" curl https://api.klinkpay.net/v1/refunds \ -X POST \ -H "Authorization: Bearer kp_test_…" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "payment": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "amount": 5000, "reason": "Customer returned one item" }' ``` ```json title="Response" { "id": "rf_8Hk2Lm4Np6Qr8St0Uv2Wx4", "object": "refund", "livemode": false, "payment": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "amount": 5000, "currency": "MMK", "status": "manual", "reason": "Customer returned one item", "created_at": "2026-11-27T11:00:00Z" } ``` ## Retrieve a refund ```http GET /v1/refunds/:id ``` Returns the refund. ```bash title="Request" curl https://api.klinkpay.net/v1/refunds/rf_8Hk2Lm4Np6Qr8St0Uv2Wx4 \ -H "Authorization: Bearer kp_test_…" ``` ## List refunds ```http GET /v1/refunds ``` **Query** | Field | Type | Description | |---|---|---| | `payment` | string | Only refunds of this payment. | | `limit, starting_after, ending_before` | | See [Pagination](/concepts/pagination.md). | ```bash title="Request" curl https://api.klinkpay.net/v1/refunds?payment=pay_4Nq7xY2mKc8vTz1aB3dE9f \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "object": "list", "data": [ { "id": "rf_8Hk2Lm4Np6Qr8St0Uv2Wx4", "object": "refund", "livemode": false, "payment": "pay_4Nq7xY2mKc8vTz1aB3dE9f", "amount": 5000, "currency": "MMK", "status": "manual", "reason": "Customer returned one item", "created_at": "2026-11-27T11:00:00Z" } ], "has_more": false } ``` > [!NOTE] > Refund events: `refund.pending` when the refund is requested, `refund.succeeded` when K-LINK has refunded the payer, `refund.failed` if it could not be completed. Wait for `refund.succeeded` before telling the customer the money is back. --- # Events Every change worth knowing about is recorded as an event and sent to your webhook endpoints. ## The event object | Field | Type | Description | |---|---|---| | `id` | string | Starts with `evt_`. Use it to deduplicate webhook deliveries. | | `object` | string | Always `event`. | | `type` | string | `payment.succeeded`, `payment.failed`, `payment.expired`, `payment.canceled`, `refund.succeeded`, `refund.pending`, `refund.failed`, `payout.created`, `payout.paid`, `payout.canceled`. A refund sends `refund.pending` when it is requested and `refund.succeeded` when K-LINK has processed it to the payer. | | `livemode` | boolean | Test or live mode. | | `created_at` | timestamp | When it happened. | | `data.object` | object | The payment, refund or payout as it was at that moment. | ```json title="payment.succeeded" { "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": 152, "total": 228 }, "net": 14972, "payment_link": null } } } ``` ## Retrieve an event ```http GET /v1/events/:id ``` Returns the event. Requires `events:read` on restricted keys. ```bash title="Request" curl https://api.klinkpay.net/v1/events/evt_2Bc4De6Fg8Hi0Jk2Lm4No6 \ -H "Authorization: Bearer kp_test_…" ``` ## List events ```http GET /v1/events ``` **Query** | Field | Type | Description | |---|---|---| | `type` | string | Only events of this type, e.g. `payment.succeeded`. | | `limit, starting_after, ending_before` | | See [Pagination](/concepts/pagination.md). | ```bash title="Request" curl https://api.klinkpay.net/v1/events?type=payment.succeeded&limit=10 \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "object": "list", "data": [ { "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": 152, "total": 228 }, "net": 14972, "payment_link": null } } } ], "has_more": false } ``` --- # Balance What K-LINK Pay holds for you, and when it will be paid out. Every succeeded payment adds its `net` (amount minus fees) to your balance. It is `pending` for your payout delay (set for your account), then `available` for the next payout. A key's mode decides which balance you see. ## The balance object | Field | Type | Description | |---|---|---| | `object` | string | Always `balance`. | | `livemode` | boolean | Test or live mode. | | `currency` | string | Three-letter ISO 4217 code, such as `SGD`, `THB` or `MMK`. | | `pending` | integer | Net of succeeded payments still within their payout delay. | | `available` | integer | Net ready for the next payout. Can be negative when refunds are more than it. | | `in_payouts` | integer | Net in payouts that are prepared but not yet paid. | | `refunds_owed` | integer | Refunds still to be deducted from future payouts. | | `next_payout_at` | timestamp \| null | When the next payout is expected, if one is scheduled. | ```json title="Balance" { "object": "balance", "livemode": true, "currency": "MMK", "pending": 50000, "available": 120000, "in_payouts": 30000, "refunds_owed": 0, "next_payout_at": "2026-11-28T03:30:00Z" } ``` ## Retrieve the balance ```http GET /v1/balance ``` Requires `balance:read` on restricted keys. ```bash title="Request" curl https://api.klinkpay.net/v1/balance \ -H "Authorization: Bearer kp_test_…" ``` --- # Payouts Transfers of your available balance to your bank account. - A payment becomes payable after your payout delay, which is set for your account. - Payouts are made on your schedule (daily, weekly or on request) to your verified bank account. - Each payout is the gross of its payments, minus refunds, the bank's fee and K-LINK Pay's fee. A refund is deducted from the next payout from the moment it is requested. - The dashboard has a CSV statement of every payment and refund in a payout. ## The payout object | Field | Type | Description | |---|---|---| | `id` | string | Starts with `po_`. | | `object` | string | Always `payout`. | | `livemode` | boolean | Test or live mode. | | `status` | enum | `pending` (prepared, transfer not yet made), `paid` or `canceled`. | | `currency` | string | Three-letter ISO 4217 code, such as `SGD`, `THB` or `MMK`. | | `gross_amount` | integer | Sum of the payments in the payout. | | `refund_amount` | integer | Refunds deducted. | | `provider_fee` | integer | The bank's fees. | | `klink_fee` | integer | K-LINK Pay's fees. | | `net_amount` | integer | What is transferred to you. | | `fee_bps` | integer | Your K-LINK Pay rate in basis points, as agreed for your account. | | `bank` | object | `{ name, account_name, account_number_last4, branch }` of the account paid to. | | `transfer_reference` | string \| null | The bank transfer reference, once paid. | | `created_at` | timestamp | When the payout was prepared. | | `paid_at` | timestamp \| null | When the transfer was made. | ```json title="A paid payout" { "id": "po_6Yz8Ab0Cd2Ef4Gh6Ij8Kl0", "object": "payout", "livemode": true, "status": "paid", "currency": "MMK", "gross_amount": 152000, "refund_amount": 5000, "provider_fee": 760, "klink_fee": 1520, "net_amount": 144720, "fee_bps": 100, "bank": { "name": "Example Bank", "account_name": "Shwe Tea House", "account_number_last4": "4821", "branch": "Yangon Main" }, "transfer_reference": "TRX-20261128-0042", "created_at": "2026-11-28T03:30:00Z", "paid_at": "2026-11-28T07:12:00Z" } ``` ## Retrieve a payout ```http GET /v1/payouts/:id ``` Requires `payouts:read` on restricted keys. ```bash title="Request" curl https://api.klinkpay.net/v1/payouts/po_6Yz8Ab0Cd2Ef4Gh6Ij8Kl0 \ -H "Authorization: Bearer kp_test_…" ``` ## List payouts ```http GET /v1/payouts ``` Newest first. Takes `limit`, `starting_after` and `ending_before`; see [Pagination](/concepts/pagination.md). ```bash title="Request" curl https://api.klinkpay.net/v1/payouts \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "object": "list", "data": [ { "id": "po_6Yz8Ab0Cd2Ef4Gh6Ij8Kl0", "object": "payout", "livemode": true, "status": "paid", "currency": "MMK", "gross_amount": 152000, "refund_amount": 5000, "provider_fee": 760, "klink_fee": 1520, "net_amount": 144720, "fee_bps": 100, "bank": { "name": "Example Bank", "account_name": "Shwe Tea House", "account_number_last4": "4821", "branch": "Yangon Main" }, "transfer_reference": "TRX-20261128-0042", "created_at": "2026-11-28T03:30:00Z", "paid_at": "2026-11-28T07:12:00Z" } ], "has_more": false } ``` --- # Payment links A shareable page where customers pay a fixed amount, without any code on your side. Share the link's `url` in a chat, an email or as a QR on an invoice. Each time a customer presses Pay, a new [payment](/api/payments.md) is created with `payment_link` set to the link's id, and you get the usual `payment.succeeded` webhook. You can also create links in the dashboard. ## The payment link object | Field | Type | Description | |---|---|---| | `id` | string | Starts with `plink_`. | | `object` | string | Always `payment_link`. | | `livemode` | boolean | Test or live mode. | | `active` | boolean | Inactive links can't be paid. | | `url` | string | The page to share. | | `amount` | integer | Fixed amount in the smallest currency unit. | | `currency` | string | Three-letter ISO 4217 code, such as `SGD`, `THB` or `MMK`. | | `description` | string | What the customer pays for; shown on the page. | | `single_use` | boolean | If true, the link stops working after one successful payment. | | `payments_count` | integer | Payments made through the link. | | `metadata` | object | Your own key–value data. | | `created_at` | timestamp | When it was created. | ```json title="A payment link" { "id": "plink_3Mn5Op7Qr9St1Uv3Wx5Yz7", "object": "payment_link", "livemode": false, "active": true, "url": "https://checkout.klinkpay.net/l/plink_3Mn5Op7Qr9St1Uv3Wx5Yz7", "amount": 25000, "currency": "MMK", "description": "Monthly membership", "single_use": false, "payments_count": 0, "metadata": {}, "created_at": "2026-11-27T09:00:00Z" } ``` ## Create a payment link ```http POST /v1/payment_links ``` **Body** | Field | Type | Required | Description | |---|---|---|---| | `amount` | integer | yes | In the smallest currency unit. | | `description` | string | yes | Shown to the customer. | | `single_use` | boolean | no | Default `false`. | | `metadata` | object | no | Your own data. | ```bash title="Request" curl https://api.klinkpay.net/v1/payment_links \ -X POST \ -H "Authorization: Bearer kp_test_…" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "amount": 25000, "description": "Monthly membership" }' ``` ```json title="Response" { "id": "plink_3Mn5Op7Qr9St1Uv3Wx5Yz7", "object": "payment_link", "livemode": false, "active": true, "url": "https://checkout.klinkpay.net/l/plink_3Mn5Op7Qr9St1Uv3Wx5Yz7", "amount": 25000, "currency": "MMK", "description": "Monthly membership", "single_use": false, "payments_count": 0, "metadata": {}, "created_at": "2026-11-27T09:00:00Z" } ``` ## Retrieve a payment link ```http GET /v1/payment_links/:id ``` Requires `payment_links:read` on restricted keys. ```bash title="Request" curl https://api.klinkpay.net/v1/payment_links/plink_3Mn5Op7Qr9St1Uv3Wx5Yz7 \ -H "Authorization: Bearer kp_test_…" ``` ## List payment links ```http GET /v1/payment_links ``` Newest first, with the usual [pagination](/concepts/pagination.md). ```bash title="Request" curl https://api.klinkpay.net/v1/payment_links \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "object": "list", "data": [ { "id": "plink_3Mn5Op7Qr9St1Uv3Wx5Yz7", "object": "payment_link", "livemode": false, "active": true, "url": "https://checkout.klinkpay.net/l/plink_3Mn5Op7Qr9St1Uv3Wx5Yz7", "amount": 25000, "currency": "MMK", "description": "Monthly membership", "single_use": false, "payments_count": 0, "metadata": {}, "created_at": "2026-11-27T09:00:00Z" } ], "has_more": false } ``` ## Deactivate a payment link ```http POST /v1/payment_links/:id/deactivate ``` Stops the link from taking new payments. Returns the link with `active: false`. Payments already made are not affected. ```bash title="Request" curl https://api.klinkpay.net/v1/payment_links/plink_3Mn5Op7Qr9St1Uv3Wx5Yz7/deactivate \ -X POST \ -H "Authorization: Bearer kp_test_…" ``` --- # Webhook endpoints Manage the URLs that receive your webhooks from code. ## The webhook endpoint object | Field | Type | Description | |---|---|---| | `id` | string | Starts with `we_`. | | `object` | string | Always `webhook_endpoint`. | | `livemode` | boolean \| null | `true` live only, `false` test only, `null` both modes. | | `url` | string | HTTPS URL we POST events to. | | `enabled_events` | string[] | Event types to send. Empty means all. | | `status` | enum | `enabled` or `disabled`. | | `description` | string \| null | Your note. | | `created_at` | timestamp | When it was created. | | `secret` | string | Signing secret. **Only in the create response**; store it then. | ```json title="A webhook endpoint" { "id": "we_9Ab1Cd3Ef5Gh7Ij9Kl1Mn3", "object": "webhook_endpoint", "livemode": null, "url": "https://shop.example.com/webhooks/klink-pay", "enabled_events": [ "payment.succeeded", "payment.failed", "refund.succeeded" ], "status": "enabled", "description": "Order fulfilment", "created_at": "2026-11-27T09:00:00Z" } ``` ## Create a webhook endpoint ```http POST /v1/webhook_endpoints ``` **Body** | Field | Type | Required | Description | |---|---|---|---| | `url` | string | yes | HTTPS URL. | | `enabled_events` | string[] | no | Default: all events. | | `livemode` | boolean \| null | no | Which mode to listen to; `null` for both. | | `description` | string | no | Your note. | ```bash title="Request" curl https://api.klinkpay.net/v1/webhook_endpoints \ -X POST \ -H "Authorization: Bearer kp_test_…" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d '{ "url": "https://shop.example.com/webhooks/klink-pay", "enabled_events": [ "payment.succeeded", "payment.failed", "refund.succeeded" ], "description": "Order fulfilment" }' ``` ```json title="Response (secret shown once)" { "id": "we_9Ab1Cd3Ef5Gh7Ij9Kl1Mn3", "object": "webhook_endpoint", "livemode": null, "url": "https://shop.example.com/webhooks/klink-pay", "enabled_events": [ "payment.succeeded", "payment.failed", "refund.succeeded" ], "status": "enabled", "description": "Order fulfilment", "created_at": "2026-11-27T09:00:00Z", "secret": "whsec_…" } ``` > [!NOTE] > Requires `webhook_endpoints:write` on restricted keys. Rotating a secret, editing and the delivery log are in the dashboard. ## List webhook endpoints ```http GET /v1/webhook_endpoints ``` Requires `webhook_endpoints:read`. Secrets are never included. ```bash title="Request" curl https://api.klinkpay.net/v1/webhook_endpoints \ -H "Authorization: Bearer kp_test_…" ``` ```json title="Response" { "object": "list", "data": [ { "id": "we_9Ab1Cd3Ef5Gh7Ij9Kl1Mn3", "object": "webhook_endpoint", "livemode": null, "url": "https://shop.example.com/webhooks/klink-pay", "enabled_events": [ "payment.succeeded", "payment.failed", "refund.succeeded" ], "status": "enabled", "description": "Order fulfilment", "created_at": "2026-11-27T09:00:00Z" } ], "has_more": false } ``` ## Delete a webhook endpoint ```http DELETE /v1/webhook_endpoints/:id ``` Stops all deliveries to the endpoint. ```bash title="Request" curl https://api.klinkpay.net/v1/webhook_endpoints/we_9Ab1Cd3Ef5Gh7Ij9Kl1Mn3 \ -X DELETE \ -H "Authorization: Bearer kp_test_…" ```