Getting started
Three steps take you from an empty account to your first payment request.
-
01
Create an account, pick a plan and upload your ID. We check it, then you turn on two-factor authentication.
-
02
Add a connected account: your paybill, till number or bank account. Then create an API key under Developers.
-
03
Send your first request with your email and that key. The customer gets an M-Pesa prompt on their phone.
curl -X POST https://pay.mutexai.net/api/v1/initiatestkpush \
-H "Content-Type: application/json" \
-d '{
"api_key": "mp_live_…",
"email": "[email protected]",
"amount": 1500,
"msisdn": "0712345678",
"reference": "ORDER-12345",
"account_id": "GP12345678"
}'
Authentication
Every request is a POST with a JSON body. It is signed in with your account email and one of your API keys.
Create a key under Developers · API keys. Give each integration its own key so it can be stopped on its own. A wrong key or email always gets the same answer, 401 with "Invalid API key or email", so the API cannot be used to find out which emails have accounts.
{
"api_key": "mp_live_…",
"email": "[email protected]"
}
Start a payment
Ask the customer's phone to confirm an M-Pesa payment to one of your connected accounts.
POST
/api/v1/initiatestkpush
| Field | What it is |
|---|---|
| amount | The amount in Kenyan shillings, from 1 to 150,000. |
| msisdn | The customer's Safaricom number: 0712345678, 01…, +254… or 254… |
| reference | Your own reference for the payment, such as an order number. It comes back in the webhook. |
| account_id | The id of one of your connected accounts, shown on its detail page. |
{
"success": "200",
"message": "Request processed successfully",
"transaction_request_id": "GPPID3011202609451234567",
"merchant_request_id": "29115-34620561-1",
"response_description": "The service request has been accepted successfully",
"account_name": "My Shop",
"account_type": "Paybill Number",
"simulated": false
}
The answer only says M-Pesa was asked to prompt the customer. It does not mean the customer has paid. Whether the payment succeeded is decided by M-Pesa alone, and is reported by the webhook and by the status request. simulated: true means the installation is in test mode and no money moved.
Where the money goes
| Connected account | The customer pays | Account reference on the M-Pesa message |
|---|---|---|
| Paybill number | Your paybill | your reference |
| Till number | Your till (Buy Goods) | till name, your reference |
| Bank account | The bank's paybill | the account number |
A request with the same account, phone, amount and reference as a payment still waiting for the customer is answered with 429 and the earlier transaction_request_id, so a double click cannot charge twice.
Payment status
Read what M-Pesa has reported about a payment so far.
POST
/api/v1/transactionstatus
{
"api_key": "mp_live_…",
"email": "[email protected]",
"transaction_request_id": "GPPID3011202609451234567"
}
{
"ResultCode": "200",
"TransactionID": "GPPID3011202609451234567",
"TransactionStatus": "Completed",
"TransactionCode": "0",
"TransactionReceipt": "NLJ7RT61SV",
"TransactionAmount": 1500,
"TransactionReference": "ORDER-12345",
"Msisdn": "254712345678"
}
TransactionStatus is Pending, Completed, Failed or Cancelled. Only Completed means money was received. A payment belongs to the account that created it: asking for anybody else's payment answers "does not exist".
Wallet
The wallet holds money you have put in. It is optional: payments to your connected accounts never pass through it.
| Endpoint (under /api/v1/wallet) | What it does | Extra fields |
|---|---|---|
| /balance | Wallet balance | — |
| /deposit | Fund the wallet by M-Pesa (minimum Ksh 10) | amount, msisdn |
| /withdraw | Send wallet money to an M-Pesa number (minimum Ksh 10, no fee) | amount, msisdn |
| /transactions | Wallet history | limit (1 to 100), type |
| /status | Recorded status of one deposit or withdrawal | transaction_reference |
| /transfer | Send wallet money to another MutexPay wallet | recipient_wallet_id, amount, reference |
| /checkout | Pay a merchant's wallet for an order | merchant_wallet_id, amount, order_id, items, callback_url |
type on the history endpoint is one of deposit, withdrawal, transfer_out, transfer_in, fee, subscription or all.
{
"wallet_id": "GPW-000002-XXXX",
"wallet_balance": 12150.00,
"currency": "KES",
"status": "active",
"user_email": "[email protected]",
"last_updated": "2026-11-30T09:45:12+00:00"
}
The wallet balance is returned inside a data object, next to success and message.
Webhooks
When a payment finishes, MutexPay posts JSON to the address you set for that connected account, and records the attempt.
Set one address per connected account under Developers · Webhooks. Every attempt is listed under Delivery logs.
| Header | Value |
|---|---|
| Content-Type | application/json |
| X-MutexPay-Event | payment.completed, payment.cancelled, payment.failed, test or checkout.completed |
| X-MutexPay-Delivery | The id of this delivery, which you can look up in Delivery logs |
| X-MutexPay-Signature | t=<unix time>,v1=<hex signature> |
{
"Event": "payment.completed",
"ResponseCode": 0,
"ResponseDescription": "Success. Request accepted for processing",
"MerchantRequestID": "29115-34620561-1",
"CheckoutRequestID": "ws_CO_18012026153045987",
"TransactionID": "GPPID3011202609451234567",
"TransactionStatus": "Completed",
"TransactionAmount": 1500,
"TransactionReceipt": "NLJ7RT61SV",
"TransactionDate": "20261130094512",
"TransactionReference": "ORDER-12345",
"Msisdn": "254712345678",
"AccountName": "My Shop",
"AccountID": "GP12345678",
"AccountType": "Paybill Number"
}
Treat only payment.completed with ResponseCode = 0 as money received, and use TransactionID to avoid fulfilling a payment twice. Answer with any 2xx status. test is sent when you press "Send a test webhook": no payment is behind it.
A delivery that is not answered (anything other than a 2xx status, or no answer within ten seconds) is retried up to 5 times, waiting 1, 5, 15 and 60 minutes between attempts, and can be sent again from Delivery logs. Webhook addresses must be public https:// addresses: MutexPay does not call private or internal addresses.
For integrations written before the product was renamed, the same three headers are also sent as X-GrandPay-Event, X-GrandPay-Delivery and X-GrandPay-Signature.
/api/v1/wallet/checkout accepts a callback_url. That notification is signed with the merchant's API key (the owner of merchant_wallet_id), so only the merchant can verify it. Its event is checkout.completed and the payload carries OrderID.
Check the signature
A webhook that says "paid" is only worth acting on once you have checked who sent it.
The signature is HMAC-SHA256(secret, "<unix time>.<raw request body>") in hex, where the secret is the signing secret on the Webhooks page. Check it over the raw body, and reject anything older than five minutes. More examples are on the code snippets page.
<?php
// Verify a MutexPay webhook before trusting it.
$raw = file_get_contents('php://input');
$secret = 'YOUR_SIGNING_SECRET'; // Webhook Settings in your MutexPay dashboard
$header = $_SERVER['HTTP_X_MUTEXPAY_SIGNATURE'] ?? '';
if (!preg_match('/t=(\d+),v1=([0-9a-f]{64})/', $header, $m)) {
http_response_code(401); exit;
}
[$_, $timestamp, $signature] = $m;
if (abs(time() - (int) $timestamp) > 300) {
http_response_code(401); exit; // too old: possible replay
}
$expected = hash_hmac('sha256', $timestamp . '.' . $raw, $secret);
if (!hash_equals($expected, $signature)) {
http_response_code(401); exit;
}
$event = json_decode($raw, true);
// Only "payment.completed" with ResponseCode 0 means the customer paid.
if (($event['Event'] ?? '') === 'payment.completed' && (int) ($event['ResponseCode'] ?? 1) === 0) {
// fulfil the order
}
http_response_code(200);
Test mode
Until an installation is switched to live payments, M-Pesa is simulated and no real money moves.
API answers then carry simulated: true, and every page of the dashboard shows "Test mode: payments are simulated". Everything else runs as in live mode: the request is validated, a signed callback is delivered to the real callback endpoint, the result is checked the same way and your webhook is called.
On this installation payments are simulated (test mode).
Rate limits and errors
Each kind of request has its own limit per minute.
| Requests | Per minute | When you go over |
|---|---|---|
| Start a payment, read a status, wallet reads | 60 | 429 Too Many Attempts |
| Wallet transfers and checkouts | 10 | |
| Wallet withdrawals | 5 |
| Status | Meaning |
|---|---|
| 400 | A field is missing or out of range. The errors object says which. |
| 401 | The key or the email is wrong, or the account is closed. |
| 429 | Too many requests, or the same payment is still waiting for the customer. |
Every error has success: false and a message in plain words.
Support
Stuck on an integration? Tell us what you are trying to do and what came back.