> ## 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.

# Authorize and pay with Pix Automático

> As the payer's institution, accept a Pix Automático authorization request and pay its scheduled debits from a Midaz account, with Pix Lerian and Lerian SPI.

Let your customer authorize a recurring Pix, and pay each scheduled debit from the customer's account.

> [!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 of the payer. It shows each request to the payer and sends the payer's decision.
* **Pix Lerian.** Keeps the authorizations and the scheduled debits of the payer. It debits the payer's account in Midaz on the settlement date.
* **Midaz.** The ledger that holds the payer's account.
* **Lerian SPI.** Exchanges the Pix Automático messages and the payments with SPI.
* **SPI.** The BACEN instant payment system. It carries the messages of the receiver's institution and settles each payment.

## Before you start

***

* The payer's account exists in Midaz, is active, and has a holder.
* Your backend checks that the payer can use the account. Send that account in `X-Account-Id`. See [Use Pix Automático with Pix Lerian](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-pix-automatico.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

***

### Authorize

![Authorize and pay with Pix Automático: Authorize](https://mintcdn.com/lerian-49cb71fc/qgZtW0Vn3HlCLdfR/images/en/d2/id-authorize-and-pay-pix-automatico-1.svg?fit=max\&auto=format\&n=qgZtW0Vn3HlCLdfR\&q=85\&s=0a5706681ca0a7dd4788c49770f55517)

| # | From | To | Message | Lerian API | What happens |
| - | - | - | - | - | - |
| 1 | SPI | Lerian SPI | `pain.009` | | The receiver's institution asks for an authorization. |
| 2 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the request to Pix Lerian. |
| 3 | Pix Lerian | Pix Lerian | Internal step | | Pix Lerian finds the payer's account. |
| 4 | Pix Lerian | Your institution | Lerian API | Event `pix_auto_request.received` | The request waits for the payer's decision. Read it with [`GET /payer/authorization-requests/{authorization_request_id}`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/pix-automatico/get-authorization-request). |
| 5 | Your institution | Your institution | Internal step | | Show the request to the payer, and get the decision. |
| 6 | Your institution | Pix Lerian | Lerian API | [`POST /payer/authorization-requests/{authorization_request_id}/decide`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/pix-automatico/decide-authorization-request) | Send `decision` `ACCEPT`, with the payer's parameters if any. Send the `X-Idempotency` header. |
| 7 | Pix Lerian | Your institution | Lerian API | Response to step 6 | Pix Lerian answers `202` with the request in `ACCEPTED` and the `authorizationId`. The authorization is `AWAITING_CONCLUSION`. Pix Lerian publishes `pix_auto_authorization.granted` and `pix_auto_authorization.awaiting_conclusion`. |
| 8 | Pix Lerian | Lerian SPI | Internal call | | Pix Lerian sends the acceptance. |
| 9 | Lerian SPI | SPI | `pain.012` | | Lerian SPI sends the acceptance to the receiver's institution. |
| 10 | SPI | Lerian SPI | `pain.012` | | The receiver's institution concludes the authorization. |
| 11 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the conclusion to Pix Lerian. |
| 12 | Pix Lerian | Your institution | Lerian API | Event `pix_auto_authorization.concluded` | The event carries the outcome. With `APPROVED`, the authorization is active. |

### Pay the scheduled debits

![Authorize and pay with Pix Automático: Pay the scheduled debits](https://mintcdn.com/lerian-49cb71fc/qgZtW0Vn3HlCLdfR/images/en/d2/id-authorize-and-pay-pix-automatico-2.svg?fit=max\&auto=format\&n=qgZtW0Vn3HlCLdfR\&q=85\&s=a3d35ef374a8a650fc76ba60b850bd3e)

| # | From | To | Message | Lerian API | What happens |
| - | - | - | - | - | - |
| 1 | SPI | Lerian SPI | `pain.013` | | The receiver's institution sends the instruction for one debit. |
| 2 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the instruction to Pix Lerian. |
| 3 | Pix Lerian | Pix Lerian | Internal step | | Pix Lerian checks the instruction against the authorization, and schedules the debit. |
| 4 | Pix Lerian | Lerian SPI | Internal call | | Pix Lerian accepts or refuses the instruction. |
| 5 | Lerian SPI | SPI | `pain.014` | | Lerian SPI sends the answer to the receiver's institution. |
| 6 | Pix Lerian | Pix Lerian | Internal step | | On the settlement date, between 00:00 and 08:00, Pix Lerian starts the debit. |
| 7 | Pix Lerian | Midaz | Internal call | | Pix Lerian debits the payer's account. The transaction credits `@external/BRL`. |
| 8 | Pix Lerian | Lerian SPI | Internal call | | Pix Lerian sends the payment. |
| 9 | Lerian SPI | SPI | `pacs.008` | | Lerian SPI sends the payment order to SPI. |
| 10 | SPI | Lerian SPI | `pacs.002` | | SPI reports the settlement or the rejection of the payment. |
| 11 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the result to Pix Lerian. |
| 12 | Pix Lerian | Midaz | Internal call | | Only for a rejected payment: Pix Lerian reverts the debit with a new reverse transaction. |
| 13 | Pix Lerian | Your institution | Lerian API | Event `outbound_transfer.completed` | The transfer has `initiationType` `AUTO`. For a rejected payment, the event is `outbound_transfer.rejected`. |

## Rules

***

### Authorize

* To refuse, send `decision` `REJECT` with `rejectionReason`. Pix Lerian publishes `pix_auto_request.rejected`. The receiver's institution does not answer a rejection.
* When no conclusion arrives within one hour, Pix Lerian publishes `pix_auto_authorization.conclusion_timed_out`. The authorization still waits for the conclusion.

### Pay the scheduled debits

* Pix Lerian refuses an instruction above the maximum amount of the payer (`AM02`), or one that differs from a fixed amount (`AM09`).
* List the scheduled debits with [`GET /payer/scheduled-payments`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/pix-automatico/list-scheduled-payments).
* The payer can cancel one scheduled debit with [`POST /payer/scheduled-payments/{scheduled_payment_id}/cancel`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/pix-automatico/cancel-scheduled-payment) until 00:00 of the settlement date. The authorization stays active.
* When the window of 00:00 to 08:00 closes without a settlement, Pix Lerian publishes `pix_auto_scheduled_payment.settlement_deferred`. It tries again on the same day, between 18:00 and 21:00.
* The times on this page are in the America/Sao\_Paulo time zone.

## How you know it finished

***

* **Authorize.** Pix Lerian publishes `pix_auto_authorization.concluded` with `APPROVED`.
* **Pay the scheduled debits.** For each debit, Pix Lerian publishes `outbound_transfer.completed` with `initiationType` `AUTO`.

## What can go wrong

***

| Situation | What you see | What to do |
| - | - | - |
| The conclusion does not arrive within one hour. | Event `pix_auto_authorization.conclusion_timed_out`. | Tell the payer that the authorization is not active yet. |
| The cancellation of a debit arrives at or after 00:00 of the settlement date. | `409`, code `PIX-0825`. | The debit stays scheduled. |
| The debit did not settle that day, and the authorization allows more attempts. | Event `pix_auto_scheduled_payment.settlement_retry_permitted`. | Tell the payer that more attempts can follow in the next days. |
| The debit did not settle that day, and the authorization allows no more attempts. | Event `pix_auto_scheduled_payment.settlement_failed`. | Tell the payer that Pix Automático did not pay this debit. |
| The answer to a call does not arrive. | No answer, or a timeout. | Send the same call again with the same `X-Idempotency` key. |

## Related

***

* [Send and receive Pix](https://docs.lerian.studio/en/diagrams/native-rails/send-and-receive-pix.md)
* [Use Pix Automático with Pix Lerian](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-pix-automatico.md)


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