# QI Tech — Investment-as-a-Service › 资产清算

Documentação da QI Tech em texto corrido, para colar em um LLM.
Fonte: https://docs.qitech.com.br
9 página(s).

Índice:
- 插入清算记录 (/zh-Hans/documentation/iaas/liquidacao_ativos/ativos/)
- 删除清算记录 (/zh-Hans/documentation/iaas/liquidacao_ativos/ativos/remocao_liquidacoes)
- Webhooks (/zh-Hans/documentation/iaas/liquidacao_ativos/ativos/webhook)
- Fluxo de liquidação de ativos (/zh-Hans/documentation/iaas/liquidacao_ativos/fluxo_liquidacao)
- 简介 (/zh-Hans/documentation/iaas/liquidacao_ativos/inicio)
- 创建付款批次 (/zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/criacao)
- 关闭付款批次的插入 (/zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/fechamento)
- 清算批次列表 (/zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/listagem)
- 产品 Webhooks (/zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/webhook)

---

# 插入清算记录

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/ativos/

---

### Request

ENDPOINT /settlement/fund_class/FUND_CLASS_KEY/payment_batch/EXTERNAL_ID/settlement
MÉTODO POST

:::info **信息**

清算和资产回购均通过此端点执行。区分两者的字段为 `collection_origin_type`。如果是清算，使用的枚举值为 "borrower" ；如果是回购，则使用 "assignor" 。
:::

```json title='Request Body'
{
    "asset_type": "ccb", 
    "total_value": 130.50,
    "external_id": "931e9437-d025-41ab-bb53-6b94e10fd361",
    "settlement_type": "installment_settlement",
    "contract_number":"0123456789/ABC",
    "installment_number": 1,
    "collection_date": "2025-01-01",
    "collection_origin_type": "borrower"
}
```
:::caution **注意**

字段 `asset_external_id` 和 `contract_number` 是系统中资产的标识符，必须传入其中**一个**，但**不能**同时传入两者。
:::

#### Body Params
`必填字段` *
| 字段                       | 类型   | 描述                                                                     | 字符数      |
|-----------------------------|--------|------------------------------------------------------------------------------|------------|
| `asset_type` *              | string | 指定要传入的资产类型                                                         | 最多 255   |
| `total_value` *             | float  | 资产付款总值（保留两位小数）                                                 | 最多 24    |
| `external_id` *             | string | 集成合作伙伴系统中清算记录的唯一标识键                                       | 最多 50    |
| `settlement_type` *         | string | 指定要传入的清算类型                                                         | 最多 50    |
| `collection_origin_type` *  | string | 确定操作是清算还是回购                                                       | 枚举值     |
| `contract_number`           | string | 与资产相关的合同编号                                                         | 最多 50    |
| `asset_external_id`         | string | 转让时提供的资产在合作伙伴系统中的唯一标识键                                 | 最多 50    |
| `if_code`                   | string | 金融工具代码（B3）                                                           | 最多 50    |
| `participant_control_number`| string | 转让时提供的参与者控制编号                                                   | 最多 50    |
| `installment_number`        | int    | 待付款分期编号                                                               | 最多 24    |
| `installment_maturity_date` | string | 待付款分期的到期日                                                           | ISO 8601   |
| `collection_date`           | string | 付款日期（此字段供集成方控制使用）                                           | ISO 8601   |

:::info **信息**

请求体中的 `external_id` 字段指的是**清算记录**的标识符，而端点中的 `EXTERNAL_ID` 字段指的是**批次**的标识符。
:::

### 资产类型
| 枚举值                | 描述                                          |
|-----------------------|---------------------------------------------|
| `ccb`                 | 银行信用凭证                                  |
| `cce`                 | 出口信用凭证                                  |
| `structured_ccb`      | 结构化银行信用凭证                            |
| `structured_cce`      | 结构化出口信用凭证                            |
| `structured_nce`      | 结构化出口信用票据                            |
| `structured_cci`      | 结构化不动产信用凭证                          |
| `duplicata_mercantil` | 商业汇票                                      |
| `duplicata_servicos`  | 服务汇票                                      |
| `discounted_contract` | 合同                                          |

