# Refunds (/docs/refunds)

> Pre-release: the public API is not live yet and has no base URL. Routes and fields are in the OpenAPI contract, at /openapi.yaml.

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 [#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](/openapi.yaml), under these names.

## What a refund takes [#what-a-refund-takes]

- **A key with the `refunds:write` scope.** A key without it gets `403` with the `insufficient_scope` code. See [What a key can do](/docs/authentication#what-a-key-can-do). Reading and listing refunds ask for another scope, `refunds:read`.
- **A `paid` charge.** A charge that was never paid answers `409` with the `charge_not_paid` code, and one that is `disputed`, `409` with the `charge_disputed` code: see [Disputes](/docs/disputes).
- **One refund per charge.** A charge that was refunded, or has a refund in progress, answers `409` with the `charge_already_refunded` code.
- **At most 90 days since the payment.** That is the window in which PIX accepts a return. After it the answer is `409` with the `refund_window_closed` code.
- **Balance to cover it.** What the refund takes comes out of the balance of the environment: see [The amount](/docs/refunds#the-amount). Without enough balance the answer is `409` with the `insufficient_balance` code, and nothing is refunded.

A refusal moves nothing: no refund is created and the balance stays as it was.

## The amount [#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 [#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 of `createRefund` never says how it ended: follow the [webhooks](/docs/webhooks), or read the refund.
- After a `failed` refund the charge is still `paid`, and it can be refunded again, with a new `Idempotency-Key`.
- Handle an unknown state without failing. In the contract `status` is an open string, not an enum, for this reason.

## Events [#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 [#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 [#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](/docs/charges#identifiers).

## Refunds of another environment [#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.