Refunds
Send money back to a customer who paid you, in full or in part.
A refund sends money back to the number that paid a collection. It goes out as a payout to that number, and you cannot name another one. Refund the whole payment or a part of it, and refund one payment more than once until the parts add up to its amount.
Create a refund
Call Create a refund with a key that has the refunds.write scope:
curl -X POST "https://api-malipo.flex.co.tz/api/v1/refunds" \
-H "Authorization: Bearer <token>" \
-H "Idempotency-Key: 2c9e7f1a-4d6b-4a8e-b3c5-7d9f1e2a4b6c" \
-H "Content-Type: application/json" \
-d '{
"payment": "0b6f3c1e-8f2a-4a51-9a57-6d1f0c2b7e93",
"amount": 4000,
"reason": "requested_by_customer"
}'| Field | Meaning |
|---|---|
payment | The ID of a SUCCEEDED collection of yours. |
amount | What the customer gets, an integer in the minor unit (4000 is TZS 4,000). Leave it out to refund everything not yet refunded. |
reason | duplicate or requested_by_customer. Any other value is refused. |
lines | Only for a payment of an invoice: 1 to 100 invoice lines to take back, each with an invoiceLine ID and an amount. The refund is the sum of the lines. If you also send amount, it must be that sum. |
You get the refund:
{
"id": "6d2b1f4e-3c55-4e0a-b1c6-0f6a9d7e5a21",
"status": "pending",
"payment": "0b6f3c1e-8f2a-4a51-9a57-6d1f0c2b7e93",
"amount": 4000,
"fee": 1500,
"currency": "TZS",
"reason": "requested_by_customer",
"livemode": false,
"createdAt": "2026-09-29T08:00:00Z",
"transactionCode": null,
"payment_method_details": {
"type": "mobile_money",
"mobile_money": {
"network": "mpesa",
"phone": "25574*****11"
}
}
}Retrieve a refund reads one refund, and
List refunds lists them, newest first. Pass payment to list the refunds
of one payment. Reading refunds needs the payments.read scope.
payment_method_details names the network and the masked number the refund is paid to, which is the number that paid.
transactionCode is the network's own code for the payout. It stays null until the refund has succeeded.
Statuses
| Status | Meaning |
|---|---|
pending | The payout to the customer has not finished. |
succeeded | The customer received the money. |
failed | The payout failed or expired. failureCode says why, such as INSUFFICIENT_BALANCE or EXPIRED. You can refund that amount again. |
Your webhook endpoint gets refund.created when you create the refund, with status pending, and
refund.updated when the status becomes succeeded or failed. Both carry the refund as the API shows it. The payout
behind a refund does not show in your payment list and sends no payment.* events: follow the refund.
Money
- The refund's
amountgoes to the customer. The payoutfeeis charged to you on top of it. The fee of the original payment is not returned. Preview the fee of a payout of the same amount to see it before you refund. - When you create a refund, your available balance must cover the amount plus the fee. If it does not, the request is
refused with
insufficient_balanceand nothing is sent. The amount and the fee are held from your balance when the payout is sent, and the hold is released if the payout fails. - A refund of a payment that bought a subscription period or paid an invoice also reaches billing. See Customer credit for what happens to credit that came from the refunded payment.
Subscriptions and invoices
A refund moves money only. Full or partial, the subscription keeps its status, its plan and its paid period, the invoice
stays paid, and no invoice is created for the refunded amount. Credit the invoice used stays used.
- The invoice gets a credit note with the refunded amount, and your customer is emailed it as their refund document.
- If access should stop, end the subscription with
Cancel a subscription and
atPeriodEnd: false. In the dashboard, a fully refunded or reversed invoice has an "End subscription" button.
A reversal works the same way: the money goes back to the customer, and the subscription and the invoice's status stay
as they were. The invoice gets paymentReversedAt and you get invoice.payment_reversed. Its credit note is your
record and is not sent to the customer. A reversed payment cannot be refunded, because only a SUCCEEDED collection
can.
Rules
- Only a
SUCCEEDEDcollection can be refunded. - A payment can be refunded for 1 year after it succeeded.
- The pending and succeeded refunds of a payment add up to at most its amount.
- A refund goes out as a payout, so it works only for a payment on a network that can pay out. For any other network the
request is refused with
refund_not_supported. - A refund of a payment that paid an invoice can also be taken by invoice line with
lines, for example only the fee line. A refund by line changes nothing on the subscription, like any other refund. - A person who refunds in the dashboard confirms with a two-factor code from the last 5 minutes. A request with an API key does not.
Errors
| Status | Code | Why |
|---|---|---|
400 | parameter_invalid | payment or reason is missing, the reason is not one of the two, the amount is not above zero, or the Idempotency-Key is not valid. |
400 | amount_invalid | The amount has a decimal point. See Money. |
400 | payment_not_refundable | The payment is not a SUCCEEDED collection. The message names its kind and status. |
400 | refund_window_passed | The payment succeeded more than 1 year ago. |
400 | refund_not_supported | The payment's network cannot send a refund yet. |
400 | amount_too_large | The amount is more than what is left to refund. This includes credit from the payment that an invoice already used. The message gives the most you can refund. |
400 | insufficient_balance | Your available balance does not cover the refund and its payout fee. |
400 | idempotency_key_reused | The Idempotency-Key was used for a different request. |
403 | permission_denied | The key lacks refunds.write, or refunds are not available to you (contact support). |
404 | resource_missing | You have no payment with this ID in this mode. |
409 | idempotency_request_in_progress | A request with this key is still running. Retry with the same key after a short wait. |
503 | service_unavailable | The refund could not be started and nothing was stored. Try again with the same key. |
Retry safely
Send the same request with the same Idempotency-Key and the customer is refunded once. You get the same refund back
with the header Idempotent-Replayed: true. See Idempotency.
Test mode
In test mode the refund goes to the number that paid and succeeds a few seconds later. See Test mode.