### 清算类型
| 枚举值                    | 描述                                                                                               |
|---------------------------|----------------------------------------------------------------------------------------------------|
| `asset_settlement`        | 资产全额清算                                                                                       |
| `asset_amortization`      | 资产摊销（宽限期）                                                                                 |
| `fine_payment`            | 资产利息或罚息支付                                                                                 |
| `installment_settlement`  | 分期清算（此时需传入 `installment_number` 字段）                                                   |
| `installment_amortization`| 分期摊销（此时需传入 `installment_number` 字段）                                                   |
| `installment_fine_payment`| 分期利息或罚息支付（此时需传入 `installment_number` 字段）                                         |
| `gloss`                   | 分期冲销（此时需传入 `installment_number` 字段）                                                   |

### collection_origin_type 类型
| 枚举值                    | 描述                                                                                               |
|---------------------------|----------------------------------------------------------------------------------------------------|
| `borrower`                | 操作为清算时使用                                                                                   |
| `assignor`                | 操作为回购时使用                                                                                   |

### Response

STATUS 201

```json title='Request Body'
{
    "status": "validated", 
    "total_value": 130.50,
    "external_id": "931e9437-d025-41ab-bb53-6b94e10fd361",
    "installment_number": 1,
    "type":"installment_settlement",
    "settlement_result":0.0,
    "assets":[
        {
            "asset_key": "f34e9437-d025-41ab-bb53-6b94e10fd361",
            "number_of_units": 1,
            "present_value": 1250.00,
            "installment_face_value":130.50
        }
    ]
}
```

### 可能的错误

STATUS 404

Response Body

```json
{
  "title": "Payment batch not found",
  "description": "The Payment Batch with external_id {payment_batch_external_id} was not found",
  "translation": "O Lote de Pagamento com identificador externo {payment_batch_external_id} não foi encontrado",
  "code": "SET000010"
}

```

---

STATUS 400

Response Body

```json
{
  "title": "Already Exists Settlement With External Id",
  "description": "The settlement with external_id {settlement_external_id} in payment batch with external id {payment_batch_external_id} already exists",
  "translation": "a liquidação com identificador {settlement_external_id} no lote de identificador {payment_batch_external_id} já existe",
  "code": "SET000013"
}

```
---

---

# 删除清算记录

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/ativos/remocao_liquidacoes

---

### Request

ENDPOINT /settlement/fund_class/FUND_CLASS_KEY/payment_batch/EXTERNAL_ID/settlement/SETTLEMENT_EXTERNAL_ID
MÉTODO PUT

```json title='Request Body'
{
    "status": "discarded", 
}
```

:::info **信息**

请求端点中的 `SETTLEMENT_EXTERNAL_ID` 字段指的是**清算记录**的标识符，而 `EXTERNAL_ID` 字段指的是**批次**的标识符。
:::

### Response

STATUS 200

```json title='Request Body'
{ 
    "external_id": "6299b801-a272-4b5a-a766-70ceb8e273a8",
    "status": "discarded"
}
```

### 可能的错误

STATUS 404

Response Body

```json
{
  "title": "Settlement not found",
  "description": "The Settlement with external_id {external_id} was not found",
  "translation": "A Liquidação com identificador externo {external_id} não foi encontrada",
  "code": "SET000011"
}

```

---

STATUS 400

Response Body

```json
{
  "title": "Invalid status",
  "description": "The status given: {status} is not suported.",
  "translation": "O status: {status} não possui suporte.",
  "code": "SET000026"
}

```
---

STATUS 400

Response Body

```json
{
  "title": "Payment Batch Status mismatch",
  "description": "Payment batch of key: {payment_batch_key} with status: {current} was expected to be: {expected}",
  "translation": "O lote de pagamento com chave: {payment_batch_key} e com status: {current} não passou, era esperado que fosse: {expected}",
  "code": "SET000016"
}

```
---

STATUS 400

Response Body

```json
{
  "title": "Settlement type mismatch",
  "description": "The settlement given has the status: {current_status} and was expected: {expected_status}",
  "translation": "A liquidação com status: {current_status} era esperado ter: {expected_status}",
  "code": "SET000024"
}

```

---

# Webhooks

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/ativos/webhook

---
#### 清算完成

STATUS Settled

