openapi: 3.1.0
info:
  title: PagVeo API
  version: "1.0"
  description: API Pix da PagVeo (cash-in, cash-out, saldo e MED). Valores em centavos. Documentação completa em https://api.pagveo.com/docs/ · Servidor MCP para IA em https://api.pagveo.com/mcp (chave com permissão mcp).
servers:
  - url: https://api.pagveo.com/v1
security:
  - basic: []
components:
  securitySchemes:
    basic: { type: http, scheme: basic, description: "client_id:client_secret" }
  parameters:
    Idem: { name: Idempotency-Key, in: header, required: false, schema: { type: string, minLength: 8, maxLength: 80 } }
    Id: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    Limit: { name: limit, in: query, schema: { type: integer, default: 25, maximum: 100 } }
    Offset: { name: offset, in: query, schema: { type: integer, default: 0 } }
    Status: { name: status, in: query, description: "Um ou vários, separados por vírgula (ex.: paid,med)", schema: { type: string } }
    Currency: { name: currency, in: query, schema: { type: string, enum: [BRL, MXN] } }
    Q: { name: q, in: query, description: "Busca livre (pagador, documento, E2E, referência, ID, descrição)", schema: { type: string } }
    AmountMin: { name: amount_min, in: query, description: centavos, schema: { type: integer } }
    AmountMax: { name: amount_max, in: query, description: centavos, schema: { type: integer } }
    From: { name: from, in: query, description: "Data de criação inicial AAAA-MM-DD (fuso de São Paulo)", schema: { type: string, format: date } }
    To: { name: to, in: query, description: "Data de criação final AAAA-MM-DD (inclusiva)", schema: { type: string, format: date } }
    Sort: { name: sort, in: query, schema: { type: string, enum: [created_at, amount, paid_at, completed_at] } }
    Dir: { name: dir, in: query, schema: { type: string, enum: [asc, desc] } }
  schemas:
    Error:
      type: object
      properties:
        error: { type: object, properties: { code: { type: string }, message: { type: string }, details: {} } }
        request_id: { type: string }
    CashinCreate:
      type: object
      required: [amount, payer]
      additionalProperties: false
      properties:
        currency: { type: string, enum: [BRL, MXN], default: BRL, description: "BRL = Pix; MXN = SPEI ou OXXO (México)" }
        method: { type: string, enum: [pix, spei, oxxo], description: "Opcional. Padrão: pix (BRL) ou spei (MXN). oxxo (MXN) = voucher pago em dinheiro numa loja OXXO, vale 12 dias. Cada método tem taxa e limites próprios." }
        amount: { type: integer, minimum: 1, description: centavos da moeda }
        payer:
          type: object
          required: [name]
          description: "document = CPF/CNPJ (obrigatório em BRL) ou RFC/CURP (opcional em MXN)"
          properties:
            name: { type: string }
            document: { type: string }
            email: { type: string }
            phone: { type: string }
            address:
              type: object
              additionalProperties: false
              description: "Opcional. Onde está o pagador; alimenta o mapa 'De onde vêm as vendas' do painel."
              properties:
                country: { type: string, minLength: 2, maxLength: 2, description: "ISO 2 letras (BR, MX). Padrão: país da moeda" }
                state: { type: string, description: "Sigla (SP, RJ, JAL, CMX...) ou nome do estado" }
                city: { type: string, maxLength: 80 }
        description: { type: string, maxLength: 140 }
        external_id: { type: string, maxLength: 80 }
        webhook_url: { type: string, format: uri }
        expires_in: { type: integer, minimum: 300, maximum: 86400 }
        metadata: { type: object, additionalProperties: { type: [string, number, boolean] } }
    Cashin:
      type: object
      properties:
        id: { type: string, format: uuid }
        external_id: { type: [string, "null"] }
        status: { type: string, enum: [pending, paid, expired, failed, refunded, med] }
        currency: { type: string, enum: [BRL, MXN] }
        method: { type: string, enum: [pix, spei, oxxo] }
        amount: { type: integer }
        fee: { type: integer }
        net_amount: { type: integer }
        description: { type: [string, "null"] }
        pix: { type: [object, "null"], properties: { copy_paste: { type: string }, qr_code_base64: { type: string } } }
        spei: { type: [object, "null"], properties: { clabe: { type: string }, bank_name: { type: string }, beneficiary: { type: [string, "null"] }, reference: { type: [string, "null"] } } }
        oxxo: { type: [object, "null"], description: "OXXO pendente: o pagador informa a referência no caixa da loja", properties: { reference: { type: string }, barcode_url: { type: [string, "null"] }, checkout_url: { type: [string, "null"] } } }
        payer: { type: object }
        end_to_end_id: { type: [string, "null"] }
        metadata: { type: object }
        expires_at: { type: string, format: date-time }
        paid_at: { type: [string, "null"], format: date-time }
        created_at: { type: string, format: date-time }
        env: { type: string, enum: [live, test] }
    CashoutCreate:
      type: object
      required: [amount]
      additionalProperties: false
      description: "BRL exige pix_key + pix_key_type; MXN exige clabe + recipient"
      properties:
        currency: { type: string, enum: [BRL, MXN], default: BRL }
        amount: { type: integer, minimum: 1 }
        pix_key: { type: string }
        pix_key_type: { type: string, enum: [cpf, cnpj, email, phone, random] }
        clabe: { type: string, description: CLABE de 18 dígitos (MXN) }
        recipient: { type: object, required: [name], properties: { name: { type: string }, document: { type: string, description: RFC ou CURP } } }
        description: { type: string, maxLength: 140 }
        external_id: { type: string, maxLength: 80 }
        webhook_url: { type: string, format: uri }
    Cashout:
      type: object
      properties:
        id: { type: string, format: uuid }
        external_id: { type: [string, "null"] }
        status: { type: string, enum: [pending, processing, completed, failed, rejected, cancelled] }
        under_review: { type: boolean }
        amount: { type: integer }
        fee: { type: integer }
        total_debit: { type: integer }
        currency: { type: string, enum: [BRL, MXN] }
        method: { type: string, enum: [pix, spei] }
        pix_key: { type: [string, "null"] }
        pix_key_type: { type: [string, "null"] }
        clabe: { type: [string, "null"] }
        recipient: { type: [object, "null"] }
        end_to_end_id: { type: [string, "null"] }
        failure_reason: { type: [string, "null"] }
        completed_at: { type: [string, "null"], format: date-time }
        created_at: { type: string, format: date-time }
        env: { type: string }
    Med:
      type: object
      properties:
        id: { type: string }
        cashin_id: { type: string }
        protocol: { type: [string, "null"] }
        amount: { type: integer }
        blocked_amount: { type: integer }
        reason: { type: string }
        status: { type: string, enum: [open, awaiting_defense, under_review, accepted, rejected, cancelled] }
        defense_deadline: { type: string, format: date-time }
        created_at: { type: string, format: date-time }
