Appearance
Create a charge
Takes a payment with no redirect. For mobile_money it sends the prompt to the payer's phone during the call. For paybill it answers the Pay Bill number and account number to show the payer. For card it answers a client_secret for the card element on your page.
The call does not wait for the payer. A 201 means the charge exists and is pending, not that it is paid. Learn the outcome from webhooks or by polling Retrieve a charge.
Endpoint
POST /v1/payments/merchant/charges| Auth | Secret key, Authorization: Bearer mkp_…, checked with no cache on every call |
| Scope | charges:write. 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 |
| Feature flag | Registered only where the deployment has direct charges on (DIRECT_CHARGES_ENABLED). card also needs DIRECT_CHARGE_CARDS_ENABLED and the card rail. Where charges are off the route answers 404 |
| Test mode | A charge made with an mkp_test_ key (every staging key) is a test charge: only the test numbers pay it, nothing is booked, and card and paybill are refused |
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 same charge (200). The same key with a different body is 422 and code 3015. See Idempotency |
Content-Type | Yes | application/json |
Parameters
Body
Unknown fields are refused with 400 and code 1701, at the top level and inside payment_method.
| Name | Type | Required | Constraints and meaning |
|---|---|---|---|
amount | integer | Yes | Minor units, 1 to 100000000000, and inside the rail's 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, a multiple of 100 |
reference | string | Yes | Your own order id, 1 to 64 characters. One pending charge per reference at a time; after it ends, a new one is allowed |
description | string | No | 1 to 140 characters |
payment_method | object | Yes | One of the three shapes below |
payer_email | string | No | At most 254 characters, a valid address. mobile_money and card only: the payer's receipt email, and on a card charge also the card's billing email. Sent with paybill it is refused with 1701 |
metadata | object | No | Up to 20 string pairs. Keys 1 to 40 characters, values strings of at most 500. Returned on the charge and in its webhooks |
on_behalf_of | string | No | Platforms only. One of your account ids. The seller is the payee and the prompt names them |
platform_fee | integer | No | Platforms only, with on_behalf_of. Minor units, a multiple of 100, at most your platform's maximum share of amount, leaving the seller at least 100 |
payment_method
| Shape | Fields | Meaning |
|---|---|---|
{ "type": "mobile_money", "phone": "…", "rail": "…" } | phone: required, the payer's number with its country code, + optional, 9 to 15 digits; it must then be a number the rail can prompt (254 and 9 digits for M-Pesa, 256 and 9 digits for MoMo). rail: optional, mpesa or momo, and if sent it must be the rail this deployment collects on | Sends a prompt to the phone now. The charge expires 6 minutes later by default (the prompt's 5 minutes and 1 minute of grace) |
{ "type": "paybill" } | none | Kenya only, where M-Pesa Pay Bill (C2B) is on. Answers a business number and an account number. The charge expires 30 minutes later by default |
{ "type": "card" } | none | Answers a client_secret for the card element. Refused on an mkp_test_ key and wherever cards are off. The charge expires 30 minutes later by default |
Example request
A mobile-money charge:
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/charges \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: order-8841-attempt-1" \
-H "Content-Type: application/json" \
-d '{
"amount": 150000,
"reference": "order-8841",
"description": "A3 print",
"payment_method": { "type": "mobile_money", "phone": "+254700000000" },
"payer_email": "[email protected]",
"metadata": { "till": "4" }
}'js
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const res = await fetch(`${BASE}/charges`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": "order-8841-attempt-1",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 150000,
reference: "order-8841",
description: "A3 print",
payment_method: { type: "mobile_money", phone: "+254700000000" },
payer_email: "[email protected]",
metadata: { till: "4" },
}),
});
const body = await res.json();
if (res.status === 409 && body.code === 3002) {
console.log("Still pending:", body.data.charge);
} else if (!body.ok) {
throw new Error(`${res.status} ${body.code}: ${body.description}`);
} else {
console.log(body.data.id, body.data.next_action.display);
}python
import os
import requests
BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
res = requests.post(
f"{BASE}/charges",
headers={
"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}",
"Idempotency-Key": "order-8841-attempt-1",
},
json={
"amount": 150000,
"reference": "order-8841",
"description": "A3 print",
"payment_method": {"type": "mobile_money", "phone": "+254700000000"},
"payer_email": "[email protected]",
"metadata": {"till": "4"},
},
timeout=30,
)
body = res.json()
if res.status_code == 409 and body["code"] == 3002:
print("Still pending:", body["data"]["charge"])
elif not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
else:
print(body["data"]["id"], body["data"]["next_action"]["display"])php
<?php
$base = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
$ch = curl_init("$base/charges");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY"),
"Idempotency-Key: order-8841-attempt-1",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"amount" => 150000,
"reference" => "order-8841",
"description" => "A3 print",
"payment_method" => ["type" => "mobile_money", "phone" => "+254700000000"],
"payer_email" => "[email protected]",
"metadata" => ["till" => "4"],
]),
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status === 409 && $body["code"] === 3002) {
echo "Still pending: ", $body["data"]["charge"], PHP_EOL;
} elseif (!$body["ok"]) {
throw new RuntimeException("$status {$body['code']}: {$body['description']}");
} else {
echo $body["data"]["id"], " ", $body["data"]["next_action"]["display"], PHP_EOL;
}The samples use the test number +254700000000, because every staging key is mkp_test_ and a real number on a test key is refused with 409 and code 2836. On production, send the payer's own number.
Response
201 Created. 200 OK when the same Idempotency-Key and body already made a charge: description is then Duplicate request — returning existing charge, and data is the charge as it is now. A repeat of a pending card charge answers a new client_secret, and the earlier one stops working.
json
{
"ok": true,
"description": "Charge created",
"data": {
"id": "ch_ke_7e1a4c9b2d5f80e3a6c1b047",
"status": "pending",
"test": true,
"amount": 150000,
"currency": "KES",
"fee": 0,
"net": 150000,
"reference": "order-8841",
"description": "A3 print",
"payment_method": { "type": "mobile_money", "rail": "mpesa", "phone": "+254 7•• ••• 000" },
"next_action": {
"type": "await_payer",
"expires_at": "2026-11-20T09:20:00.000Z",
"display": "Enter your M-Pesa PIN on your phone"
},
"failure": null,
"receipt_number": null,
"hosted_url": "https://mookhpay.co/checkout/cs_ke_0b4d2f7a9c1e53b8d6a2e410",
"metadata": { "till": "4" },
"expires_at": "2026-11-20T09:20:00.000Z",
"created_at": "2026-11-20T09:14:00.000Z"
}
}A paybill charge's next_action:
json
{
"type": "pay_to_paybill",
"business_number": "4123456",
"account_number": "CS48213077",
"amount": 150000,
"expires_at": "2026-11-20T09:44:00.000Z"
}A card charge's next_action. client_secret is in this answer and its idempotent repeat only, never in a read:
json
{
"type": "use_card_element",
"client_secret": "ch_ke_7e1a4c9b2d5f80e3a6c1b047_secret_Qm9xV2t1c2Fzd2VldGhlYXJ0aGlzcm91bmRhbmRibHV",
"expires_at": "2026-11-20T09:44:00.000Z",
"amount": 150000,
"fee": 2500,
"total": 152500,
"currency": "KES"
}Response fields
data is the charge object. On create:
| Field | Type | Meaning |
|---|---|---|
id | string | ch_<country>_<24 hex>. Store it with your order |
status | string | pending |
next_action | object | What the payer has to do: await_payer, pay_to_paybill or use_card_element |
next_action.client_secret | string | Card only. <charge id>_secret_<43 characters>. Hand it to your checkout page and nothing else. It works only for this charge, until expires_at or until the charge leaves pending, whichever is first |
next_action.fee, next_action.total | integer | Card only. The card fee the payer adds and what their card is charged, in minor units. You receive amount |
account, platform_fee | string, integer | Only with on_behalf_of. net is then amount less platform_fee |
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | Body not valid JSON, a field breaks its constraint, an unknown field, a missing Idempotency-Key, bad metadata, a phone the rail cannot prompt, a bad payer_email, payer_email with paybill, or platform_fee without on_behalf_of | Fix the request. The handler checks carry a description that names the problem |
400 | 3004 | CHARGE_METHOD_UNAVAILABLE | card on an mkp_test_ key, where cards are off, or where the currency is not taken by card; paybill on a test key or where Pay Bill is off | Use another method |
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header | Remove the header |
400 | 3017 | PLATFORM_FEE_INVALID | With on_behalf_of: amount or fee breaks the fee rules | Correct the amount or fee |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks charges:write, 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 |
403 | 3013 | PLATFORM_IP_NOT_ALLOWED | on_behalf_of from an address not on your allow-list | Call from a listed address |
404 | 2943 | PLATFORM_ACCOUNT_NOT_FOUND | on_behalf_of names an account you do not reach | Check the id |
409 | 2709 | WALLET_NOT_PROVISIONED | The payee's main wallet does not exist yet | Retry after a few seconds |
409 | 2836 | CHECKOUT_TEST_MODE | mobile_money on a test key with a number that is not a test number | Use a test number |
409 | 3002 | CHARGE_REFERENCE_PENDING | A charge for this reference is still pending. data.charge names it | Wait for it to end, or cancel it, then charge again |
409 | 3018 | PLATFORM_FEE_WALLET_MISSING | A fee above 0 and your own main wallet does not exist | Contact MOOKHPay |
422 | 2701 | RAIL_NOT_AVAILABLE | payment_method.rail is not the rail this deployment collects on, or no mobile rail is on | Leave rail out, or use the right host |
422 | 2702 | INVALID_AMOUNT | amount is outside the rail's limits | Use an amount inside the limits |
422 | 2721 | COLLECTION_DISABLED | The rail is not taking payments | Retry later |
422 | 2838 | TEST_NUMBER_LIVE | A test number on a live key | Use a real number |
422 | 3015 | IDEMPOTENCY_KEY_REUSED | The Idempotency-Key was used before with a different body | Use a new key for a new request |
429 | 3005 | CHARGE_PROMPT_LIMIT | Over a charge limit (see below) | Wait Retry-After seconds |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over 100 unknown account ids in an hour | Wait Retry-After seconds |
503 | 2782 | AUTHN_UNAVAILABLE | Keys cannot be checked | Retry with backoff, same key and body |
503 | 2752 | LEDGER_UNAVAILABLE | The wallet check did not answer | Retry with backoff, same key and body |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | With on_behalf_of: the account could not be read | Retry with backoff |
When the prompt itself is refused (for example a rail or test-number refusal raised while sending it), no charge is kept: the same Idempotency-Key can be sent again once the problem is fixed.
Rate limit
Three limits, each answering 429 with code 3005, Retry-After and data.retryAfter:
| Limit | Default | Counts |
|---|---|---|
| Per account | 300 an hour (CHARGES_PER_KEY) | Every create on any of the account's keys, every method. MOOKHPay can raise it for your account; see Raising your limits |
| Per payer number | 5 prompts an hour (CHARGE_PROMPTS_PER_PHONE) | mobile_money only, across every merchant and the hosted page. A test number is counted per merchant |
| Per number and merchant | 3 prompts an hour (CHARGE_PROMPTS_PER_PHONE_MERCHANT) | mobile_money only. MOOKHPay can raise it for your account |
Requests refused later in the call (for example 3002) still count.