```json title='Webhook Body'
{
    "data":{
        "payment_batch_external_id": "ac597f90-a13e-4f78-86f0-11c66f5fa6d6",
        "settlement_external_id": "1caff47c-bd05-48b0-a6bc-9569f5070f6b",
        "settlement_status": "settled",
    },
    "webhook_type":"settlement.settlement_status_change",
    "webhook_datetime":"2024-04-23T15:08:30Z"
}
```

---

# Fluxo de liquidação de ativos

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/fluxo_liquidacao

Esta página oferece uma visão holística do fluxo de liquidação de ativos já encarteirados no fundo: desde a criação do lote de pagamento até a conclusão das liquidações e a atualização da carteira. Acompanhe a evolução dos **status do lote**, dos **status de cada liquidação** e dos **webhooks** em cada etapa.

:::tip Como usar este fluxograma
Passe o mouse sobre cada etapa para ver os detalhes do endpoint e acessar a documentação completa. As trilhas coloridas mostram simultaneamente o que acontece com o lote, com cada liquidação e quais webhooks você receberá após o processamento.
:::

{`
.cf-legend{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:24px}
.cf-legend-item{display:flex;align-items:center;gap:6px;font-size:0.8rem;font-weight:600}
.cf-legend-dot{width:12px;height:12px;border-radius:3px}

.cf-step{position:relative;margin-bottom:4px}
.cf-step:not(:last-child)::after{content:'';display:block;width:2px;height:16px;margin:0 auto;background:var(--ifm-color-emphasis-300)}

.cf-card{border:1.5px solid var(--ifm-color-emphasis-200);border-radius:10px;padding:16px 20px;transition:box-shadow 0.2s,border-color 0.2s;cursor:pointer;background:var(--ifm-background-surface-color,var(--ifm-background-color))}
.cf-card:hover{box-shadow:0 4px 16px rgba(0,0,0,0.08);border-color:var(--ifm-color-primary)}

.cf-card-header{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.cf-num{width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:0.8rem;font-weight:800;color:#fff;flex-shrink:0}
.cf-num-int{background:#3b82f6}
.cf-num-qi{background:#8b5cf6}
.cf-num-ges{background:#d946ef}
.cf-title{font-size:1rem;font-weight:700;color:var(--ifm-font-color-base)}
.cf-actor{font-size:0.7rem;font-weight:700;padding:2px 8px;border-radius:12px;margin-left:auto}
.cf-actor-int{background:rgba(59,130,246,0.12);color:#2563eb}
.cf-actor-qi{background:rgba(139,92,246,0.12);color:#7c3aed}
.cf-actor-ges{background:rgba(217,70,239,0.12);color:#c026d3}
.cf-subtitle{font-size:0.82rem;color:var(--ifm-color-emphasis-700);margin-top:4px;margin-left:38px}

.cf-tracks{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px;margin-left:38px}
.cf-track{display:inline-flex;align-items:center;gap:5px;padding:3px 10px;border-radius:6px;font-size:0.75rem;font-family:var(--ifm-font-family-monospace);border:1px solid}
.cf-track-lote{background:rgba(34,197,94,0.1);color:#16a34a;border-color:rgba(34,197,94,0.25)}
.cf-track-ativo{background:rgba(59,130,246,0.1);color:#2563eb;border-color:rgba(59,130,246,0.25)}
.cf-track-wh{background:rgba(245,158,11,0.1);color:#b45309;border-color:rgba(245,158,11,0.25)}
.cf-track-err{background:rgba(239,68,68,0.1);color:#dc2626;border-color:rgba(239,68,68,0.25)}
.cf-track-label{font-family:var(--ifm-font-family-base);font-weight:700;font-size:0.7rem;text-transform:uppercase;letter-spacing:0.03em}
.cf-new{font-weight:700}
.cf-unchanged{opacity:0.5}

.cf-details{max-height:0;overflow:hidden;opacity:0;transition:max-height 0.35s ease,opacity 0.25s ease,margin 0.3s ease;margin-left:38px}
.cf-card:hover .cf-details{max-height:300px;opacity:1;margin-top:14px;padding-top:12px;border-top:1px solid var(--ifm-color-emphasis-200)}

.cf-endpoint{font-family:var(--ifm-font-family-monospace);font-size:0.82rem;padding:8px 12px;border-radius:6px;background:var(--ifm-color-emphasis-100);margin-bottom:8px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.cf-method{font-weight:800;padding:2px 6px;border-radius:4px;font-size:0.72rem}
.cf-method-post{background:#f97316;color:#fff}
.cf-method-put{background:#3b82f6;color:#fff}
.cf-method-get{background:#22c55e;color:#fff}
.cf-desc{font-size:0.82rem;color:var(--ifm-color-emphasis-700);margin-bottom:8px}
.cf-link{font-size:0.82rem;font-weight:600;color:var(--ifm-color-primary);text-decoration:none}
.cf-link:hover{text-decoration:underline}

.cf-branch{margin-top:12px;margin-left:38px;display:flex;gap:12px;flex-wrap:wrap}
.cf-branch-path{flex:1;min-width:200px;border-radius:8px;padding:10px 14px;border:1.5px dashed}
.cf-branch-ok{border-color:rgba(34,197,94,0.4);background:rgba(34,197,94,0.05)}
.cf-branch-err{border-color:rgba(239,68,68,0.4);background:rgba(239,68,68,0.05)}
.cf-branch-label{font-size:0.78rem;font-weight:700;margin-bottom:4px}
.cf-branch-label-ok{color:#16a34a}
.cf-branch-label-err{color:#dc2626}

html[data-theme='dark'] .cf-track-lote{background:rgba(34,197,94,0.15);color:#4ade80;border-color:rgba(34,197,94,0.3)}
html[data-theme='dark'] .cf-track-ativo{background:rgba(59,130,246,0.15);color:#60a5fa;border-color:rgba(59,130,246,0.3)}
html[data-theme='dark'] .cf-track-wh{background:rgba(245,158,11,0.15);color:#fbbf24;border-color:rgba(245,158,11,0.3)}
html[data-theme='dark'] .cf-track-err{background:rgba(239,68,68,0.15);color:#f87171;border-color:rgba(239,68,68,0.3)}
html[data-theme='dark'] .cf-branch-ok{background:rgba(34,197,94,0.08)}
html[data-theme='dark'] .cf-branch-err{background:rgba(239,68,68,0.08)}
html[data-theme='dark'] .cf-actor-int{background:rgba(59,130,246,0.2);color:#60a5fa}
html[data-theme='dark'] .cf-actor-qi{background:rgba(139,92,246,0.2);color:#a78bfa}
html[data-theme='dark'] .cf-actor-ges{background:rgba(217,70,239,0.2);color:#e879f9}
`}

