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

# Orquestração

> Como a PlugToPay seleciona o gateway, distribui carga por percentual e gerencia retentativas.

## Como o gateway é escolhido

A cada pagamento, o roteador percorre três camadas em ordem de prioridade:

```
1. gateway_first_try no body da requisição?
   → Sim: usa esse gateway (se habilitado)
   → Não: continua ↓

2. Existem regras de roteamento por percentual para esse método?
   → Sim: seleciona pelo algoritmo de maior déficit
   → Não: continua ↓

3. Fallback: primeiro gateway habilitado, ordenado por `order`
```

***

## Referência rápida de rotas

| Método | Rota                               | Auth                        | Descrição                      |
| ------ | ---------------------------------- | --------------------------- | ------------------------------ |
| `GET`  | `/api/v1/company/gateways/order`   | `X-Client-ID` + `X-API-Key` | Consultar ordem atual          |
| `PUT`  | `/api/v1/company/gateways/order`   | `X-Client-ID` + `X-API-Key` | Definir ordem dos gateways     |
| `GET`  | `/api/v1/company/gateways/routing` | `X-Client-ID` + `X-API-Key` | Consultar regras de percentual |
| `PUT`  | `/api/v1/company/gateways/routing` | `X-Client-ID` + `X-API-Key` | Definir regras de percentual   |
| `GET`  | `/api/v1/user/company/config`      | `Bearer JWT`                | Consultar configurações        |
| `PUT`  | `/api/v1/user/company/config`      | `Bearer JWT`                | Atualizar configurações        |
