Skip to content

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
AuthSecret key, Authorization: Bearer mkp_…, checked with no cache on every call
Scopecharges: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 flagRegistered 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 modeA 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 ​

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

Parameters ​

Body ​

Unknown fields are refused with 400 and code 1701, at the top level and inside payment_method.

NameTypeRequiredConstraints and meaning
amountintegerYesMinor 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
referencestringYesYour own order id, 1 to 64 characters. One pending charge per reference at a time; after it ends, a new one is allowed
descriptionstringNo1 to 140 characters
payment_methodobjectYesOne of the three shapes below
payer_emailstringNoAt 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
metadataobjectNoUp 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_ofstringNoPlatforms only. One of your account ids. The seller is the payee and the prompt names them
platform_feeintegerNoPlatforms 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 ​

ShapeFieldsMeaning
{ "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 onSends 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" }noneKenya 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" }noneAnswers 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:

FieldTypeMeaning
idstringch_<country>_<24 hex>. Store it with your order
statusstringpending
next_actionobjectWhat the payer has to do: await_payer, pay_to_paybill or use_card_element
next_action.client_secretstringCard 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.totalintegerCard only. The card fee the payer adds and what their card is charged, in minor units. You receive amount
account, platform_feestring, integerOnly with on_behalf_of. net is then amount less platform_fee

Errors ​

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATABody 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_ofFix the request. The handler checks carry a description that names the problem
4003004CHARGE_METHOD_UNAVAILABLEcard 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 offUse another method
4003014IDENTITY_HEADER_REFUSEDThe request carries a session or identity headerRemove the header
4003017PLATFORM_FEE_INVALIDWith on_behalf_of: amount or fee breaks the fee rulesCorrect the amount or fee
4012781API_KEY_INVALIDMissing, malformed, unknown or revoked keyCheck the key
4032941API_KEY_SCOPE_REQUIREDThe key lacks charges:write, 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
4033013PLATFORM_IP_NOT_ALLOWEDon_behalf_of from an address not on your allow-listCall from a listed address
4042943PLATFORM_ACCOUNT_NOT_FOUNDon_behalf_of names an account you do not reachCheck the id
4092709WALLET_NOT_PROVISIONEDThe payee's main wallet does not exist yetRetry after a few seconds
4092836CHECKOUT_TEST_MODEmobile_money on a test key with a number that is not a test numberUse a test number
4093002CHARGE_REFERENCE_PENDINGA charge for this reference is still pending. data.charge names itWait for it to end, or cancel it, then charge again
4093018PLATFORM_FEE_WALLET_MISSINGA fee above 0 and your own main wallet does not existContact MOOKHPay
4222701RAIL_NOT_AVAILABLEpayment_method.rail is not the rail this deployment collects on, or no mobile rail is onLeave rail out, or use the right host
4222702INVALID_AMOUNTamount is outside the rail's limitsUse an amount inside the limits
4222721COLLECTION_DISABLEDThe rail is not taking paymentsRetry later
4222838TEST_NUMBER_LIVEA test number on a live keyUse a real number
4223015IDEMPOTENCY_KEY_REUSEDThe Idempotency-Key was used before with a different bodyUse a new key for a new request
4293005CHARGE_PROMPT_LIMITOver a charge limit (see below)Wait Retry-After seconds
4291804RATE_LIMIT_EXCEEDEDOver 100 unknown account ids in an hourWait Retry-After seconds
5032782AUTHN_UNAVAILABLEKeys cannot be checkedRetry with backoff, same key and body
5032752LEDGER_UNAVAILABLEThe wallet check did not answerRetry with backoff, same key and body
5033016PLATFORM_ACCOUNTS_UNAVAILABLEWith on_behalf_of: the account could not be readRetry 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:

LimitDefaultCounts
Per account300 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 number5 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 merchant3 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.

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