## Legenda

Agente Integrador
QI Tech (automático)
Status do Lote
Status da Liquidação
Webhook

## Fluxograma

1
Criação do lote de pagamento
Agente Integrador
Cria um lote com identificador único ( external_id ) por fundo, contendo conta de crédito opcional e demais metadados.
Lote: pending_settlements_insertion
POST /settlement/fund_class/{fund_class_key}/payment_batch
O lote fica pronto para receber liquidações.
Ver documentação completa →

2
Inserção das liquidações
Agente Integrador
Insere cada liquidação (parcela, amortização, liquidação total, etc.) no lote. Repita para todas as operações desejadas.
Lote: pending_settlements_insertion
Liquidação: validated
POST /settlement/fund_class/{fund_class_key}/payment_batch/{external_id}/settlement
Cada liquidação recebe status validated após inserção bem-sucedida. Não há webhook neste momento; os webhooks são enviados após o encerramento e o processamento.
Ver documentação completa →

3
Remoção de liquidação (opcional)
Agente Integrador
Antes de encerrar o lote, você pode descartar uma liquidação inserida por engano. Somente liquidações em status validated podem ser removidas.
Lote: pending_settlements_insertion
Liquidação: validated
Removeu uma liquidação
discarded
A liquidação deixa de entrar no processamento.
Não aplicável
Pule este passo se não precisar remover nenhuma liquidação.
PUT /settlement/fund_class/{fund_class_key}/payment_batch/{external_id}/settlement/{settlement_external_id}
Corpo: {"status": "discarded"} . Após o encerramento do lote não é possível remover liquidações individuais.
Ver documentação completa →

