Refunds
Sending the amount of a paid charge back to the payer: what it takes, how it ends, and how to retry safely.
A refund sends the amount of a paid charge back to the payer, by PIX. You ask for the refund, what it takes leaves your balance at once, and the bank returns the amount to the payer shortly after.
Operations
| Operation in the contract | What it does |
|---|---|
createRefund | Asks for the refund of a charge. Requires Idempotency-Key and the refunds:write scope |
getRefund | Returns one refund by its id |
listRefunds | Returns the refunds of the environment, newest first, paginated by cursor |
The route, the fields and the limits of each operation are in the OpenAPI contract, under these names.
What a refund takes
- A key with the
refunds:writescope. A key without it gets403with theinsufficient_scopecode. See What a key can do. Reading and listing refunds ask for another scope,refunds:read. - A
paidcharge. A charge that was never paid answers409with thecharge_not_paidcode, and one that isdisputed,409with thecharge_disputedcode: see Disputes. - One refund per charge. A charge that was refunded, or has a refund in progress, answers
409with thecharge_already_refundedcode. - At most 90 days since the payment. That is the window in which PIX accepts a return. After it the answer is
409with therefund_window_closedcode. - Balance to cover it. What the refund takes comes out of the balance of the environment: see The amount. Without enough balance the answer is
409with theinsufficient_balancecode, and nothing is refunded.
A refusal moves nothing: no refund is created and the balance stays as it was.
The amount
- A refund is always for the full amount of the charge. There is no partial refund, and the payer gets the full amount back.
- By default the fee of the charge is returned with the refund. The refund takes from your balance only what the charge left there, and the platform gives back the fee. A charge covers its own refund.
- The rule is a setting of your account. An account can be set to leave the fee with the platform. Then the full amount comes out of your balance, and the balance left by a charge does not cover its own refund: the difference is the fee.
- A refund follows the rule in force when it was asked for. Changing the setting does not change a refund that is
pending.
States
The state is the status field.
| State | Meaning |
|---|---|
pending | What the refund takes left your balance, and the bank has not confirmed the return yet |
succeeded | The amount reached the payer, and the charge is refunded. Final |
failed | The bank did not make the return. What the refund took is back in your balance. Final |
- A refund is created
pending. The answer ofcreateRefundnever says how it ended: follow the webhooks, or read the refund. - After a
failedrefund the charge is stillpaid, and it can be refunded again, with a newIdempotency-Key. - Handle an unknown state without failing. In the contract
statusis an open string, not an enum, for this reason.
Events
| Event | When | data.id |
|---|---|---|
refund.created | The refund was asked for, and what it takes left your balance | The refund |
refund.succeeded | The amount reached the payer | The refund |
refund.failed | The bank did not make the return, and what the refund took is back in your balance | The refund |
charge.refunded | The charge became refunded, together with refund.succeeded | The charge |
To know which charge a refund event is about, read the refund with getRefund: charge_id says it.
Idempotency
Asking for a refund requires the Idempotency-Key header: a value that you choose, unique for each refund you intend to ask for. A UUID is fine.
| You repeat the request with | Result |
|---|---|
The same Idempotency-Key and the same charge | The refund that already exists is returned, as it is now. No new refund is asked for |
The same Idempotency-Key and another charge | 422 with the idempotency_key_reused code |
A different Idempotency-Key and the same charge | 409 with the charge_already_refunded code, unless the earlier refund failed |
- The key is unique per environment, among refunds. It does not collide with the key of a charge.
- The key never expires.
- Simultaneous requests for the same charge ask for a single refund. The ones with the same key receive it, and the others get
charge_already_refunded. - If a request fails with a network error or a timeout, repeat it with the same key. It is safe: the money never goes back twice.
Identifiers
The id of a refund has the same format as the one of a charge, with the prefix rfd. For example, rfd_01h455vb4pex5vsknk084sn02q. See Identifiers.
Refunds of another environment
Asking for a refund that does not belong to the environment of your key returns 404 with the refund_not_found code, exactly as if it did not exist. Asking to refund a charge of another environment returns 404 with the charge_not_found code.