Skip to content

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
AuthSecret key, Authorization: Bearer mkp_…. See API keys and scopes
Scopecheckouts. 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
HostThe payments host for the key's country. See Environments

Headers ​

HeaderRequiredValue
AuthorizationYesBearer mkp_test_… or Bearer mkp_live_…
Idempotency-KeyYes1 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-TypeYesapplication/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.

NameTypeRequiredConstraints and meaning
amountintegerYesMinor 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
referencestringNoYour 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
descriptionstringNo1 to 140 characters. Shown to the payer
return_urlstringNo1 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
phonestringNo9 to 15 digits, country code included, no + (254712345678). Fills the phone field on the hosted page. It does not send a prompt
line_itemsarrayNo1 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_ofstringNoPlatforms 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_feeintegerNoPlatforms 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": 135000

Response fields ​

data is the checkout object. The fields that matter on create:

FieldTypeMeaning
idstringcs_<country>_<24 hex>. Store it against your order
urlstringThe hosted page. Redirect the payer's browser here
statusstringopen on create
amountstringMinor units, as a string
expires_atstringISO 8601. 30 minutes after creation by default
account, platform_fee, netstring, integer, integerOnly on a checkout made with on_behalf_of. net is amount less platform_fee

Errors ​

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAThe 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_ofFix the request. The description names the problem only for the handler checks (line items, return_url, platform_fee)
4003014IDENTITY_HEADER_REFUSEDThe request carries a session or identity header such as X-User-ID or X-Acting-AsRemove the header. The payee is always the key's owner
4003017PLATFORM_FEE_INVALIDWith 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 100Correct the amount or fee. The description says which rule failed
4012781API_KEY_INVALIDMissing, malformed, unknown or revoked keyCheck the key
4032941API_KEY_SCOPE_REQUIREDThe key lacks checkouts, or sends on_behalf_of without payments:writeIssue a key with the scope
4033042API_KEY_IP_NOT_ALLOWEDThe account has allowed addresses and the call came from another addressCall from a listed address
4032942PLATFORM_NOT_ENABLEDon_behalf_of from an organisation that is not an active platformAsk MOOKHPay to switch your platform on
4033013PLATFORM_IP_NOT_ALLOWEDon_behalf_of from an address not on your platform's allow-listCall from a listed address
4042943PLATFORM_ACCOUNT_NOT_FOUNDon_behalf_of names an account that is unknown, another platform's, revoked or malformedCheck the id. Each miss counts toward the limit below
4092709WALLET_NOT_PROVISIONEDThe payee's main wallet does not exist yet, usually just after an account was createdRetry after a few seconds
4093018PLATFORM_FEE_WALLET_MISSINGplatform_fee above 0 and your platform's own main wallet does not existContact MOOKHPay
4222702INVALID_AMOUNTamount is outside the rail's collection limits, or not whole units on MoMoUse an amount inside the limits
4222721COLLECTION_DISABLEDThe deployment has no mobile-money rail taking paymentsRetry later
4223015IDEMPOTENCY_KEY_REUSEDThe 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 useUse a new key for the new body, or resend the first body
4291804RATE_LIMIT_EXCEEDEDOver the rate limit, or over 100 unknown account ids in an hourWait Retry-After seconds
5032782AUTHN_UNAVAILABLEKeys cannot be checkedRetry with backoff and the same Idempotency-Key
5032752LEDGER_UNAVAILABLEThe wallet check did not answerRetry with backoff and the same Idempotency-Key
5033016PLATFORM_ACCOUNTS_UNAVAILABLEWith on_behalf_of: the account could not be readRetry 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.

Staging documentation. A checkout made with a secret key on staging charges a real phone. See Environments.