4
Encerramento do lote
Agente Integrador
Sinaliza que todas as liquidações foram inseridas (e ajustadas) e que o processamento pode iniciar — ou descarta o lote inteiro.
Lote: pending_payment / discarded
Liquidação: validated (ou discarded)
Processar lote
pending_payment
É necessário ter ao menos uma liquidação no lote.
Descartar lote
discarded
Nenhuma liquidação será processada. Fluxo encerrado.
PUT /settlement/fund_class/{fund_class_key}/payment_batch/{external_id}
Envie {"batch_status": "pending_payment"} para encerrar e processar, ou {"batch_status": "discarded"} para descartar o lote.
Ver documentação completa →

5
Pagamento do lote
QI Tech
A QI Tech confirma o pagamento do lote. Em seguida as liquidações individuais são processadas e os webhooks de liquidação são disparados.
Lote: paid
Webhook: payment_batch_status_change
Webhook settlement.payment_batch_status_change com status paid . Opcionalmente, use a listagem de lotes para acompanhar o lote.
GET /settlement/fund_class/{fund_class_key}/payment_batches
Consulta opcional para acompanhar o lote por status ou data de referência.
Webhooks do lote →

6
Conclusão das liquidações
QI Tech
Cada liquidação processada com sucesso é conciliada na carteira do fundo. Este é o status final de sucesso por liquidação.
Liquidação: settled
Webhook: settlement_status_change
Webhook settlement.settlement_status_change com settlement_status settled para cada liquidação concluída (após o pagamento do lote).
Ver documentação de webhooks de liquidação →

---

## Resumo de webhooks

A tabela abaixo consolida todos os webhooks da API de liquidação:

| # | Tipo do webhook | Campo de status | Valor | Momento no fluxo | Ação esperada |
|---|---|---|---|---|---|
| 1 | `settlement.payment_batch_status_change` | `status` | `paid` | Após confirmação do pagamento do lote (passo 5) | A partir deste evento, as liquidações são processadas e os webhooks por liquidação passam a ser enviados. |
| 2 | `settlement.settlement_status_change` | `settlement_status` | `settled` | Por liquidação, após processamento bem-sucedido (passo 6) | Liquidação concluída e conciliada na carteira. |
| 3 | `settlement.settlement_status_change` | `settlement_status` | `discarded` | Por liquidação, quando descartada por remoção manual, descarte interno ou rejeição permanente da carteira | Liquidação não será processada. Nenhuma movimentação financeira é gerada. |
| 4 | `settlement.payment_batch_status_change` | `status` | `completed` | Após todas as liquidações do lote atingirem status final (`settled` ou `discarded`) | O ciclo do lote está encerrado. Todas as liquidações foram processadas. |
| 5 | `settlement.payment_batch_status_change` | `status` | `discarded` | Quando o lote é descartado (por solicitação do parceiro, descarte automático ou falha no cancelamento em conta caixa) | Nenhuma liquidação do lote será processada. |

:::info Payload do webhook de liquidação
O payload do webhook `settlement_status_change` varia conforme os dados enviados na criação da liquidação:

- **Identificação do ativo:** apenas um dos campos `contract_number` ou `asset_external_id` estará presente, conforme o método de identificação usado na criação. Nunca os dois simultaneamente.
- **Campos de parcela** (`installment_number`, `installment_maturity_date`, `installment_external_id`): presentes somente para tipos de liquidação por parcela — `installment_settlement`, `installment_amortization`, `installment_fine_payment` e `gloss`. Ausentes em tipos de ativo total (`asset_settlement`, `asset_amortization`, `fine_payment`).

Para a estrutura completa dos payloads, consulte [Webhooks do lote de pagamento](/documentation/iaas/liquidacao_ativos/lote_pagamento/webhook) e [Webhooks de liquidação](/documentation/iaas/liquidacao_ativos/ativos/webhook).
:::

---

# 简介

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/inicio

本节将介绍相关 API，这些 API 用于实现由 QI CTVM 管理的投资基金的资产清算流程。需要特别说明的是，国债或债券等资产的清算流程不适用于此上下文。

如需访问这些服务，请联系团队 [integracao.dtvm@qitech.com.br](mailto:integracao.dtvm@qitech.com.br)，以便在沙盒（Homologação）环境和生产环境中获得相应权限。

执行资产清算需要以下步骤：

1. 创建付款批次；
2. 插入待付款的资产；
3. 关闭付款批次；

## 清算流程

