# 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
<?php
$ch = curl_init("https://api.klinkpay.net/v1/payments");
curl_setopt_array($ch, [
    CURLOPT_POST => 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
}
```
