{
  "openapi": "3.1.0",
  "info": {
    "title": "N — API v1",
    "version": "2027-02-01",
    "description": "Cobrança e nota fiscal. Ambiente de testes: nenhuma nota vai para o governo; os centavos do total escolhem o cenário. Dinheiro sempre em centavos (BRL)."
  },
  "servers": [
    {
      "url": "https://n.tpai.com.br/api/v1"
    },
    {
      "url": "https://n.tpai.com.br/sandbox/v1"
    }
  ],
  "security": [
    {
      "chave": []
    }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "sobreAConta",
        "summary": "Empresa ligada à chave e códigos de serviço aprovados",
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/fiscal-intents": {
      "post": {
        "operationId": "criarIntencaoFiscal",
        "summary": "Intenção de emissão (responde 202)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Idempotencia"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NovaIntencao"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Aceita",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IntencaoFiscal"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      },
      "get": {
        "operationId": "listarIntencoesFiscais",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/IntencaoFiscal"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/fiscal-intents/{id}": {
      "get": {
        "operationId": "consultarIntencaoFiscal",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IntencaoFiscal"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/fiscal-documents/{id}": {
      "get": {
        "operationId": "consultarDocumentoFiscal",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IntencaoFiscal"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/fiscal-documents/{id}/files": {
      "get": {
        "operationId": "arquivosDoDocumento",
        "summary": "Links de 10 minutos para XML e PDF",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Arquivos"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/fiscal-documents/{id}/events": {
      "post": {
        "operationId": "eventoFiscal",
        "summary": "Cancelar, com motivo",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Idempotencia"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EventoFiscal"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Aceito",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IntencaoFiscal"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/checkout-sessions": {
      "post": {
        "operationId": "criarCheckout",
        "parameters": [
          {
            "$ref": "#/components/parameters/Idempotencia"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NovaCobranca"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pagamento"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/payment-links": {
      "post": {
        "operationId": "criarLinkDePagamento",
        "parameters": [
          {
            "$ref": "#/components/parameters/Idempotencia"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NovaCobranca"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Criada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pagamento"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/payments": {
      "get": {
        "operationId": "listarPagamentos",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Pagamento"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/payments/{id}": {
      "get": {
        "operationId": "consultarPagamento",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pagamento"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/payments/{id}/refunds": {
      "post": {
        "operationId": "estornar",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Idempotencia"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "integer"
                  },
                  "reason": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Estornado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pagamento"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/payments/{id}/simulate": {
      "post": {
        "operationId": "simularPagamento",
        "summary": "Só no ambiente de testes: o comprador pagou",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pagamento"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/orders/{external_id}/fulfillments": {
      "post": {
        "operationId": "concluirPedido",
        "summary": "Serviço concluído; dispara o gatilho fiscal",
        "parameters": [
          {
            "name": "external_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Idempotencia"
          }
        ],
        "responses": {
          "201": {
            "description": "Registrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pagamento"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "409": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "listarEventos",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Evento"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    },
    "/events/{id}/replay": {
      "post": {
        "operationId": "reenviarEvento",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resultado da entrega"
          },
          "404": {
            "$ref": "#/components/responses/Erro"
          },
          "422": {
            "$ref": "#/components/responses/Erro"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "chave": {
        "type": "http",
        "scheme": "bearer",
        "description": "Chave n_test_ da tela Integração do app"
      }
    },
    "parameters": {
      "Idempotencia": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 255
        },
        "description": "Repetir com a mesma chave e o mesmo corpo devolve o mesmo recurso; com outro corpo, 409 idempotency_key_reused."
      }
    },
    "responses": {
      "Erro": {
        "description": "Erro",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "required": [
                    "code",
                    "message"
                  ],
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "field": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Cliente": {
        "type": "object",
        "properties": {
          "document": {
            "type": "string",
            "description": "CPF ou CNPJ"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          }
        }
      },
      "NovaIntencao": {
        "type": "object",
        "required": [
          "items"
        ],
        "properties": {
          "model": {
            "enum": [
              "nfse",
              "nfe",
              "nfce"
            ]
          },
          "external_id": {
            "type": "string"
          },
          "customer": {
            "$ref": "#/components/schemas/Cliente"
          },
          "items": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "unit_amount"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "description": "Item da LC 116 (ex.: 17.01) na NFS-e"
                },
                "description": {
                  "type": "string"
                },
                "quantity": {
                  "type": "number"
                },
                "unit_amount": {
                  "type": "integer"
                },
                "ncm": {
                  "type": "string"
                },
                "cfop": {
                  "type": "string"
                },
                "unit": {
                  "type": "string"
                }
              }
            }
          },
          "business_event": {
            "type": "string"
          },
          "service_period": {
            "type": "string"
          },
          "occurred_on": {
            "type": "string"
          },
          "payment_reference": {
            "type": "object"
          }
        }
      },
      "IntencaoFiscal": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "fi_…"
            ]
          },
          "object": {
            "const": "fiscal_intent"
          },
          "livemode": {
            "type": "boolean"
          },
          "status": {
            "enum": [
              "awaiting_trigger",
              "pending_data",
              "queued",
              "transmitting",
              "awaiting_query",
              "authorized",
              "rejected"
            ]
          },
          "model": {
            "type": "string"
          },
          "total_amount": {
            "type": "integer"
          },
          "currency": {
            "const": "BRL"
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "missing_fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rejection": {
            "type": [
              "object",
              "null"
            ]
          },
          "document": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "status": {
                "enum": [
                  "authorized",
                  "cancel_requested",
                  "cancelled",
                  "replaced"
                ]
              },
              "number": {
                "type": "integer"
              },
              "access_key": {
                "type": "string"
              },
              "protocol": {
                "type": "string"
              },
              "authorized_at": {
                "type": "string"
              },
              "files_url": {
                "type": "string"
              }
            }
          },
          "payment_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string"
          },
          "resource_version": {
            "type": "integer"
          }
        }
      },
      "EventoFiscal": {
        "type": "object",
        "required": [
          "type",
          "reason"
        ],
        "properties": {
          "type": {
            "const": "cancel"
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "Arquivos": {
        "type": "object",
        "properties": {
          "document_id": {
            "type": "string"
          },
          "xml_url": {
            "type": "string"
          },
          "pdf_url": {
            "type": "string"
          },
          "expires_at": {
            "type": "string"
          }
        }
      },
      "NovaCobranca": {
        "type": "object",
        "required": [
          "amount",
          "description"
        ],
        "properties": {
          "amount": {
            "type": "integer"
          },
          "description": {
            "type": "string"
          },
          "method": {
            "enum": [
              "pix",
              "card"
            ]
          },
          "installments": {
            "type": "integer",
            "minimum": 1,
            "maximum": 12
          },
          "external_id": {
            "type": "string"
          },
          "customer": {
            "$ref": "#/components/schemas/Cliente"
          },
          "service_code": {
            "type": "string"
          },
          "issue_invoice": {
            "type": "boolean"
          },
          "fiscal_trigger": {
            "enum": [
              "immediate",
              "service_completed"
            ]
          },
          "split": {
            "type": "object",
            "required": [
              "name",
              "document",
              "amount"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "document": {
                "type": "string"
              },
              "amount": {
                "type": "integer"
              }
            }
          },
          "invoice_on": {
            "enum": [
              "total",
              "commission"
            ]
          }
        }
      },
      "Pagamento": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "pay_…"
            ]
          },
          "object": {
            "const": "payment"
          },
          "status": {
            "enum": [
              "requires_action",
              "processing",
              "unknown",
              "succeeded",
              "failed",
              "expired",
              "refunded",
              "disputed"
            ]
          },
          "method": {
            "enum": [
              "pix",
              "card"
            ]
          },
          "amount": {
            "type": "integer"
          },
          "installments": {
            "type": "integer"
          },
          "description": {
            "type": "string"
          },
          "external_id": {
            "type": "string"
          },
          "checkout_url": {
            "type": "string"
          },
          "pix": {
            "type": [
              "object",
              "null"
            ]
          },
          "fee_expected": {
            "type": "integer"
          },
          "refunded_amount": {
            "type": "integer"
          },
          "split": {
            "type": [
              "object",
              "null"
            ]
          },
          "fiscal_intent_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "paid_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string"
          },
          "resource_version": {
            "type": "integer"
          }
        }
      },
      "Evento": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "api_version": {
            "type": "string"
          },
          "created_at": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "establishment_id": {
            "type": "string"
          },
          "resource_version": {
            "type": "integer"
          },
          "data": {
            "type": "object"
          }
        }
      }
    }
  }
}
