Appearance
Create a checkout
Opens a hosted checkout for a fixed amount and answers the address to send the payer to. The payment goes to the account that owns the key, into its main wallet, or, for a platform, to one of its seller accounts.
Creating a checkout charges nobody and sends no prompt. The payer chooses how to pay on the hosted page. There is no list or cancel route for checkouts. A paid checkout is refunded with Create a refund.
Endpoint
POST /v1/payments/merchant/checkouts| Auth | Secret key, Authorization: Bearer mkp_…. See API keys and scopes |
| Scope | checkouts. With on_behalf_of, also payments:write, and the key must belong to an active platform. platform_fee without on_behalf_of is 400 1701, before any scope check |
| Host | The payments host for the key's country. See Environments |
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_test_… or Bearer mkp_live_… |
Idempotency-Key | Yes | 1 to 128 characters. The same key and body answer the checkout the key first made, with 200. The same key with a different body answers 422 and code 3015. The new body must first pass the field, line_items, return_url, platform, amount and wallet checks. See Idempotency |
Content-Type | Yes | application/json |
Parameters
Body
Unknown fields are refused with 400 and code 1701. There is no currency field: Kenya is KES, Uganda is UGX, set by the host.
| Name | Type | Required | Constraints and meaning |
|---|---|---|---|
amount | integer | Yes | Minor units (150000 is 1,500.00). At least 1, and inside the mobile-money rail's collection limits: KES 1.00 to 150,000.00 on M-Pesa, UGX 1 to 5,000,000 in whole units on MTN MoMo. With on_behalf_of it must be a multiple of 100 |
reference | string | No | Your own order number, 1 to 64 characters. The payer sees it on the checkout page under the amount. It is added to return_url as reference once paid |
description | string | No | 1 to 140 characters. Shown to the payer |
return_url | string | No | 1 to 2048 characters. Where the payer's browser goes after the payment settles. Must be https. Off production, http://localhost and http://127.0.0.1 are also accepted |
phone | string | No | 9 to 15 digits, country code included, no + (254712345678). Fills the phone field on the hosted page. It does not send a prompt |
line_items | array | No | 1 to 50 items. Each is { description, amount, quantity? }: description 1 to 140 characters, amount an integer of at least 1 in minor units, quantity 1 to 999 (default 1). The sum of amount × quantity must equal amount, or the call is refused with 1701 and the description line_items must sum to amount |
on_behalf_of | string | No | Platforms only. One of your account ids, acct_<country>_<24 hex>. That seller is paid and is the payee the payer sees, "via" your platform. See Take payments with a fee |
platform_fee | integer | No | Platforms only, with on_behalf_of. Your fee in minor units, 0 to 100000000000. It must be a multiple of 100, at most your platform's maximum share of amount, and leave the seller at least 100. It is credited to your own main wallet when the payment is booked |
A checkout made with on_behalf_of cannot be paid from a MOOKHPay balance.
Example request
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",
"return_url": "https://shop.example.com/paid",
"line_items": [
{ "description": "Latte", "amount": 60000, "quantity": 2 },
{ "description": "Mandazi", "amount": 30000 }
]
}'js
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const res = await fetch(`${BASE}/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",
return_url: "https://shop.example.com/paid",
line_items: [
{ description: "Latte", amount: 60000, quantity: 2 },
{ description: "Mandazi", amount: 30000 },
],
}),
});
const body = await res.json();
if (!body.ok) throw new Error(`${res.status} ${body.code}: ${body.description}`);
console.log(body.data.url);python
import os
import requests
BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
res = requests.post(
f"{BASE}/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",
"return_url": "https://shop.example.com/paid",
"line_items": [
{"description": "Latte", "amount": 60000, "quantity": 2},
{"description": "Mandazi", "amount": 30000},
],
},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
print(body["data"]["url"])php
<?php
$base = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
$ch = curl_init("$base/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",
"return_url" => "https://shop.example.com/paid",
"line_items" => [
["description" => "Latte", "amount" => 60000, "quantity" => 2],
["description" => "Mandazi", "amount" => 30000],
],
]),
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if (!$body["ok"]) {
throw new RuntimeException("$status {$body['code']}: {$body['description']}");
}
echo $body["data"]["url"], PHP_EOL;Response
201 Created for a new checkout. 200 OK when the Idempotency-Key already made a checkout from the same body: description is then Duplicate request — returning existing checkout, and data is that checkout as it is now, including its payment. The same key with a different body answers 422 and code 3015 instead. A checkout made before November 2026's change has no stored body, so its key answers 200 whatever the body; see Idempotency.
json
{
"ok": true,
"description": "Checkout created",
"data": {
"id": "cs_ke_3f9a1c7e5b2d4a8e6c0b91d7",
"url": "https://mookhpay.co/checkout/cs_ke_3f9a1c7e5b2d4a8e6c0b91d7",
"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-20T09:30:00.000Z",
"created_at": "2026-11-20T09:00:00.000Z",
"payment": null
}
}A checkout made with on_behalf_of adds three fields:
json
"account": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee": 15000,
"net": 135000Response fields
data is the checkout object. The fields that matter on create:
| Field | Type | Meaning |
|---|---|---|
id | string | cs_<country>_<24 hex>. Store it against your order |
url | string | The hosted page. Redirect the payer's browser here |
status | string | open on create |
amount | string | Minor units, as a string |
expires_at | string | ISO 8601. 30 minutes after creation by default |
account, platform_fee, net | string, integer, integer | Only on a checkout made with on_behalf_of. net is amount less platform_fee |
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | The body is not valid JSON, a field breaks its constraint, an unknown field is sent, Idempotency-Key is missing, line_items do not sum to amount, return_url is not an https URL, or platform_fee is sent without on_behalf_of | Fix the request. The description names the problem only for the handler checks (line items, return_url, platform_fee) |
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header such as X-User-ID or X-Acting-As | Remove the header. The payee is always the key's owner |
400 | 3017 | PLATFORM_FEE_INVALID | With on_behalf_of: amount or platform_fee is not a multiple of 100, the fee is over your maximum share, or it leaves the seller less than 100 | Correct the amount or fee. The description says which rule failed |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks checkouts, or sends on_behalf_of without payments:write | Issue a key with the scope |
403 | 3042 | API_KEY_IP_NOT_ALLOWED | The account has allowed addresses and the call came from another address | Call from a listed address |
403 | 2942 | PLATFORM_NOT_ENABLED | on_behalf_of from an organisation that is not an active platform | Ask MOOKHPay to switch your platform on |
403 | 3013 | PLATFORM_IP_NOT_ALLOWED | on_behalf_of from an address not on your platform's allow-list | Call from a listed address |
404 | 2943 | PLATFORM_ACCOUNT_NOT_FOUND | on_behalf_of names an account that is unknown, another platform's, revoked or malformed | Check the id. Each miss counts toward the limit below |
409 | 2709 | WALLET_NOT_PROVISIONED | The payee's main wallet does not exist yet, usually just after an account was created | Retry after a few seconds |
409 | 3018 | PLATFORM_FEE_WALLET_MISSING | platform_fee above 0 and your platform's own main wallet does not exist | Contact MOOKHPay |
422 | 2702 | INVALID_AMOUNT | amount is outside the rail's collection limits, or not whole units on MoMo | Use an amount inside the limits |
422 | 2721 | COLLECTION_DISABLED | The deployment has no mobile-money rail taking payments | Retry later |
422 | 3015 | IDEMPOTENCY_KEY_REUSED | The Idempotency-Key already made a checkout from a different body, such as another amount or on_behalf_of. Also answered when the stored checkout for this key was made the other way (for yourself, or by a platform for a seller), which does not happen in normal use | Use a new key for the new body, or resend the first body |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over the rate limit, or over 100 unknown account ids in an hour | Wait Retry-After seconds |
503 | 2782 | AUTHN_UNAVAILABLE | Keys cannot be checked | Retry with backoff and the same Idempotency-Key |
503 | 2752 | LEDGER_UNAVAILABLE | The wallet check did not answer | Retry with backoff and the same Idempotency-Key |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | With on_behalf_of: the account could not be read | Retry with backoff |
A request with a bad key and a bad field gets 401: the key is checked before the fields. Only a body that is not valid JSON is refused before the key. See Errors.
Rate limit
120 requests a minute per key owner, one bucket shared with Retrieve a checkout, Retrieve a charge, List charges for a reference and Cancel a charge. Over it: 429, code 1804, with Retry-After and data.retryAfter in seconds.
With on_behalf_of, every unknown account id counts toward a second limit: after 100 in an hour, every account lookup answers 429 and code 1804 until the hour is up. See Limits and rate limits.