> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Return a received Pix

> Return all or part of a Pix your institution received, as a Pix return on SPI, with Pix Lerian and Lerian SPI.

Return all or part of a Pix that one of your accounts received.

> [!NOTE]
>
> This flow is a suggested reading of the BACEN manuals for Pix. The manuals prevail over this page. Your institution, as the participant, validates the flow and implements it on the Lerian APIs. See [how to read the diagrams](https://docs.lerian.studio/en/diagrams/introduction.md).

## Participants

***

* **Your institution.** The Pix participant that received the original Pix. It calls the Pix Lerian API and receives its events.
* **Pix Lerian.** Connects Midaz to Lerian SPI. It posts the return in Midaz and hands it to Lerian SPI.
* **Midaz.** The ledger that holds the account that received the original Pix.
* **Lerian SPI.** Exchanges the Pix messages with SPI.
* **SPI.** The BACEN instant payment system. It settles the return.

## Before you start

***

* The original Pix is a received transfer in `COMPLETED`. See [Send and receive Pix](https://docs.lerian.studio/en/diagrams/native-rails/send-and-receive-pix.md).
* Your systems receive the Pix Lerian events. See [Pix Lerian events](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-events.md).

## Diagram

***

![Return a received Pix](https://mintcdn.com/lerian-49cb71fc/qgZtW0Vn3HlCLdfR/images/en/d2/id-return-a-received-pix.svg?fit=max\&auto=format\&n=qgZtW0Vn3HlCLdfR\&q=85\&s=f74ea84c1f6712ef8a8f660e90c19d63)

## Steps

***

| # | From | To | Message | Lerian API | What happens |
| - | - | - | - | - | - |
| 1 | Your institution | Pix Lerian | Lerian API | [`POST /transfers/{id}/refunds`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/spi/create-refund) | Request the return of the original transfer, with the amount, `reasonCode` and `reason`. Send the `X-Idempotency` header. |
| 2 | Pix Lerian | Pix Lerian | Internal step | | Pix Lerian checks that the original transfer can take a return of this amount. |
| 3 | Pix Lerian | Midaz | Internal call | | Pix Lerian debits the account that received the original Pix. The transaction credits `@external/BRL`. |
| 4 | Pix Lerian | Lerian SPI | Internal call | | Pix Lerian sends the return. |
| 5 | Lerian SPI | SPI | `pacs.004` | | Lerian SPI sends the return to SPI. |
| 6 | Pix Lerian | Your institution | Lerian API | Response to step 1 | Pix Lerian answers `201` with the return in `PROCESSING`. |
| 7 | SPI | Lerian SPI | `pacs.002` | | SPI reports the settlement or the rejection of the return. |
| 8 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the result to Pix Lerian. |
| 9 | Pix Lerian | Midaz | Internal call | | Only for a rejected return: Pix Lerian reverts the debit with a new reverse transaction. |
| 10 | Pix Lerian | Your institution | Lerian API | Event `refund.completed` | The return settled. For a return that failed, the event is `refund.failed`. |

## Rules

***

* `reasonCode` is one of `MD06` (return of the original Pix), `SL02` (return of a Pix Saque or Pix Troco), `FR01` (fraud, MED) or `BE08` (operational flaw, MED).
* The returns of one transfer add up to the original amount at most.
* BACEN accepts a return within 90 days of the settlement of the original Pix.
* A return is a new Pix and a new transaction in Midaz. The original transfer and its transaction do not change.

## How you know it finished

***

Pix Lerian publishes `refund.completed` or `refund.failed`. [`GET /refunds/{id}`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/spi/get-refund) shows the same result.

## What can go wrong

***

| Situation | What you see | What to do |
| - | - | - |
| The rail refused the return. | `422`, code `PIX-0013`. | The return did not leave. Check the request before you send a new one. |
| The request ended with an error, or no answer arrived. | `5xx`, `409` with code `PIX-0406`, or a timeout. | The return can still be `PROCESSING`. List the returns of the transfer with [`GET /refunds`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/spi/list-refunds) and `transferId`. Send a new request only when the return is not there. |

The [Pix Lerian error list](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/pix-lerian-error-list.md) describes each code.

## Related

***

* [Send and receive Pix](https://docs.lerian.studio/en/diagrams/native-rails/send-and-receive-pix.md)
* [Report a fraud and recover funds](https://docs.lerian.studio/en/diagrams/native-rails/report-a-fraud-and-recover-funds.md)
* [Use SPI with Pix Lerian](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-spi.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.