Skip to content

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
AuthSecret key
Scoperefunds:write
Switched onPer 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 ​

HeaderRequiredValue
AuthorizationYesBearer mkp_…
Idempotency-KeyYes1 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-TypeYesapplication/json

Parameters ​

Body. Unknown fields are refused. Send exactly one of checkout_id and charge_id.

NameTypeRequiredConstraints
checkout_idstringOne of the twoA hosted checkout your key made or was paid by, cs_<country>_…
charge_idstringOne of the twoA direct charge your key made, ch_<country>_…
amountintegerNoMinor 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
reasonstringNoWhy 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 same Idempotency-Key and 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, answers 422 and code 3015. A second part refund of one payment is a new refund and needs a new key, once the first is refunded or declined.

Errors ​

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAThe 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 missingFix the request
4003014IDENTITY_HEADER_REFUSEDThe request carries a session or identity headerRemove it
4012781API_KEY_INVALIDMissing, malformed, unknown or revoked keyCheck the key
4032941API_KEY_SCOPE_REQUIREDThe key lacks refunds:writeHave an Owner replace the key with one that has it
4033042API_KEY_IP_NOT_ALLOWEDThe account has allowed addresses and the call came from another addressCall from a listed address
4042783CHECKOUT_NOT_FOUNDNo checkout by that checkout_id that your key may seeCheck the id
4043001CHARGE_NOT_FOUNDNo charge by that charge_id that your key may seeCheck the id
4092861REFUND_NOT_ALLOWEDThe payment cannot be refunded. data.reason is not_paid, nothing_left, other_refund, platform_payment, test_payment or not_inbound. See What cannot be refundedDo not retry
4092862REFUND_ALREADY_OPENA refund of this payment is already requested or approvedWait for it to be decided, then ask again if something is left
4222702INVALID_AMOUNTA part refund that is not a multiple of 100Send whole units, or leave amount out to refund all that is left
4222863REFUND_AMOUNT_TOO_HIGHamount is more than is left to refund. data.refundable is what is left, in minor unitsSend data.refundable or less
4223015IDEMPOTENCY_KEY_REUSEDThe Idempotency-Key was used with a different bodyUse a new key, or resend the original body
4291804RATE_LIMIT_EXCEEDEDOver the rate limit belowWait Retry-After seconds
5032782AUTHN_UNAVAILABLEThe key could not be checkedRetry 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.

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