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

# Charge with a dynamic QR code

> Create a Pix charge with a dynamic QR code, and receive its payment into a Midaz account, with Pix Lerian and Lerian SPI.

Create a Pix charge with a dynamic QR code, and know when the payer pays it.

> [!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 receiver. It calls the Pix Lerian API, shows the QR code, and receives the events.
* **Pix Lerian.** Creates the charge and tracks its status. It credits the payment in Midaz.
* **Midaz.** The ledger that holds the account that receives the payment.
* **Lerian SPI.** Registers the charge, serves it to the payer's institution, and exchanges the Pix messages with SPI.
* **SPI.** The BACEN instant payment system. It settles the payment.
* **Payer's institution.** The Pix participant of the payer. It reads the charge and sends the payment.

## Before you start

***

* The account that receives the payment has an active Pix key that your institution registered with Pix Lerian.
* Your systems receive the Pix Lerian events. See [Pix Lerian events](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-events.md).

## Diagram

***

![Charge with a dynamic QR code](https://mintcdn.com/lerian-49cb71fc/qgZtW0Vn3HlCLdfR/images/en/d2/id-charge-with-a-dynamic-qr-code.svg?fit=max\&auto=format\&n=qgZtW0Vn3HlCLdfR\&q=85\&s=50596cb2fae6582aeab55911e3cd16a1)

## Steps

***

| # | From | To | Message | Lerian API | What happens |
| - | - | - | - | - | - |
| 1 | Your institution | Pix Lerian | Lerian API | [`POST /collections/immediate`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/cob/create-immediate-collection) | Create the charge with your `txId`, the Pix key, the amount and the expiration. Send the `X-Idempotency` header. |
| 2 | Pix Lerian | Pix Lerian | Internal step | | Pix Lerian checks that the Pix key is active. |
| 3 | Pix Lerian | Lerian SPI | Internal call | | Pix Lerian registers the charge with Lerian SPI. |
| 4 | Pix Lerian | Your institution | Lerian API | Response to step 1 | Pix Lerian answers `201` with the charge in `ACTIVE`, the QR code content in `emvPayload`, and its location. |
| 5 | Your institution | Your institution | Internal step | | Show the QR code to the payer. |
| 6 | Payer's institution | Lerian SPI | HTTPS | | The payer's institution reads the charge at its location. Lerian SPI answers with the signed charge. |
| 7 | Payer's institution | SPI | `pacs.008` | | The payer's institution sends the payment. |
| 8 | SPI | Lerian SPI | `pacs.008` | | The payment arrives at your institution. |
| 9 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the arriving Pix to Pix Lerian. Pix Lerian accepts it, and SPI settles it, as in [Receive a Pix](https://docs.lerian.studio/en/diagrams/native-rails/send-and-receive-pix.md). |
| 10 | Pix Lerian | Midaz | Internal call | | After the settlement, Pix Lerian credits the account. |
| 11 | Lerian SPI | Lerian SPI | Internal step | | After the settlement, Lerian SPI marks the charge as paid. |
| 12 | Lerian SPI | Pix Lerian | Internal call | | Lerian SPI passes the paid charge to Pix Lerian. |
| 13 | Pix Lerian | Your institution | Lerian API | Event `collection.paid` | The charge is `COMPLETED`. |

## Rules

***

* A charge creates no transaction in Midaz. The money arrives as a received Pix, with its own `inbound_transfer.completed` event.
* A new charge needs a new `X-Idempotency` key and a new `txId`.
* A due-date charge follows the same steps. Create it with [`POST /collections/duedate`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/cob/create-due-date-collection). Its `collection.paid` event has `type` `DUE_DATE`.
* To end an unpaid immediate charge, cancel it with [`DELETE /collections/immediate/{id}`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/cob/cancel-immediate-collection). The charge becomes `CANCELLED`.

## How you know it finished

***

Pix Lerian publishes `collection.paid`, and [`GET /collections/immediate/{id}`](https://docs.lerian.studio/en/reference/interfaces/pix-lerian/cob/get-immediate-collection) shows the charge in `COMPLETED`.

## What can go wrong

***

| Situation | What you see | What to do |
| - | - | - |
| The Pix key is unknown, or it is not active. | Pix Lerian refuses the charge. | Use an active Pix key of the receiving account. |
| The answer to the request does not arrive. | No answer, or a timeout. | Send the same request again with the same `X-Idempotency` key. |

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)
* [Use COB with Pix Lerian](https://docs.lerian.studio/en/interfaces/pix-lerian/pix-lerian-cob.md)


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