下图展示了主路径、分支以及每个步骤产生的状态。将鼠标悬停在节点上可查看端点，点击可打开该步骤的文档。

<FlowDiagram
  columns={3}
  labels={{ you: '集成方', qitech: 'QI Tech', manager: '基金管理人', docs: '查看文档' }}
  nodes={[
    { id: 'criacao', row: 1, col: 2, actor: 'you', num: 1,
      title: '创建付款批次',
      status: 'pending_settlements_insertion',
      desc: '所有将被一起处理的清算记录的容器，由唯一的 external_id 标识。',
      endpoint: { method: 'POST', path: '/settlement/fund_class/{fund_class_key}/payment_batch' },
      href: '/documentation/iaas/liquidacao_ativos/lote_pagamento/criacao' },

    { id: 'insercao', row: 2, col: 2, actor: 'you', num: 2,
      title: '插入清算记录',
      status: '清算：validated',
      desc: '每条清算记录一次请求，需提供资产类型、金额、清算方式和标识符。',
      endpoint: { method: 'POST', path: '.../payment_batch/{external_id}/settlement' },
      href: '/documentation/iaas/liquidacao_ativos/ativos' },

    { id: 'remocao', row: 2, col: 3, actor: 'you', tag: '可选',
      title: '移除某条清算记录',
      status: '清算：discarded',
      desc: '丢弃误插入的清算记录。仅在批次尚未关闭时可执行。',
      endpoint: { method: 'PUT', path: '.../settlement/{settlement_external_id}' },
      href: '/documentation/iaas/liquidacao_ativos/ativos/remocao_liquidacoes' },

    { id: 'encerramento', row: 3, col: 2, actor: 'you', num: 3,
      title: '关闭批次',
      desc: '设置 batch_status。批次中至少需要插入一条清算记录。',
      endpoint: { method: 'PUT', path: '.../payment_batch/{external_id}' },
      href: '/documentation/iaas/liquidacao_ativos/lote_pagamento/fechamento' },

    { id: 'descartado', row: 4, col: 1, actor: 'you', tone: 'end',
      title: '批次已丢弃',
      status: 'discarded',
      desc: '不处理任何清算记录，也不产生任何资金变动。流程终止。' },

    { id: 'pago', row: 4, col: 2, actor: 'qitech',
      title: '批次付款已确认',
      status: 'paid',
      desc: 'QI Tech 确认付款。从该事件起，各条清算记录开始被处理。',
      href: '/documentation/iaas/liquidacao_ativos/lote_pagamento/webhook' },

    { id: 'processa', row: 5, col: 2, actor: 'qitech',
      title: '逐条处理清算记录',
      status: '清算：settled',
      desc: '每条清算记录都会在基金投资组合中完成对账，并通过 webhook 单独发送通知。',
      href: '/documentation/iaas/liquidacao_ativos/ativos/webhook' },

    { id: 'conciliada', row: 6, col: 2, actor: 'qitech', tone: 'ok',
      title: '基金投资组合已对账',
      status: 'completed',
      desc: '所有清算记录均已达到最终状态，批次周期结束。',
      href: '/documentation/iaas/liquidacao_ativos/lote_pagamento/webhook' },
  ]}
  edges={[
    { from: 'criacao', to: 'insercao' },
    { from: 'insercao', to: 'remocao', dashed: true },
    { from: 'insercao', to: 'encerramento' },
    { from: 'encerramento', to: 'descartado', label: 'discarded', tone: 'end' },
    { from: 'encerramento', to: 'pago', label: 'pending_payment', tone: 'ok' },
    { from: 'pago', to: 'processa', label: 'webhook' },
    { from: 'processa', to: 'conciliada', label: 'webhook' },
  ]}
/>

:::tip 完整流程
如需了解每一次状态流转、webhook 载荷以及异常路径，请参阅[资产清算流程](/documentation/iaas/liquidacao_ativos/fluxo_liquidacao)。
:::

# 创建批次
在此步骤中，需要生成一个付款批次密钥，该密钥将用于在清算过程中标识批次。此密钥将在创建批次时发送，之后即可进入下一步骤。
:::caution **注意**

每个批次在已注册的基金中必须拥有**唯一密钥**。
:::

