Skip to Content
ePay.lkDocs
Payments

Create a payment

Create a payment on your server with POST /v1/payments, then send the payer to the hosted checkout.

A payment represents one amount you want to collect from one payer. You create it on your server, redirect the payer to its checkout_url, and ePay takes care of payment methods, 3-D Secure, retries after a decline, and notifying you.

POST/v1/paymentsscope payments:write

Request

curl https://beta.api.epay.lk/v1/payments \
  -H "Authorization: Bearer $EPAY_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042" \
  -d '{
    "amount": 125000,
    "currency": "LKR",
    "description": "Order #1042 — 2 items",
    "order_id": "1042",
    "customer": { "name": "Nimal Perera", "email": "nimal@example.com", "phone": "+94771234567" },
    "metadata": { "cart_id": "c_98431" },
    "return_url": "https://shop.example.lk/checkout/return",
    "cancel_url": "https://shop.example.lk/cart",
    "expires_in_minutes": 30
  }'

Parameters

ParameterTypeDescription
amountinteger, requiredAmount in minor units. 125000 = LKR 1,250.00. Must be a positive integer.
currencyLKR | USDDefaults to LKR.
descriptionstring ≤ 500Shown to the payer on the checkout page and in your dashboard.
order_idstring 1–100Your reference. Returned on the redirect and in webhooks; filterable with GET /v1/payments?order_id=.
customerobjectname (≤ 200), email (valid email), phone (≤ 30). Prefills the checkout and links the payment to a customer record.
metadataobjectUp to 20 string key/value pairs (keys ≤ 40 chars, values ≤ 500). Returned unchanged; never shown to the payer.
return_urlhttp(s) URL ≤ 2000Where the payer goes after the payment ends. ePay appends payment_id, status, order_id.
cancel_urlhttp(s) URL ≤ 2000Where the payer goes if they cancel on the checkout page.
expires_in_minutesinteger 5–1440How long the checkout stays payable. Default 60.

Always send an Idempotency-Key so a network retry can't create a second payment.

Response

Returns the Payment object with status requires_payment, plus checkout_url:

{
  "id": "pay_8Hq2LxV0cT4mZr7N",
  "object": "payment",
  "status": "requires_payment",
  "amount": 125000,
  "currency": "LKR",
  "amount_refunded": 0,
  "fee": 0,
  "net": 0,
  "description": "Order #1042 — 2 items",
  "order_id": "1042",
  "source": "api",
  "customer": { "id": "cus_3fD1aQ9wK2", "name": "Nimal Perera", "email": "nimal@example.com", "phone": "+94771234567" },
  "payment_method": null,
  "failure": null,
  "metadata": { "cart_id": "c_98431" },
  "return_url": "https://shop.example.lk/checkout/return",
  "cancel_url": "https://shop.example.lk/cart",
  "checkout_url": "https://beta.pay.epay.lk/c/cs_Q2h4bW9uZXlfaXNfbm90X3JlYWw",
  "payment_link_id": null,
  "invoice_id": null,
  "livemode": true,
  "created_at": "2026-11-22T10:15:00.000Z",
  "expires_at": "2026-11-22T10:45:00.000Z",
  "succeeded_at": null,
  "settled_at": null
}

checkout_url is returned once

checkout_url contains a single-use capability token and appears only in the create response (and in an idempotent replay of it). GET /v1/payments/:id doesn't include it. Redirect immediately, or store it with the order if you redirect later.

Amounts in minor units

Convert at the edge of your system and keep integers everywhere else:

Displayamount
LKR 1.00100
LKR 1,250.00125000
LKR 59,000.505900050

Avoid floating-point arithmetic for money: 19.99 * 100 is 1998.9999999999998 in JavaScript. Use Math.round(value * 100) or, better, store cents as integers in your database.

Next

On this page