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

# Register a payroll loan

> How the averbação of a payroll loan and the contract's documentation reach Dataprev through Lerian.

Register the payroll deduction of a loan at Dataprev, then send the contract's documentation.

> [!NOTE]
>
> This flow is a suggested interpretation of the Dataprev manuals for Crédito do Trabalhador. The manuals prevail over this page. Your institution 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 financial institution that makes the loan.
* **Lerian.** Lerian Consignado. It exchanges the requests with Dataprev, and exposes the API and the events your institution uses.
* **Dataprev.** Runs the Crédito do Trabalhador system: the loan auctions and the registry of payroll loans.

## Diagram

***

![Register a payroll loan](https://mintcdn.com/lerian-49cb71fc/KypD0TIKUCqZ014J/images/en/d2/id-register-a-payroll-loan.svg?fit=max\&auto=format\&n=KypD0TIKUCqZ014J\&q=85\&s=10e234479a3610920f44d18b5ba2ebb3)

## Steps

***

| # | From | To | Message | Lerian API | What happens |
| - | - | - | - | - | - |
| 1 | Your institution | Lerian | Lerian API | [`POST /v1/consignado/contracts/{numero_contrato}/averbacao`](https://docs.lerian.studio/en/reference/rails/consignado/averbar-consignado-contract) | Send the averbação of the contract, with no document. You choose `numero_contrato`: 2 to 15 letters or digits. |
| 2 | Lerian | Dataprev | Dataprev API | | Lerian sends the averbação to Dataprev (Manual 003). |
| 3 | Dataprev | Lerian | Dataprev API | | Dataprev accepts the averbação and holds the payroll-deduction mandate. |
| 4 | Lerian | Your institution | Lerian API | [`POST /v1/consignado/contracts/{numero_contrato}/averbacao`](https://docs.lerian.studio/en/reference/rails/consignado/averbar-consignado-contract) | The operation answers `attachment_pending`: the contract waits for its documentation. |
| 5 | Lerian | Your institution | Lerian API | Event `consignado.averbacao.accepted` | Lerian publishes the accepted averbação. |
| 6 | Your institution | Lerian | Lerian API | [`POST /v1/consignado/contracts/{numero_contrato}/ccb-attachment`](https://docs.lerian.studio/en/reference/rails/consignado/attach-consignado-ccb) | Send the documentation under its own `X-Idempotency` key: the signed CCB, the signature evidence and `data_hora_assinatura`, the instant the worker signed. |
| 7 | Lerian | Dataprev | Dataprev API | | Lerian sends the contract information to Dataprev (Manual 004). |
| 8 | Dataprev | Lerian | Dataprev API | | Dataprev accepts the documentation and returns its operation hash. |
| 9 | Lerian | Your institution | Lerian API | [`POST /v1/consignado/contracts/{numero_contrato}/ccb-attachment`](https://docs.lerian.studio/en/reference/rails/consignado/attach-consignado-ccb) | The operation answers `confirmed`. |
| 10 | Lerian | Your institution | Lerian API | Event `consignado.averbacao.confirmed` | Lerian publishes the confirmed averbação. |

The Dataprev Manual 004 gives your institution 7 days after the averbação to send the documentation. [`GET /v1/consignado/contracts/{numero_contrato}/averbacao`](https://docs.lerian.studio/en/reference/rails/consignado/get-consignado-contract-averbacao-operation) shows `documentation_due_at` and `documentation_overdue`.

A contract takes one accepted documentation. Lerian reports the outstanding balance of the contract to Dataprev from the accepted averbação on.

When Dataprev refuses the averbação with a code that Lerian recognizes, the operation reads `rejected`, and Lerian publishes `consignado.averbacao.rejected`. When Dataprev answers the averbação with any other code, or its answer does not arrive, the operation reads `averbacao_unknown`. Do not send it again under a new key. Read the averbação, and contact Lerian with the contract number if it stays `averbacao_unknown`.

Documentation sent before Dataprev accepts the averbação answers `409` `AVERBACAO_NOT_ACCEPTED`, and nothing reaches Dataprev. If Dataprev refuses the documentation, the answer is `422` with the Dataprev codes in `upstream`. Send the corrected documentation under a new `X-Idempotency` key. If the call ends without a verdict, send the same documentation again.

## How you know it finished

***

The documentation answers `confirmed`, and Lerian publishes `consignado.averbacao.confirmed`.

## Related

***

* [Answer a payroll loan request](https://docs.lerian.studio/en/diagrams/native-rails/answer-a-payroll-loan-request.md)
* [Refinance a payroll loan](https://docs.lerian.studio/en/diagrams/native-rails/refinance-a-payroll-loan.md)
* [How Lerian Consignado works](https://docs.lerian.studio/en/rails/consignado/how-consignado-works.md)
* [Consignado events](https://docs.lerian.studio/en/reference/events/consignado.md)


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