# 插入资产
在此步骤中，清算相关资产将逐一发送，并附带其待清算金额、资产类型、清算方式以及资产标识符等信息，格式详情请参见 [5.4.3.1 资产](ativos/ativos.md)。

# 关闭批次
最后，插入所有资产后，需要使用批次密钥关闭付款批次。此后，付款批次的清算处理将在内部启动，并最终通过 webhook 指示流程完成。

:::info **信息**

现金对账和资产组合更新将由 API 自动完成。
:::

---

# 创建付款批次

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/criacao

---

### Request

ENDPOINT /settlement/fund_class/FUND_CLASS_KEY/payment_batch
MÉTODO POST

```json title='Request Body'
{
    "external_id": "41d6ff41-1dac-4df7-9e50-d15210ec57f3", 
    "description": "PAGAMENOS - ABC - 2025-01-01",
    "account": {
        "account_number":"123456",
        "account_digit":"0",
        "account_branch": "0001",
        "financial_institution_code": "329",
    },
}
```

### Body Params
`必填字段 * `
| 字段                     | 类型   | 描述                                                                    | 字符数     |
|--------------------------|--------|-----------------------------------------------------------------------------|------------|
| `external_id` *          | string | 集成合作伙伴系统中此批次的唯一标识键。                                      | 最多 50    |
| `account_key`            | string | 用于标识清算入账账户的字段                                                  | 36         |
| `account`                | JSON   | 用于标识清算入账账户的字段                                                  | -          |
| `description`            | string | 清算批次描述                                                                | 255        |
| `reference_date`         | string | 清算参考日期。                                                              | ISO 8601   |
| `end_to_end_id`          | string | 清算金融对手方的 PIX 标识符。                                               | 32         |
| `source_document_number` | string | 清算金融对手方的文件号码。                                                  | 14 - 18    |

:::caution **注意**

`account` 和 `account_key` 字段均非必填，但若未作为参数传入，清算将在基金主账户中生成。两者不应同时传入。账户信息必须属于该基金旗下的账户。
:::

### Account
| 字段                         | 类型   | 描述                     | 字符数     |
|------------------------------|--------|----------------------------------|------------|
| `account_number`             | string | 账号                             | 最多 50    |
| `account_digit`              | string | 账号校验位                       | 1          |
| `account_branch`             | string | 账户支行                         | 最多 50    |
| `financial_institution_code` | string | 金融机构代码                     | 3          |

### Response

STATUS 201

```json title='Response Body'
{
    "external_id": "41d6ff41-1dac-4df7-9e50-d15210ec57f3",
    "status": "pending_settlements_insertion",
    "description": "Lote de Pagamento - 2024-01-01 - 41d6ff41-1dac-4df7-9e50-d15210ec57f3",
    "fund_class_key": "4b8377d0-58ec-479f-8ee9-9f963d5c47ad",
    "payment_batch_key": "63f0dbec-e9c4-4943-929e-1d47b9edbb0b",
    "reference_date": "2024-01-01",
}
```

### 可能的错误

STATUS 404

Response Body

```json
{
  "title": "Fund Class not Found",
  "description": "Fund Class with key {fund_class_key} was not found.",
  "translation": "A Classe de Fundo com chave {fund_class_key} nao foi encontrado.",
  "code": "SET000005"
}

```

STATUS 400

Response Body

```json
{
  "title": "Bad Request",
  "description": "Payment batch is being created in {accounting_date}, while fund is in {fund_class_accounting_date}",
  "translation": "Payment batch esta sendo criado em {accounting_date}, fundo esta em {fund_class_accounting_date}",
  "code": "SET000044"
}

```

STATUS 409

Response Body

```json
{
  "title": "Payment batch external id already exists",
  "description": "The Payment Batch with external id {payment_batch_external_id} already exists",
  "translation": "O Lote de Pagamento com identificador externo {payment_batch_external_id} ja existe",
  "code": "SET000009"
}

```

STATUS 404

Response Body

```json
{
  "title": "Account not found",
  "description": "The account with key ({account_key}) was not found.",
  "translation": "A conta com chave({account_key}) não foi encontrada.",
  "code": "SET000009"
}

```

---

# 关闭付款批次的插入

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/fechamento

---

### Request

ENDPOINT /settlement/fund_class/FUND_CLASS_KEY/payment_batch/EXTERNAL_ID
MÉTODO PUT

