Skip to content

Platform quickstart ​

This page takes one seller from nothing to paid out: open their account, take a payment with your fee, read their balance and pay them out. Each step links to the page with the details.

Before you start ​

  • Your organisation is switched on as a platform by MOOKHPay. See How platforms work.
  • An Owner made a secret key with accounts:write, accounts:read, checkouts, charges:write, payments:write and payouts:write, and saved it as MOOKHPAY_SECRET_KEY. The Owner chooses the scopes on Create A Key in the hub (API Integrations, API Keys, Secret Key); see API keys and scopes.
  • An Owner made the payout signing secret in the hub and saved it as MOOKHPAY_PAYOUT_SECRET. See Pay out sellers.
  • Everything below runs against Kenya staging. Staging keys are mkp_test_, so the charge in step 2 is a test charge paid by a test number and moves no money. Accounts and payouts on staging are real. See Testing.

1. Open the seller's account ​

sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/accounts \
  -H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
  -H "Idempotency-Key: seller-8841" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "+254712345678",
    "first_name": "Joy",
    "last_name": "Otieno",
    "external_reference": "seller-8841",
    "terms": { "accepted_at": "2026-11-20T09:12:00Z", "version": "2026-10" }
  }'
js
const API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const auth = { Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}` };

async function call(method, path, { body, headers } = {}) {
  const res = await fetch(`${API}${path}`, {
    method,
    headers: { ...auth, ...(body ? { "Content-Type": "application/json" } : {}), ...headers },
    body: typeof body === "string" ? body : body && JSON.stringify(body),
  });
  const answer = await res.json();
  if (!answer.ok) throw new Error(`${res.status} ${answer.code}: ${answer.description}`);
  return answer.data;
}

const account = await call("POST", "/accounts", {
  headers: { "Idempotency-Key": "seller-8841" },
  body: {
    phone: "+254712345678",
    first_name: "Joy",
    last_name: "Otieno",
    external_reference: "seller-8841",
    terms: { accepted_at: "2026-11-20T09:12:00Z", version: "2026-10" },
  },
});
console.log(account.id); // acct_ke_…
python
import os
import requests

API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
AUTH = {"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}"}

def call(method, path, json=None, data=None, headers=None):
    res = requests.request(method, API + path, json=json, data=data,
                           headers={**AUTH, **(headers or {})}, timeout=30)
    answer = res.json()
    if not answer["ok"]:
        raise RuntimeError(f"{res.status_code} {answer['code']}: {answer['description']}")
    return answer["data"]

account = call("POST", "/accounts", headers={"Idempotency-Key": "seller-8841"}, json={
    "phone": "+254712345678",
    "first_name": "Joy",
    "last_name": "Otieno",
    "external_reference": "seller-8841",
    "terms": {"accepted_at": "2026-11-20T09:12:00Z", "version": "2026-10"},
})
print(account["id"])  # acct_ke_…
php
<?php
const API = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";

function call(string $method, string $path, $body = null, array $headers = []): array {
    $ch = curl_init(API . $path);
    $all = array_merge(["Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY")], $headers);
    if ($body !== null) {
        $all[] = "Content-Type: application/json";
        curl_setopt($ch, CURLOPT_POSTFIELDS, is_string($body) ? $body : json_encode($body));
    }
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => $all,
    ]);
    $answer = json_decode(curl_exec($ch), true);
    if (!$answer["ok"]) {
        throw new RuntimeException("{$answer['code']}: {$answer['description']}");
    }
    return $answer["data"];
}

$account = call("POST", "/accounts", [
    "phone" => "+254712345678",
    "first_name" => "Joy",
    "last_name" => "Otieno",
    "external_reference" => "seller-8841",
    "terms" => ["accepted_at" => "2026-11-20T09:12:00Z", "version" => "2026-10"],
], ["Idempotency-Key: seller-8841"]);
echo $account["id"], "\n"; // acct_ke_…

The seller gets a text from MOOKHPay telling them how to claim the account. If the phone already has a MOOKHPay account you get 409 with code 2944: link that account instead. The rest of this page uses the Node, Python and PHP call helper defined here. Details: Open seller accounts.

2. Take a payment with your fee ​

Charge KES 500 for the seller and keep KES 50. Amounts on a platform payment are whole shillings: multiples of 100 in minor units.

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
let charge = await call("POST", "/charges", {
  headers: { "Idempotency-Key": "order-8842" },
  body: {
    amount: 50000,
    reference: "order-8842",
    payment_method: { type: "mobile_money", phone: "+254700000000" },
    on_behalf_of: account.id,
    platform_fee: 5000,
  },
});
while (charge.status === "pending") {
  await new Promise((r) => setTimeout(r, 2000));
  charge = await call("GET", `/charges/${charge.id}`);
}
console.log(charge.status, charge.net); // succeeded 45000
python
import time

charge = call("POST", "/charges", headers={"Idempotency-Key": "order-8842"}, json={
    "amount": 50000,
    "reference": "order-8842",
    "payment_method": {"type": "mobile_money", "phone": "+254700000000"},
    "on_behalf_of": account["id"],
    "platform_fee": 5000,
})
while charge["status"] == "pending":
    time.sleep(2)
    charge = call("GET", f"/charges/{charge['id']}")
print(charge["status"], charge["net"])  # succeeded 45000
php
<?php
$charge = call("POST", "/charges", [
    "amount" => 50000,
    "reference" => "order-8842",
    "payment_method" => ["type" => "mobile_money", "phone" => "+254700000000"],
    "on_behalf_of" => $account["id"],
    "platform_fee" => 5000,
], ["Idempotency-Key: order-8842"]);
while ($charge["status"] === "pending") {
    sleep(2);
    $charge = call("GET", "/charges/{$charge['id']}");
}
echo $charge["status"], " ", $charge["net"], "\n"; // succeeded 45000

+254700000000 is the test number that succeeds after about three seconds. On production, use the payer's real number and listen for payment.succeeded rather than polling alone. A hosted checkout takes the same two fields. Details: Take payments with a fee.

3. Read the seller's balance ​

sh
curl https://payments-ke-staging.mookhpay.co/v1/payments/merchant/accounts/acct_ke_9c2f41b07e5d38a6c1f0b294/balance \
  -H "Authorization: Bearer $MOOKHPAY_SECRET_KEY"
js
const balance = await call("GET", `/accounts/${account.id}/balance`);
const main = balance.wallets.find((w) => w.wallet === "main");
console.log(balance.currency, main.balance);
python
balance = call("GET", f"/accounts/{account['id']}/balance")
main = next(w for w in balance["wallets"] if w["wallet"] == "main")
print(balance["currency"], main["balance"])
php
<?php
$balance = call("GET", "/accounts/{$account['id']}/balance");
$main = array_values(array_filter($balance["wallets"], fn($w) => $w["wallet"] === "main"))[0];
echo $balance["currency"], " ", $main["balance"], "\n";

A test charge is never booked, so on staging the balance does not change. Details: Balances and dashboards.

4. Pay the seller out ​

A payout is signed with the payout signing secret: sha256= and the hex HMAC-SHA256 of the timestamp, a full stop and the exact body bytes.

sh
ACCOUNT=acct_ke_9c2f41b07e5d38a6c1f0b294
BODY='{"amount":10000,"remarks":"First payout"}'
TS=$(date +%s)
SIG="sha256=$(printf '%s.%s' "$TS" "$BODY" \
  | openssl dgst -sha256 -hmac "$MOOKHPAY_PAYOUT_SECRET" -hex | sed 's/^.* //')"

curl -X POST "https://payments-ke-staging.mookhpay.co/v1/payments/merchant/accounts/$ACCOUNT/payouts" \
  -H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
  -H "Idempotency-Key: payout-8841-1" \
  -H "Content-Type: application/json" \
  -H "X-Mookh-Timestamp: $TS" \
  -H "X-Mookh-Signature: $SIG" \
  --data-raw "$BODY"
js
import { createHmac } from "node:crypto";

const body = JSON.stringify({ amount: 10000, remarks: "First payout" });
const timestamp = Math.floor(Date.now() / 1000).toString();
const signature =
  "sha256=" +
  createHmac("sha256", process.env.MOOKHPAY_PAYOUT_SECRET).update(`${timestamp}.`).update(body).digest("hex");

const payout = await call("POST", `/accounts/${account.id}/payouts`, {
  headers: {
    "Idempotency-Key": "payout-8841-1",
    "X-Mookh-Timestamp": timestamp,
    "X-Mookh-Signature": signature,
  },
  body, // the signed string, sent as is
});
console.log(payout.payout_id, payout.status);
python
import hashlib
import hmac
import json
import os
import time

body = json.dumps({"amount": 10000, "remarks": "First payout"}, separators=(",", ":")).encode()
timestamp = str(int(time.time()))
signature = "sha256=" + hmac.new(
    os.environ["MOOKHPAY_PAYOUT_SECRET"].encode(), timestamp.encode() + b"." + body, hashlib.sha256
).hexdigest()

payout = call("POST", f"/accounts/{account['id']}/payouts", data=body, headers={
    "Idempotency-Key": "payout-8841-1",
    "Content-Type": "application/json",
    "X-Mookh-Timestamp": timestamp,
    "X-Mookh-Signature": signature,
})
print(payout["payout_id"], payout["status"])
php
<?php
$body = json_encode(["amount" => 10000, "remarks" => "First payout"]);
$timestamp = (string) time();
$signature = "sha256=" . hash_hmac("sha256", "$timestamp.$body", getenv("MOOKHPAY_PAYOUT_SECRET"));

$payout = call("POST", "/accounts/{$account['id']}/payouts", $body, [
    "Idempotency-Key: payout-8841-1",
    "X-Mookh-Timestamp: $timestamp",
    "X-Mookh-Signature: $signature",
]);
echo $payout["payout_id"], " ", $payout["status"], "\n";

The payout goes to the seller's chosen payout account, or their phone. It is real on staging and needs money in the seller's main wallet: the amount plus the payout fee (0 for now). Without it, it answers 422 with code 2732. payout.paid or payout.failed follows. Details and a test vector for your signing code: Pay out sellers.

Next ​

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