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

# Liquide uma autorização anterior

> Liquide um pagamento previamente autorizado. Suporta captura parcial. Deve ser chamado dentro da janela de autorização do adquirente.

export const SchemaLangNote = ({lang}) => {
  const text = ({
    es: "Los nombres de campos y el esquema de solicitud/respuesta que se muestran a continuación están en inglés — se generan a partir de la especificación OpenAPI. El texto explicativo de esta página está traducido.",
    pt: "Os nomes dos campos e o esquema de requisição/resposta exibidos abaixo estão em inglês — são gerados a partir da especificação OpenAPI. O texto explicativo desta página está traduzido."
  })[lang] || "Field names and the request/response schema shown below are in English — they are generated from the OpenAPI specification.";
  return <Note>{text}</Note>;
};

Chame `POST /payment/{id}/capture` para liquidar fundos de um `POST /payment/authorization` anterior. Você pode capturar menos do que o valor total autorizado — uma captura parcial — e a retenção restante é liberada automaticamente. Você deve chamar este endpoint dentro da janela de autorização do adquirente (normalmente 7 dias) ou a retenção expira e você precisará autorizar novamente.

<SchemaLangNote lang="pt" />

## Identificar o pagamento

`{id}` é o `id` de pagamento do Therius devolvido na resposta a `POST /payment/authorization` (e `POST /payment/purchase`). Guarde-o quando você cria o pagamento. `orderCode` e `paymentCode` são os seus próprios campos de referência — **não** são aceitos como forma de endereçar o pagamento para captura, reembolso ou cancelamento.

Um `id` que não existe, ou que pertence a outro lojista, devolve `404`.

## Exemplo

### Captura total

<RequestExample>
  ```bash cURL theme={"dark"}
  curl -X POST https://api.therius.io/v1/payment/9f8b2c1e-4d5a-6b7c-8d9e-0f1a2b3c4d5e/capture \
    -H "Authorization: Bearer prv_production_your_key_here" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "merchantCode": "MERCHANT_001",
      "amount": { "currency": "USD", "value": 9900, "exponent": 2 }
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={"dark"}
  {
    "id": "9f8b2c1e-4d5a-6b7c-8d9e-0f1a2b3c4d5e",
    "status": "captured",
    "paymentCode": "PC-1234567890",
    "orderCode": "ORDER-20240101-002",
    "merchantCode": "MERCHANT_001",
    "amount": { "currency": "USD", "value": 9900, "exponent": 2 }
  }
  ```
</ResponseExample>

### Captura parcial

```bash theme={"dark"}
curl -X POST https://api.therius.io/v1/payment/9f8b2c1e-4d5a-6b7c-8d9e-0f1a2b3c4d5e/capture \
  -H "Authorization: Bearer prv_production_your_key_here" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "merchantCode": "MERCHANT_001",
    "amount": { "currency": "USD", "value": 7500, "exponent": 2 }
  }'
```

```json theme={"dark"}
{
  "id": "9f8b2c1e-4d5a-6b7c-8d9e-0f1a2b3c4d5e",
  "status": "captured",
  "paymentCode": "PC-1234567890",
  "orderCode": "ORDER-20240101-002",
  "merchantCode": "MERCHANT_001",
  "amount": { "currency": "USD", "value": 7500, "exponent": 2 }
}
```

<Note>
  Quando você faz uma captura parcial, o Therius libera automaticamente a retenção restante (\$24.00 no exemplo acima). Você não precisa enviar uma requisição de cancelamento separada para a parte não capturada.
</Note>

<Warning>
  Você só pode capturar um pagamento autorizado uma vez. Se você precisar capturar um valor diferente depois que uma captura parcial já foi processada, você precisará criar uma nova autorização.
</Warning>

<Tip>
  Passe sempre um `Idempotency-Key` na captura. Se o seu servidor esgotar o tempo limite e você tentar de novo, a mesma chave garante que você não liquidará duas vezes a mesma autorização.
</Tip>


## OpenAPI

````yaml POST /payment/{id}/capture
openapi: 3.1.0
info:
  title: Therius API
  description: REST API for payments, subscriptions, and billing plans.
  version: 1.0.0
servers:
  - url: https://api.therius.io/v1
    description: Production
  - url: https://api-sandbox.therius.io/v1
    description: Sandbox
security:
  - bearerAuth: []
paths:
  /payment/{id}/capture:
    post:
      tags:
        - Payments
      summary: Settle a prior authorization
      operationId: capturePayment
      parameters:
        - $ref: '#/components/parameters/PaymentId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - merchantCode
                - amount
              properties:
                merchantCode:
                  type: string
                  description: >-
                    Your merchant account identifier. Validated against the
                    Bearer key's merchant; required if the key maps to more than
                    one merchant account.
                amount:
                  $ref: '#/components/schemas/Amount'
                reference:
                  type: string
                  description: Optional internal reference for this capture operation.
      responses:
        '200':
          description: Capture result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ModificationResponse'
components:
  parameters:
    PaymentId:
      name: id
      in: path
      required: true
      description: >-
        The Therius payment `id` returned by `POST /payment/authorization` or
        `POST /payment/purchase`.
      schema:
        type: string
        format: uuid
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      description: >-
        A UUID you generate per operation. Required in production. Retrying with
        the same key returns the original response.
      schema:
        type: string
        format: uuid
  schemas:
    Amount:
      type: object
      required:
        - currency
        - value
        - exponent
      properties:
        currency:
          type: string
          description: >-
            ISO 4217 currency code. On capture, refund and cancel it must match
            the currency of the original payment.
          example: USD
        value:
          type: integer
          description: >-
            Amount in minor units (cents, pence, etc.). `4999` = $49.99 for USD
            (exponent 2); `5000` = ¥5000 for JPY (exponent 0). On capture it
            must not exceed the authorized value; on refund the cumulative total
            across refunds must not exceed the captured amount.
          example: 4999
        exponent:
          type: integer
          description: >-
            Number of decimal places for the currency — `2` for USD/EUR, `0` for
            JPY. Determines where the decimal point sits in `value`.
          example: 2
    ModificationResponse:
      type: object
      description: Result of a capture, refund, cancel or cancel_or_refund.
      properties:
        id:
          type: string
          description: The Therius payment `id`.
        merchantCode:
          type: string
        orderCode:
          type: string
        paymentCode:
          type: string
          description: Therius receipt ID.
        amount:
          $ref: '#/components/schemas/Amount'
        status:
          type: string
          enum:
            - captured
            - refunded
            - cancelled
            - failed
          description: Outcome of the operation.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your secret API key: `Bearer prv_production_xxx` (production) or `Bearer
        prv_sandbox_xxx` (sandbox).

````