Appearance
Take payments with a fee
Add on_behalf_of and platform_fee to a hosted checkout or a direct charge. The seller is the payee. Your fee goes to your own organisation's wallet, and the rest goes to the seller's wallet, in one ledger booking.
| You use | The key needs |
|---|---|
POST /checkouts with on_behalf_of | checkouts and payments:write |
POST /charges with on_behalf_of | charges:write and payments:write |
The account's grant is not checked on a payment: only your key's scopes are. A linked account whose owner did not approve payments:write can still be paid through your platform today. Ask for payments:write when you link an account anyway, since the owner sees what you asked for.
The two fields
| Field | Type | Rules |
|---|---|---|
on_behalf_of | string | One of your account ids, acct_<country>_<24 hex> |
platform_fee | integer | Optional, minor units. Only with on_behalf_of. Defaults to 0 |
The amount rules change when you pay on behalf of an account:
amountmust be whole currency units, a multiple of100, even whenplatform_feeis0or left out.150050is refused.platform_feemust be whole currency units too:0,100,200and so on.- The fee can be at most your platform's maximum share of
amount, which MOOKHPay set when it switched you on. The maximum isamount × share, rounded down to the minor unit. A 10% share on150000allows up to15000. - The fee must leave the seller at least one whole unit:
amount − platform_fee ≥ 100.
A request that breaks any of these answers 400 with code 3017 and a description naming the rule that failed. platform_fee without on_behalf_of answers 400 with code 1701.
A fee above 0 needs your own organisation's main wallet to exist. If it does not, the call answers 409 with code 3018. A wallet appears shortly after the organisation is created; if you see 3018, ask MOOKHPay.
Create a checkout for a seller
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/checkouts \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: order-8841" \
-H "Content-Type: application/json" \
-d '{
"amount": 150000,
"reference": "order-8841",
"description": "Hand-thrown mug",
"return_url": "https://market.example/orders/8841",
"on_behalf_of": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee": 15000
}'js
const res = await fetch(
"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/checkouts",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": "order-8841",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 150000,
reference: "order-8841",
description: "Hand-thrown mug",
return_url: "https://market.example/orders/8841",
on_behalf_of: "acct_ke_9c2f41b07e5d38a6c1f0b294",
platform_fee: 15000,
}),
},
);
const body = await res.json();
if (!body.ok) throw new Error(`${res.status} ${body.code}: ${body.description}`);
// Send the buyer to body.data.urlpython
import os
import requests
res = requests.post(
"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/checkouts",
headers={
"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}",
"Idempotency-Key": "order-8841",
},
json={
"amount": 150000,
"reference": "order-8841",
"description": "Hand-thrown mug",
"return_url": "https://market.example/orders/8841",
"on_behalf_of": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee": 15000,
},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
# Send the buyer to body["data"]["url"]php
<?php
$ch = curl_init("https://payments-ke-staging.mookhpay.co/v1/payments/merchant/checkouts");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY"),
"Idempotency-Key: order-8841",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"amount" => 150000,
"reference" => "order-8841",
"description" => "Hand-thrown mug",
"return_url" => "https://market.example/orders/8841",
"on_behalf_of" => "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee" => 15000,
]),
]);
$body = json_decode(curl_exec($ch), true);
if (!$body["ok"]) {
throw new RuntimeException("{$body['code']}: {$body['description']}");
}
// Send the buyer to $body["data"]["url"]The answer is the checkout object with three more fields:
json
{
"ok": true,
"description": "Checkout created",
"data": {
"id": "cs_ke_5b1e0c9a7d2f4e6b8a3c1d0e",
"url": "https://mookhpay.co/checkout/cs_ke_5b1e0c9a7d2f4e6b8a3c1d0e",
"status": "open",
"test": false,
"amount": "150000",
"currency": "KES",
"reference": "order-8841",
"description": "Hand-thrown mug",
"line_items": null,
"return_url": "https://market.example/orders/8841",
"account": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee": 15000,
"net": 135000,
"expires_at": "2026-11-20T10:02:04.000Z",
"created_at": "2026-11-20T09:32:04.000Z",
"payment": null
}
}net is what the seller receives. Note that amount is a string on a checkout and platform_fee and net are numbers.
Create a direct charge for a seller
The same two fields go on POST /charges. The mobile-money prompt goes straight to the payer's phone, naming the seller.
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/charges \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: order-8842" \
-H "Content-Type: application/json" \
-d '{
"amount": 50000,
"reference": "order-8842",
"payment_method": { "type": "mobile_money", "phone": "+254700000000" },
"on_behalf_of": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee": 5000
}'js
const res = await fetch(
"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/charges",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": "order-8842",
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 50000,
reference: "order-8842",
payment_method: { type: "mobile_money", phone: "+254700000000" },
on_behalf_of: "acct_ke_9c2f41b07e5d38a6c1f0b294",
platform_fee: 5000,
}),
},
);
const body = await res.json();
if (!body.ok) throw new Error(`${res.status} ${body.code}: ${body.description}`);
console.log(body.data.id, body.data.status, body.data.net); // ch_ke_… pending 45000python
import os
import requests
res = requests.post(
"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/charges",
headers={
"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}",
"Idempotency-Key": "order-8842",
},
json={
"amount": 50000,
"reference": "order-8842",
"payment_method": {"type": "mobile_money", "phone": "+254700000000"},
"on_behalf_of": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee": 5000,
},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
print(body["data"]["id"], body["data"]["status"], body["data"]["net"])php
<?php
$ch = curl_init("https://payments-ke-staging.mookhpay.co/v1/payments/merchant/charges");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY"),
"Idempotency-Key: order-8842",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"amount" => 50000,
"reference" => "order-8842",
"payment_method" => ["type" => "mobile_money", "phone" => "+254700000000"],
"on_behalf_of" => "acct_ke_9c2f41b07e5d38a6c1f0b294",
"platform_fee" => 5000,
]),
]);
$body = json_decode(curl_exec($ch), true);
if (!$body["ok"]) {
throw new RuntimeException("{$body['code']}: {$body['description']}");
}
echo $body["data"]["id"], " ", $body["data"]["status"], "\n";On staging every charge is a test charge, because staging keys are mkp_test_. +254700000000 is the test number that succeeds; see Testing. The charge carries account, platform_fee and net beside the usual fields of the charge object.
When the money moves
Nothing is credited when you create the checkout or charge. When the payment is booked, the ledger credits the seller's main wallet with net and your organisation's main wallet with platform_fee, in one transaction: both land or neither does. Then payment.succeeded is sent.
- The fee is fixed when the checkout or charge is created. Nothing the payer does can change it.
- If the seller's account has a split rule, it runs on what the seller receives after your fee.
- The fee is credited to your wallet. It is not deducted from your payouts, and it is not sent anywhere.
What the payer sees
- The hosted page names the seller as the payee, "via" your organisation's display name. The page reads this from
payee.viaonGET /v1/payments/public/checkouts/{id}. - The mobile-money prompt names the seller.
- The emailed receipt, sent when the payer gave an email address, names the payee as "Joy Otieno via Kilimani Market": the seller's display name, then yours.
How each payment method treats the fee
| Case | What happens |
|---|---|
| Mobile money (M-Pesa in Kenya, MTN MoMo in Uganda) | Booked with your fee as above |
| Card, on the hosted page or a card charge | The card fee is added on top for the payer. Your fee and the seller's net are unchanged |
Pay Bill charge (payment_method.type: "paybill"), paid with the exact amount and account number | Booked with your fee |
| The payer uses the Pay Bill account number with a different amount, or after the payment was already made | M-Pesa has already taken the money, so it is not refused. The whole amount goes to the seller's main wallet with no fee, and it does not settle your checkout or charge |
| The payer tries to pay a checkout from their MOOKHPay balance | Refused with 409 and code 2946. A checkout made on behalf of an account cannot be paid from a balance |
Idempotency keys and references are yours
Your Idempotency-Key values and charge reference values belong to your platform, whichever seller a payment is for. They never collide with keys or references the seller uses with their own key, and one pending charge per reference applies across all your sellers. Use your own order id.
Who can read and cancel
| Your platform | The seller (with their own key) | |
|---|---|---|
GET /checkouts/{id} | Yes, with account, platform_fee and net | Yes, with account, platform_fee and net |
GET /charges/{id} | Yes | Yes |
GET /charges?reference= | Yes, for charges you made | Only for charges the seller made |
POST /charges/{id}/cancel | Yes | No: 404 with code 3001 |
Refunds
A payment taken through a platform cannot be refunded through MOOKHPay. POST /refunds on such a payment answers 409 and code 2861 with data.reason platform_payment, and a refund request in the hub and a card refund are refused too.
Webhooks
Your platform's endpoints and the seller's own endpoints (if the seller has any) both receive the payment events.
| Event | Your copy | The seller's copy |
|---|---|---|
payment.succeeded, payment.failed | Adds account, platform_fee and net | Adds platform_fee and net, no account |
charge.expired, charge.cancelled | Adds account, platform_fee and net | Not sent |
platform_fee and net are numbers in these payloads, while amount is a string. See the event catalogue.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | platform_fee without on_behalf_of | Add on_behalf_of, or drop the fee |
400 | 3017 | PLATFORM_FEE_INVALID | amount or fee not whole units, fee over your share, or the seller left with less than 100 | Fix the amounts |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks payments:write | Make a key with it |
403 | 2942 | PLATFORM_NOT_ENABLED | Not a platform | Ask MOOKHPay |
403 | 3013 | PLATFORM_IP_NOT_ALLOWED | Called from an unlisted address | Call from a listed address |
404 | 2943 | PLATFORM_ACCOUNT_NOT_FOUND | The account is unknown, another platform's or revoked | Stop using the id |
409 | 2709 | WALLET_NOT_PROVISIONED | The seller's wallet is not set up yet | Retry in a moment |
409 | 2946 | PLATFORM_BALANCE_PAY_UNAVAILABLE | The payer tried to pay from a MOOKHPay balance | The payer uses mobile money or a card |
409 | 3018 | PLATFORM_FEE_WALLET_MISSING | Your organisation has no wallet to take the fee | Ask MOOKHPay |
503 | 2752 | LEDGER_UNAVAILABLE | Your wallet could not be checked | Retry with the same key |
The errors a checkout or charge can answer anyway are on Create a checkout and Create a charge.