```json title='Request Body'
{
    "batch_status": "pending_payment",
}
```
### Body Params
#### `必填字段` *
| 字段 | 类型 | 描述 | 字符数 |
|-|-|-|-|
| `batch_status` * | string | 指定要传入的状态 | 最多 50 |
### 状态
| 枚举值 | 描述|
|---|---|
| `pending_payment`| 待付款|
| `discarded` | 已丢弃|
### Response

STATUS 200

```json title='Response Body'
{
    "external_id": "41d6ff41-1dac-4df7-9e50-d15210ec57f3",
    "status": "pending_payment",
}
```

### 可能的错误

STATUS 404

Response Body

```json
{
  "title": "Payment batch not found",
  "description": "The Payment Batch with external_id {payment_batch_external_id} was not found",
  "translation": "O Lote de Pagamento com identificador externo {payment_batch-external_id} não foi encontrado",
  "code": "SET000010"
}

```

---

STATUS 400

Response Body

```json
{
  "title": "Invalid status",
  "description": "The status given: {status} is not suported.",
  "translation": "O status: {status} não possui suporte.",
  "code": "SET000026"
}

```
---

STATUS 400

Response Body

```json
{
  "title": "Payment Batch with no settlement",
  "description": "Payment batch of external_id: {payment_batch_external_id} have no settlements to be settled",
  "translation": "O lote de pagamento com identificador: {payment_batch_external_id} não possui liquidações",
  "code": "SET000017"
}

```
---

---

# 清算批次列表

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/listagem

---

### Request

ENDPOINT /settlement/fund_class/FUND_CLASS_KEY/payment_batchs
MÉTODO GET

### Response

STATUS 200

```json title='Response Body'
{
    "data": [
        {
            "description": "LOTE DE LIQUIDAÇÃO 08/08",
            "fund_class": {
                "name": "FUNDO DE INVESTIMENTO EM DIREITOS CREDITÓRIOS RECEBÍVEIS",
                "manager": {
                    "name": "EXEMPLO CAPITAL",
                    "manager_key": "a7498c6c-1893-42ec-a8f3-bc6ad0c6b52c",
                    "document_number": "45.585.471/0001-47"
                },
                "fund_class_key": "a3ecf74b-d280-4d3c-aefd-cb223dbf0451",
                "document_number": "60.910.091/0001-24"
            },
            "payment_batch_key": "50859e88-544c-4c79-a7aa-d373d90aa571",
            "status": "discarded",
            "external_id": "5910209c-9cb5-4569-9069-f2dbc8060434",
            "reference_date": "2025-08-08",
            "account_key": "5e621ba2-b4ac-4ddd-9893-82d220e1577e"
        },
        {
            "description": "AJUSTE LOTE DE LIQUIDAÇÃO 06/08",
            "fund_class": {
                "name": "FUNDO DE INVESTIMENTO EM DIREITOS CREDITÓRIOS RECEBÍVEIS",
                "manager": {
                    "name": "EXEMPLO CAPITAL",
                    "manager_key": "a7498c6c-1893-42ec-a8f3-bc6ad0c6b52c",
                    "document_number": "45.585.471/0001-47"
                },
                "fund_class_key": "a3ecf74b-d280-4d3c-aefd-cb223dbf0451",
                "document_number": "60.910.091/0001-24"
            },
            "payment_batch_key": "5e9f645d-10e1-4ecc-9154-e8d81bb54e72",
            "status": "completed",
            "external_id": "214b237b-3453-40cb-a07a-d9f57065a1bd",
            "reference_date": "2025-08-06",
            "account_key": "5e621ba2-b4ac-4ddd-9893-82d220e1577e",
            "total_value": 143.18
        }
    ],
    "limit": 10,
    "page": 0,
    "is_last_page": false
}
```

---

# 产品 Webhooks

URL: /zh-Hans/documentation/iaas/liquidacao_ativos/lote_pagamento/webhook

---
#### 付款批次已付款

STATUS Paid

```json title='Webhook Body'
{
    "data":{
        "external_id": "57efbd9f-0917-4c79-9a43-bc8f1039fc78",
        "status": "paid"
    },
    "webhook_type":"settlement.payment_batch_status_change",
    "webhook_datetime":"2024-04-23T15:08:30Z"  
}
```