Appearance
Cancel a charge
Stops a pending charge from being paid. A Pay Bill charge stops matching payments at once, and the hosted page stops taking new attempts.
Cancelling cannot recall a prompt that is already on the payer's phone. If the payer approves it anyway, the payment is booked and the charge moves to succeeded, with payment.succeeded sent. Cancelling does not refund anything.
Endpoint
POST /v1/payments/merchant/charges/{id}/cancel| Auth | Secret key, Authorization: Bearer mkp_… |
| Scope | charges:write |
| Who can cancel | Only the merchant or platform that made the charge. A seller cannot cancel a charge a platform made for it |
| Feature flag | Registered only where direct charges are on |
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_test_… or Bearer mkp_live_… |
Content-Type | Only with a body | application/json |
No Idempotency-Key is needed: cancelling a charge that is already cancelled answers it again with 200.
Parameters
Path
| Name | Type | Required | Constraints and meaning |
|---|---|---|---|
id | string | Yes | The charge id, ch_<country>_<24 hex> |
Body
None. Send no body, or {}. Anything else is 400, code 1701, cancel takes no body. An empty body sent with Content-Type: application/json is not valid JSON, so either leave out the header or send {}.
Example request
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/charges/ch_ke_7e1a4c9b2d5f80e3a6c1b047/cancel \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{}'js
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const id = "ch_ke_7e1a4c9b2d5f80e3a6c1b047";
const res = await fetch(`${BASE}/charges/${id}/cancel`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Content-Type": "application/json",
},
body: "{}",
});
const body = await res.json();
if (res.status === 409 && body.code === 3003) {
console.log("Already ended; read the charge to see how");
} else if (!body.ok) {
throw new Error(`${res.status} ${body.code}: ${body.description}`);
} else {
console.log(body.data.status);
}python
import os
import requests
BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
charge_id = "ch_ke_7e1a4c9b2d5f80e3a6c1b047"
res = requests.post(
f"{BASE}/charges/{charge_id}/cancel",
headers={"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}"},
json={},
timeout=30,
)
body = res.json()
if res.status_code == 409 and body["code"] == 3003:
print("Already ended; read the charge to see how")
elif not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
else:
print(body["data"]["status"])php
<?php
$base = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
$id = "ch_ke_7e1a4c9b2d5f80e3a6c1b047";
$ch = curl_init("$base/charges/$id/cancel");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => "{}",
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status === 409 && $body["code"] === 3003) {
echo "Already ended; read the charge to see how", PHP_EOL;
} elseif (!$body["ok"]) {
throw new RuntimeException("$status {$body['code']}: {$body['description']}");
} else {
echo $body["data"]["status"], PHP_EOL;
}Response
200 OK, with the charge as it is now. charge.cancelled is sent to your endpoints the first time a charge is cancelled.
json
{
"ok": true,
"description": "Charge cancelled",
"data": {
"id": "ch_ke_7e1a4c9b2d5f80e3a6c1b047",
"status": "cancelled",
"test": false,
"amount": 150000,
"currency": "KES",
"fee": 0,
"net": 150000,
"reference": "order-8841",
"description": "A3 print",
"payment_method": { "type": "paybill" },
"next_action": null,
"failure": null,
"receipt_number": null,
"hosted_url": "https://mookhpay.co/checkout/cs_ke_0b4d2f7a9c1e53b8d6a2e410",
"metadata": {},
"expires_at": "2026-11-20T09:44:00.000Z",
"created_at": "2026-11-20T09:14:00.000Z"
}
}Response fields
data is the charge object, with status cancelled and next_action null. Once cancelled, a new charge for the same reference is allowed.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | A body other than {}, or an empty body sent as JSON | Send {} or no body |
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header | Remove the header |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks charges:write | Issue a key with the scope |
403 | 3042 | API_KEY_IP_NOT_ALLOWED | The account has allowed addresses and the call came from another address | Call from a listed address |
404 | 3001 | CHARGE_NOT_FOUND | No such charge, or one you did not make | Check the id |
409 | 3003 | CHARGE_NOT_CANCELLABLE | The charge has already succeeded, failed or expired | Read the charge to see how it ended |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over the rate limit | Wait Retry-After seconds |
503 | 2782 | AUTHN_UNAVAILABLE | Keys cannot be checked | Retry with backoff |
Rate limit
120 requests a minute per key owner, shared with the charge reads and the checkout routes. Over it: 429, code 1804, Retry-After in seconds.