paths:
  /balance:
    get:
      summary: Saldo
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { env: { type: string }, currency: { type: string }, available: { type: integer }, blocked: { type: integer }, balances: { type: array, items: { type: object } } } } } } }
  /statement:
    get:
      summary: Extrato (lançamentos do saldo)
      parameters: [{ $ref: "#/components/parameters/Limit" }, { $ref: "#/components/parameters/Offset" }, { $ref: "#/components/parameters/Currency" }, { $ref: "#/components/parameters/Q" }, { $ref: "#/components/parameters/From" }, { $ref: "#/components/parameters/To" }, { name: kind, in: query, schema: { type: string } }, { name: bucket, in: query, schema: { type: string, enum: [available, blocked] } }, { name: direction, in: query, schema: { type: string, enum: [in, out] } }]
      responses: { "200": { description: OK } }
  /cashins:
    post:
      summary: Criar cobrança Pix
      parameters: [{ $ref: "#/components/parameters/Idem" }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/CashinCreate" } } } }
      responses:
        "201": { description: Criada, content: { application/json: { schema: { $ref: "#/components/schemas/Cashin" } } } }
        "422": { description: Regra de negócio, content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
    get:
      summary: Listar cobranças
      parameters: [{ $ref: "#/components/parameters/Limit" }, { $ref: "#/components/parameters/Offset" }, { $ref: "#/components/parameters/Status" }, { $ref: "#/components/parameters/Currency" }, { $ref: "#/components/parameters/Q" }, { $ref: "#/components/parameters/AmountMin" }, { $ref: "#/components/parameters/AmountMax" }, { $ref: "#/components/parameters/From" }, { $ref: "#/components/parameters/To" }, { $ref: "#/components/parameters/Sort" }, { $ref: "#/components/parameters/Dir" }, { name: external_id, in: query, schema: { type: string } }, { name: paid_from, in: query, schema: { type: string, format: date } }, { name: paid_to, in: query, schema: { type: string, format: date } }]
      responses: { "200": { description: OK } }
  /cashins/{id}:
    get:
      summary: Consultar cobrança
      parameters: [{ $ref: "#/components/parameters/Id" }]
      responses: { "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Cashin" } } } } }
  /sandbox/cashins/{id}/pay:
    post:
      summary: Simular pagamento (somente chave de teste)
      parameters: [{ $ref: "#/components/parameters/Id" }]
      responses: { "200": { description: OK } }
  /cashouts:
    post:
      summary: Solicitar saque Pix
      parameters: [{ $ref: "#/components/parameters/Idem" }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/CashoutCreate" } } } }
      responses:
        "201": { description: Criado, content: { application/json: { schema: { $ref: "#/components/schemas/Cashout" } } } }
        "422": { description: Regra de negócio, content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
    get:
      summary: Listar saques
      parameters: [{ $ref: "#/components/parameters/Limit" }, { $ref: "#/components/parameters/Offset" }, { $ref: "#/components/parameters/Status" }, { $ref: "#/components/parameters/Currency" }, { $ref: "#/components/parameters/Q" }, { $ref: "#/components/parameters/AmountMin" }, { $ref: "#/components/parameters/AmountMax" }, { $ref: "#/components/parameters/From" }, { $ref: "#/components/parameters/To" }, { $ref: "#/components/parameters/Sort" }, { $ref: "#/components/parameters/Dir" }, { name: external_id, in: query, schema: { type: string } }, { name: completed_from, in: query, schema: { type: string, format: date } }, { name: completed_to, in: query, schema: { type: string, format: date } }]
      responses: { "200": { description: OK } }
  /cashouts/{id}:
    get:
      summary: Consultar saque
      parameters: [{ $ref: "#/components/parameters/Id" }]
      responses: { "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Cashout" } } } } }
  /meds:
    get:
      summary: Listar MEDs
      parameters: [{ $ref: "#/components/parameters/Limit" }, { $ref: "#/components/parameters/Offset" }, { $ref: "#/components/parameters/Status" }, { $ref: "#/components/parameters/Q" }, { $ref: "#/components/parameters/From" }, { $ref: "#/components/parameters/To" }]
      responses: { "200": { description: OK } }
  /meds/{id}:
    get:
      summary: Consultar MED
      parameters: [{ $ref: "#/components/parameters/Id" }]
      responses: { "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Med" } } } } }
