Refunds
Send money back to the number that paid a collection, in full or in part.
A refund sends money back to the M-Pesa number that paid a collection: a cancelled order, a returned item, a double payment. Endpoint details are in the Refunds reference.
Refunding
curl https://api.autopayke.com/api/v1/refunds \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: rma-2041" \
-H "Content-Type: application/json" \
-d '{
"collection": "col_7Rm2Xq9Lt4Wz8Kb3Np6Vd1Hs",
"amount": 50000,
"reason": "order_cancelled",
"reference": "RMA-2041"
}'| Rule | Why |
|---|---|
| Only paid collections, up to 180 days after payment. | Older money is better sent as a normal payout you choose. |
| Refunds never add up to more than the collection. | Pending and succeeded refunds both count. Two refunds sent at once can't both take the last shillings. |
| Whole shillings only. | M-Pesa pays whole shillings. |
| Paid from your balance, with payout fees. | The collection's own fee isn't returned. |
GET /api/v1/collections/{id} shows amount_refunded, so you can tell how much is left before you refund.
What happens next
- You get
refund.created. The refund is paid as a payout to the payer's number, withrefund_idandcollection_idin its metadata. - When the money arrives you get
refund.succeeded. - If it can't be paid, or comes back, you get
refund.failedwith afailure_code. Its amount is free to refund again.
If your balance can't cover a refund, the request fails with
INSUFFICIENT_BALANCE and no refund is kept. Top up and try again with a new Idempotency-Key.Testing
With an apk_test_ key, collect from +254700000001, then refund that collection. The refund succeeds a few seconds later.