Skip to content

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 useThe key needs
POST /checkouts with on_behalf_ofcheckouts and payments:write
POST /charges with on_behalf_ofcharges: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 ​

FieldTypeRules
on_behalf_ofstringOne of your account ids, acct_<country>_<24 hex>
platform_feeintegerOptional, minor units. Only with on_behalf_of. Defaults to 0

The amount rules change when you pay on behalf of an account:

  • amount must be whole currency units, a multiple of 100, even when platform_fee is 0 or left out. 150050 is refused.
  • platform_fee must be whole currency units too: 0, 100, 200 and 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 is amount × share, rounded down to the minor unit. A 10% share on 150000 allows up to 15000.
  • 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.url
python
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 45000
python
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.via on GET /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 ​

CaseWhat 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 chargeThe 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 numberBooked with your fee
The payer uses the Pay Bill account number with a different amount, or after the payment was already madeM-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 balanceRefused 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 platformThe seller (with their own key)
GET /checkouts/{id}Yes, with account, platform_fee and netYes, with account, platform_fee and net
GET /charges/{id}YesYes
GET /charges?reference=Yes, for charges you madeOnly for charges the seller made
POST /charges/{id}/cancelYesNo: 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.

EventYour copyThe seller's copy
payment.succeeded, payment.failedAdds account, platform_fee and netAdds platform_fee and net, no account
charge.expired, charge.cancelledAdds account, platform_fee and netNot sent

platform_fee and net are numbers in these payloads, while amount is a string. See the event catalogue.

Errors ​

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAplatform_fee without on_behalf_ofAdd on_behalf_of, or drop the fee
4003017PLATFORM_FEE_INVALIDamount or fee not whole units, fee over your share, or the seller left with less than 100Fix the amounts
4032941API_KEY_SCOPE_REQUIREDThe key lacks payments:writeMake a key with it
4032942PLATFORM_NOT_ENABLEDNot a platformAsk MOOKHPay
4033013PLATFORM_IP_NOT_ALLOWEDCalled from an unlisted addressCall from a listed address
4042943PLATFORM_ACCOUNT_NOT_FOUNDThe account is unknown, another platform's or revokedStop using the id
4092709WALLET_NOT_PROVISIONEDThe seller's wallet is not set up yetRetry in a moment
4092946PLATFORM_BALANCE_PAY_UNAVAILABLEThe payer tried to pay from a MOOKHPay balanceThe payer uses mobile money or a card
4093018PLATFORM_FEE_WALLET_MISSINGYour organisation has no wallet to take the feeAsk MOOKHPay
5032752LEDGER_UNAVAILABLEYour wallet could not be checkedRetry with the same key

The errors a checkout or charge can answer anyway are on Create a checkout and Create a charge.

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