Skip to content

List refunds ​

Lists the refunds on your account, newest first, including those asked for in the hub. Filter by status, or by the checkout or charge they refund.

Endpoint ​

GET /v1/payments/merchant/refunds
AuthSecret key
Scoperefunds:write
Switched onPer deployment (REFUND_API_ENABLED). Where it is off, the route answers 404

Headers ​

HeaderRequiredValue
AuthorizationYesBearer mkp_…

Parameters ​

Query. Unknown parameters are refused. The filters combine.

NameTypeRequiredConstraints
statusstringNoOne or more of requested, approved, refunded and declined, comma separated
checkout_idstringNoOnly refunds of this checkout
charge_idstringNoOnly refunds of this direct charge
limitintegerNo1 to 100. Default 20
starting_afterstringNoThe last id of the previous page, with the same filters

To page through every refund, pass the last id of each page as starting_after until has_more is false. Refunds made while you page appear at the top and are not in the pages that follow. See Pagination.

Example request ​

sh
curl "https://payments-ke-staging.mookhpay.co/v1/payments/merchant/refunds?checkout_id=cs_ke_3f9a1c7e5b2d4a8e6c0b91d7" \
  -H "Authorization: Bearer $MOOKHPAY_SECRET_KEY"
js
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";

export async function allRefunds(filters = {}) {
  const refunds = [];
  let after;
  for (;;) {
    const query = new URLSearchParams({ ...filters, limit: "100" });
    if (after) query.set("starting_after", after);
    const res = await fetch(`${BASE}/refunds?${query}`, {
      headers: { Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}` },
    });
    const answer = await res.json();
    if (!answer.ok) throw new Error(`${res.status} ${answer.code}: ${answer.description}`);
    refunds.push(...answer.data.refunds);
    if (!answer.data.has_more) return refunds;
    after = answer.data.refunds.at(-1).id;
  }
}

console.log(await allRefunds({ status: "requested" }));
python
import os

import requests

BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"


def all_refunds(**filters):
    refunds, after = [], None
    while True:
        params = {**filters, "limit": 100}
        if after:
            params["starting_after"] = after
        res = requests.get(
            f"{BASE}/refunds",
            params=params,
            headers={"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}"},
            timeout=15,
        )
        answer = res.json()
        if not answer["ok"]:
            raise RuntimeError(f"{res.status_code} {answer['code']}: {answer['description']}")
        refunds.extend(answer["data"]["refunds"])
        if not answer["data"]["has_more"]:
            return refunds
        after = answer["data"]["refunds"][-1]["id"]


print(all_refunds(status="requested"))
php
<?php
function all_refunds(array $filters = []): array
{
    $base = 'https://payments-ke-staging.mookhpay.co/v1/payments/merchant';
    $refunds = [];
    $after = null;
    while (true) {
        $query = $filters + ['limit' => 100];
        if ($after !== null) {
            $query['starting_after'] = $after;
        }
        $ch = curl_init("$base/refunds?" . http_build_query($query));
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 15,
            CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('MOOKHPAY_SECRET_KEY')],
        ]);
        $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']}");
        }
        array_push($refunds, ...$answer['data']['refunds']);
        if (!$answer['data']['has_more']) {
            return $refunds;
        }
        $after = end($answer['data']['refunds'])['id'];
    }
}

print_r(all_refunds(['status' => 'requested']));

Response ​

200 OK with description Refunds.

json
{
  "ok": true,
  "description": "Refunds",
  "data": {
    "refunds": [
      {
        "id": "rf_5b1e8c2d7a4f90b3e6a1c2d8",
        "status": "refunded",
        "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": "UAB3K9L2MP",
        "method": "mobile",
        "requested_via": "app",
        "requested_at": "2026-11-21T07:40:12.000Z",
        "reviewed_at": "2026-11-21T07:58:30.000Z",
        "refunded_at": "2026-11-21T08:00:00.000Z"
      }
    ],
    "has_more": false
  }
}

Response fields ​

FieldTypeMeaning
refundsarrayUp to limit refund objects, newest first
has_morebooleantrue when there is at least one more refund after the last one here

Errors ​

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAAn unknown query parameter, a status with a value that is not one of the four, or limit outside 1 to 100 (limit is 1 to 100)Fix the query
4003012PLATFORM_CURSOR_INVALIDstarting_after is not one of your refundsUse an id from the previous page
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
4291804RATE_LIMIT_EXCEEDEDOver the rate limit belowWait Retry-After seconds
5032782AUTHN_UNAVAILABLEThe key could not be checkedRetry

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.

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