Appearance
Create a refund
Asks MOOKHPay to send a paid checkout's or charge's money back to the payer, all of it or part. Nothing moves when you call it: the refund is made in requested, MOOKHPay reviews it, and refund.succeeded or refund.declined follows. See Refunds.
Endpoint
POST /v1/payments/merchant/refunds| Auth | Secret key |
| Scope | refunds:write |
| Switched on | Per deployment (REFUND_API_ENABLED). Where it is off, the route does not exist and answers 404 |
The key is checked with authn on every call, with no 60-second cache.
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_… |
Idempotency-Key | Yes | 1 to 128 characters. The same key and body return the same refund. The same key with a different body answers 422 and code 3015. See Idempotency |
Content-Type | Yes | application/json |
Parameters
Body. Unknown fields are refused. Send exactly one of checkout_id and charge_id.
| Name | Type | Required | Constraints |
|---|---|---|---|
checkout_id | string | One of the two | A hosted checkout your key made or was paid by, cs_<country>_… |
charge_id | string | One of the two | A direct charge your key made, ch_<country>_… |
amount | integer | No | Minor units, at least 1. Leave it out to refund all that is left. A part refund must be a multiple of 100 (whole currency units), and no more than what is left |
reason | string | No | Why you are refunding, up to 200 characters. MOOKHPay's reviewers see it, and it is on the refund object |
There is no currency, destination or phone field. MOOKHPay sends the money back the way the payer paid.
Example request
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/refunds \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: refund-order-1042-1" \
-H "Content-Type: application/json" \
-d '{
"checkout_id": "cs_ke_3f9a1c7e5b2d4a8e6c0b91d7",
"amount": 50000,
"reason": "One latte was not served"
}'js
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
export async function createRefund(body, idempotencyKey) {
const res = await fetch(`${BASE}/refunds`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": idempotencyKey,
"Content-Type": "application/json",
},
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 refund = await createRefund(
{ checkout_id: "cs_ke_3f9a1c7e5b2d4a8e6c0b91d7", amount: 50000, reason: "One latte was not served" },
"refund-order-1042-1",
);
console.log(refund.id, refund.status);python
import os
import requests
BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
def create_refund(body, idempotency_key):
res = requests.post(
f"{BASE}/refunds",
json=body,
headers={
"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}",
"Idempotency-Key": idempotency_key,
},
timeout=15,
)
answer = res.json()
if not answer["ok"]:
raise RuntimeError(f"{res.status_code} {answer['code']}: {answer['description']}")
return answer["data"]
refund = create_refund(
{"checkout_id": "cs_ke_3f9a1c7e5b2d4a8e6c0b91d7", "amount": 50000, "reason": "One latte was not served"},
"refund-order-1042-1",
)
print(refund["id"], refund["status"])php
<?php
const BASE = 'https://payments-ke-staging.mookhpay.co/v1/payments/merchant';
function create_refund(array $body, string $idempotencyKey): array
{
$ch = curl_init(BASE . '/refunds');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($body),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('MOOKHPAY_SECRET_KEY'),
'Idempotency-Key: ' . $idempotencyKey,
'Content-Type: application/json',
],
]);
$answer = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (!$answer['ok']) {
throw new RuntimeException("{$status} {$answer['code']}: {$answer['description']}");
}
return $answer['data'];
}
$refund = create_refund(
['checkout_id' => 'cs_ke_3f9a1c7e5b2d4a8e6c0b91d7', 'amount' => 50000, 'reason' => 'One latte was not served'],
'refund-order-1042-1'
);
echo $refund['id'], ' ', $refund['status'], PHP_EOL;Response
201 Created with description Refund requested when the refund is made. 200 OK with description Refund already requested when the same Idempotency-Key and body already made it; data is then the refund as it stands now.
json
{
"ok": true,
"description": "Refund requested",
"data": {
"id": "rf_5b1e8c2d7a4f90b3e6a1c2d8",
"status": "requested",
"amount": 50000,
"fee": 0,
"currency": "KES",
"reason": "One latte was not served",
"decline_reason": null,
"checkout_id": "cs_ke_3f9a1c7e5b2d4a8e6c0b91d7",
"charge_id": null,
"intent_id": "pi_8c1e4f0a7b3d92e5a6f01c48",
"reference": "order-1042",
"provider_receipt": null,
"method": null,
"requested_via": "api",
"requested_at": "2026-11-21T07:40:12.000Z",
"reviewed_at": null,
"refunded_at": null
}
}Response fields
data is the refund object. fee is 0 until MOOKHPay approves the refund and sets method. A refund paid back to the payer's phone then follows the payout fee, which is 0 for now. See Fees.
Retries
- A timeout, a dropped connection or a
503: retry with the sameIdempotency-Keyand the same body. You get the refund that exists, or it is made now. - A refusal (
404,409,422) makes nothing. Fix the cause and send again. - The same key with a different body, such as another
amount, answers422and code3015. A second part refund of one payment is a new refund and needs a new key, once the first isrefundedordeclined.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | The body is not JSON, a field is unknown or out of range, both or neither of checkout_id and charge_id were sent, reason is over 200 characters, or Idempotency-Key is missing | Fix the request |
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header | Remove it |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks refunds:write | Have an Owner replace the key with one that has it |
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 | 2783 | CHECKOUT_NOT_FOUND | No checkout by that checkout_id that your key may see | Check the id |
404 | 3001 | CHARGE_NOT_FOUND | No charge by that charge_id that your key may see | Check the id |
409 | 2861 | REFUND_NOT_ALLOWED | The payment cannot be refunded. data.reason is not_paid, nothing_left, other_refund, platform_payment, test_payment or not_inbound. See What cannot be refunded | Do not retry |
409 | 2862 | REFUND_ALREADY_OPEN | A refund of this payment is already requested or approved | Wait for it to be decided, then ask again if something is left |
422 | 2702 | INVALID_AMOUNT | A part refund that is not a multiple of 100 | Send whole units, or leave amount out to refund all that is left |
422 | 2863 | REFUND_AMOUNT_TOO_HIGH | amount is more than is left to refund. data.refundable is what is left, in minor units | Send data.refundable or less |
422 | 3015 | IDEMPOTENCY_KEY_REUSED | The Idempotency-Key was used with a different body | Use a new key, or resend the original body |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over the rate limit below | Wait Retry-After seconds |
503 | 2782 | AUTHN_UNAVAILABLE | The key could not be checked | Retry with the same key and body |
Rate limit
120 requests a minute per account, shared by the three refund routes. Over it: 429, code 1804, with Retry-After and data.retryAfter in seconds. MOOKHPay can raise it for your account; see Raising your limits.