Appearance
Hosted checkout
A hosted checkout is one order with a fixed amount. Your server creates it, sends the payer to MOOKHPay's page, and reads it back before fulfilling. The page asks for the payer's number or card. Your server never sees either.
The money goes to the account that owns the key, into its main wallet. A checkout can be paid once. It cannot be edited or cancelled after it is created. A paid checkout can be refunded in full or in part, after MOOKHPay reviews the refund.
Use a direct charge when the payer must stay on your own screen. Use a payment link when you want a standing page with no server.
Before you start
You need a secret key with the checkouts scope. A key made with no choice of scopes has it. See API keys and scopes.
Create a checkout
Call POST /checkouts with an Idempotency-Key. The amount is in minor units: 150000 is KES 1,500.00.
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/checkouts \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: order-1042" \
-H "Content-Type: application/json" \
-d '{
"amount": 150000,
"reference": "order-1042",
"description": "2 lattes and a mandazi",
"line_items": [
{ "description": "Latte", "amount": 60000, "quantity": 2 },
{ "description": "Mandazi", "amount": 30000 }
],
"return_url": "https://shop.example.com/paid",
"phone": "254712345678"
}'js
const API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const res = await fetch(`${API}/checkouts`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": "order-1042",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 150000,
reference: "order-1042",
description: "2 lattes and a mandazi",
line_items: [
{ description: "Latte", amount: 60000, quantity: 2 },
{ description: "Mandazi", amount: 30000 },
],
return_url: "https://shop.example.com/paid",
phone: "254712345678",
}),
});
const body = await res.json();
if (!body.ok) throw new Error(`${body.code}: ${body.description}`);
console.log(body.data.id, body.data.url);python
import os
import requests
API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
res = requests.post(
f"{API}/checkouts",
headers={
"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}",
"Idempotency-Key": "order-1042",
},
json={
"amount": 150000,
"reference": "order-1042",
"description": "2 lattes and a mandazi",
"line_items": [
{"description": "Latte", "amount": 60000, "quantity": 2},
{"description": "Mandazi", "amount": 30000},
],
"return_url": "https://shop.example.com/paid",
"phone": "254712345678",
},
timeout=15,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{body['code']}: {body['description']}")
print(body["data"]["id"], body["data"]["url"])php
<?php
$api = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
$ch = curl_init("$api/checkouts");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY"),
"Idempotency-Key: order-1042",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"amount" => 150000,
"reference" => "order-1042",
"description" => "2 lattes and a mandazi",
"line_items" => [
["description" => "Latte", "amount" => 60000, "quantity" => 2],
["description" => "Mandazi", "amount" => 30000],
],
"return_url" => "https://shop.example.com/paid",
"phone" => "254712345678",
]),
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body["ok"]) {
throw new RuntimeException($body["code"] . ": " . $body["description"]);
}
echo $body["data"]["id"], " ", $body["data"]["url"], "\n";The answer is 201 with the checkout:
json
{
"ok": true,
"description": "Checkout created",
"data": {
"id": "cs_ke_4f1c9a0b7d2e6f3a8b5c1d09",
"url": "https://mookhpay.co/checkout/cs_ke_4f1c9a0b7d2e6f3a8b5c1d09",
"status": "open",
"test": false,
"amount": "150000",
"currency": "KES",
"reference": "order-1042",
"description": "2 lattes and a mandazi",
"line_items": [
{ "description": "Latte", "amount": "60000", "quantity": 2 },
{ "description": "Mandazi", "amount": "30000", "quantity": 1 }
],
"return_url": "https://shop.example.com/paid",
"expires_at": "2026-11-20T10:30:00.000Z",
"created_at": "2026-11-20T10:00:00.000Z",
"payment": null
}
}amount and each line's amount come back as strings. Store id against your order, then redirect the payer to url. Read url from the answer rather than building it: its host differs between deployments.
What you can send
Unknown fields are refused with 400 and code 1701. There is no currency field: the deployment sets it, KES in Kenya and UGX in Uganda.
| Field | Type | Required | Rules |
|---|---|---|---|
amount | integer | Yes | Minor units, at least 1, inside the rail's collection limits: KES 1 to KES 150,000 on M-Pesa, UGX 1 to UGX 5,000,000 in whole shillings on MTN MoMo. Outside them: 422 and code 2702 |
reference | string | No | Your order id, 1 to 64 characters. The payer sees it on the page under the amount. It comes back on every read, on webhooks and on the redirect |
description | string | No | 1 to 140 characters, shown to the payer |
line_items | array | No | 1 to 50 lines. See Line items |
return_url | string | No | Where the payer goes once the checkout is paid. See Return URL |
phone | string | No | Fills in the payer's number on the page. 9 to 15 digits with the country code and no +, such as 254712345678. The payer can change it. It is not checked against the rail until a prompt is sent |
on_behalf_of, platform_fee | No | Platforms only. See Take payments with a fee |
Line items
Each line is shown on the page. A line's description is 1 to 140 characters, its amount is the unit price in minor units (at least 1), and quantity is 1 to 999, 1 when left out. Lines take no other fields.
The lines must add up to amount: the sum of amount × quantity over every line. When they do not, the call answers 400 and code 1701 with the description line_items must sum to amount.
Return URL
return_url is 1 to 2048 characters and must be https. Off production, http://localhost and http://127.0.0.1 are also accepted, so you can build against staging from your machine. Any other address answers 400 and code 1701 with the description return_url must be https or return_url is not a URL.
MOOKHPay never fetches the address. It is only handed to the payer's browser.
Status and expiry
status | Meaning |
|---|---|
open | It can be paid, or a payment attempt is in flight |
completed | The money landed. payment holds the receipt |
expired | expires_at has passed and no attempt is in flight |
There is no failed or cancelled status. A declined prompt leaves the checkout open, and the payer can try again until it expires. payment.status tells you how the last attempt went.
status is worked out on every read from the latest attempt and the clock, so your GET and the payer's page always agree.
- A checkout lives 30 minutes by default (
CHECKOUT_TTL_SECONDS, 1800 seconds). Readexpires_atfrom the answer instead of assuming it. - An attempt still in flight at
expires_atkeeps the checkoutopenuntil the rail answers, and it can still complete. - On Kenya, an exact Pay Bill payment can complete a checkout after
expires_at. See M-Pesa menu.
Fulfil only when status is completed, read with your own key. See Confirming payments.
The payment object
payment is null until somebody tries to pay. After that it is the latest attempt, and a new attempt replaces it.
| Field | Type | Meaning |
|---|---|---|
intent_id | string | The attempt's id, pi_… |
status | string | created, reserved, submitted, pending, completed, failed, expired or reversed |
amount_settled | string or null | Minor units received. null until it settles |
provider_receipt | string or null | The M-Pesa or MoMo receipt, the CyberSource transaction id for a card, or MOOKHPay's own reference for a balance payment. null until it settles |
reference | string or null | MOOKHPay's receipt reference (SM…), once the payment is booked |
phone | string or null | The payer's number in full. Only your read carries it, never the payer's page |
Read a checkout
GET /checkouts/{id} answers the checkout as it is now. Only the account that owns the key, or the platform that made it for a seller, can read it. Any other id answers 404 and code 2783, the same as an unknown one.
sh
curl https://payments-ke-staging.mookhpay.co/v1/payments/merchant/checkouts/cs_ke_4f1c9a0b7d2e6f3a8b5c1d09 \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY"js
const API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const id = "cs_ke_4f1c9a0b7d2e6f3a8b5c1d09";
const res = await fetch(`${API}/checkouts/${id}`, {
headers: { Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}` },
});
const body = await res.json();
if (!body.ok) throw new Error(`${body.code}: ${body.description}`);
console.log(body.data.status, body.data.payment);python
import os
import requests
API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
checkout_id = "cs_ke_4f1c9a0b7d2e6f3a8b5c1d09"
res = requests.get(
f"{API}/checkouts/{checkout_id}",
headers={"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}"},
timeout=15,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{body['code']}: {body['description']}")
print(body["data"]["status"], body["data"]["payment"])php
<?php
$api = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
$id = "cs_ke_4f1c9a0b7d2e6f3a8b5c1d09";
$ch = curl_init("$api/checkouts/$id");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY")],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body["ok"]) {
throw new RuntimeException($body["code"] . ": " . $body["description"]);
}
echo $body["data"]["status"], "\n";A completed checkout reads like this:
json
{
"ok": true,
"description": "Checkout",
"data": {
"id": "cs_ke_4f1c9a0b7d2e6f3a8b5c1d09",
"url": "https://mookhpay.co/checkout/cs_ke_4f1c9a0b7d2e6f3a8b5c1d09",
"status": "completed",
"test": false,
"amount": "150000",
"currency": "KES",
"reference": "order-1042",
"description": "2 lattes and a mandazi",
"line_items": [
{ "description": "Latte", "amount": "60000", "quantity": 2 },
{ "description": "Mandazi", "amount": "30000", "quantity": 1 }
],
"return_url": "https://shop.example.com/paid",
"expires_at": "2026-11-20T10:30:00.000Z",
"created_at": "2026-11-20T10:00:00.000Z",
"payment": {
"intent_id": "pi_7c2d9e4f1a0b3c5d6e8f9a1b",
"status": "completed",
"amount_settled": "150000",
"provider_receipt": "TKJ3H8X2QP",
"reference": "SM4K7Q2P9X",
"phone": "254712345678"
}
}
}Retries and the idempotency key
Every create needs an Idempotency-Key of 1 to 128 characters. A second create with the same key and the same body answers 200 with the checkout the key first made, as it stands now.
The body of a repeated create is compared with the first one. A different body under the same key, such as a changed amount, answers 422 and code 3015 and changes nothing; it does not return the first checkout. The same is true of direct charges. Use one key per order, and a new key when the order's amount changes. A checkout made before this changed in November 2026 has no stored body, so its key still answers the first checkout with 200. See Idempotency.
One payment attempt at a time
The page sends one prompt at a time. While an attempt is in flight, asking again does not send a second prompt: the page is answered with the attempt already running.
| The page asks to pay | Answer |
|---|---|
| While a mobile-money prompt is in flight | The current attempt, 200. No new prompt |
| A checkout already paid | 409, code 2785 |
| An expired checkout | 409, code 2784 |
| By mobile money while a card payment is in flight | 409, code 2786 |
These are the payer page's calls. Your server never makes them. See Public routes.
What the payer sees
The page at url shows your name, the amount, description, reference under the amount, and the line items. It never shows a previous payer's number. The id carries the country (cs_ke_…, cs_ug_…), and the page calls that country's host. The payer does not sign in.
The page offers each way to pay that the deployment has switched on for this checkout:
| Way to pay | When it is offered | What the payer pays |
|---|---|---|
| Mobile money prompt | Always: M-Pesa in Kenya, MTN MoMo in Uganda | The amount |
| M-Pesa menu (Pay Bill) | Kenya, where Pay Bill is switched on | The amount |
| Card | Where the card rail is on for the checkout's currency | The amount plus a card fee. You receive the amount in full |
| MOOKHPay balance | A payer who signs in to MOOKHPay on the page. Not offered on a checkout a platform made for a seller | The amount |
If you sent phone at create, the number is filled in. The payer can change it.
M-Pesa menu (Kenya)
When Pay Bill is on, the page shows a Pay Bill number and an account number made for this checkout: CS and eight digits. The payer can pay from the M-Pesa menu instead of waiting for a prompt.
| The payer pays | Result |
|---|---|
| Exactly the checkout amount | The checkout becomes completed, even after expires_at |
| Any other amount | The money still goes to your main wallet as an ordinary payment. The checkout stays open or expired, and you reconcile it yourself |
| The exact amount on a checkout already paid | The money goes to your main wallet. The checkout is not paid twice |
M-Pesa completes a menu payment before MOOKHPay is asked, so a wrong amount cannot be refused. Your checkout read does not include the Pay Bill numbers; only the payer's page shows them.
After payment
When the checkout is completed and you set return_url, the page shows the paid state for 3 seconds and then opens return_url with three query parameters added:
| Parameter | Value |
|---|---|
checkout | The checkout id |
reference | Your reference, when you set one |
status | completed |
Parameters already on return_url are kept. checkout, reference and status replace any existing parameters of those names.
The redirect happens only after completion. An expired checkout links back to your return_url without these parameters. Anybody can type the redirect address, so never fulfil from the query string: read the checkout with your key.
Refusals when you create
| HTTP | Code | When |
|---|---|---|
400 | 1701 | A field breaks its rules, a field is unknown, Idempotency-Key is missing, or line_items does not add up |
401 | 2781 | The key is missing, malformed, unknown or revoked |
403 | 2941 | The key does not have checkouts |
409 | 2709 | The account's wallet is not set up yet. Try again in a moment |
422 | 2702 | amount is outside the rail's limits |
422 | 2721 | Payments are switched off on this deployment |
429 | 1804 | Over 120 requests a minute for your account. Wait Retry-After seconds |
503 | 2752, 2782 | The ledger or the key service did not answer. Retry with the same Idempotency-Key |
The full list, including the platform codes, is on Create a checkout and Errors.
For platforms
A platform adds on_behalf_of and platform_fee to take a payment for one of its sellers. The seller is the payee, the page names the seller "via" your platform, and the checkout cannot be paid from a MOOKHPay balance. See Take payments with a fee.
Not offered
- Listing checkouts. Store each
idwhen you create it. - Changing or cancelling a checkout. Let it expire and create another.
- Test checkouts from a secret key. Every checkout made with a secret key is real, on staging too. Test checkouts come only from a Pay Button test key. See Testing.