{
  "info": {
    "name": "Altha One | Pix — API LIVE",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "API real. Chave privada no backend. Consulte /docs antes de operar. POSTs desabilitados por padrão pelo script de preparação; ative somente para uma ordem financeira real autorizada."
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.althaone.com.br/api/v1/pix"
    },
    {
      "key": "api_key",
      "value": ""
    },
    {
      "key": "charges_idempotency_key",
      "value": ""
    },
    {
      "key": "withdrawals_idempotency_key",
      "value": ""
    },
    {
      "key": "charge_id",
      "value": ""
    },
    {
      "key": "withdrawal_id",
      "value": ""
    },
    {
      "key": "allow_live_writes",
      "value": "false"
    }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{api_key}}",
        "type": "string"
      }
    ]
  },
  "item": [
    {
      "name": "Criar charges",
      "request": {
        "method": "POST",
        "url": "{{base_url}}/charges",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{charges_idempotency_key}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"amount_minor\": 10000,\n  \"external_reference\": \"exemplo-123\",\n  \"description\": \"Pedido de exemplo\",\n  \"expires_in_seconds\": 3600\n}"
        }
      }
    },
    {
      "name": "Listar charges",
      "request": {
        "method": "GET",
        "url": "{{base_url}}/charges"
      }
    },
    {
      "name": "Consultar charges",
      "request": {
        "method": "GET",
        "url": "{{base_url}}/charges/{{charge_id}}"
      }
    },
    {
      "name": "Criar withdrawals",
      "request": {
        "method": "POST",
        "url": "{{base_url}}/withdrawals",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{withdrawals_idempotency_key}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"amount_minor\": 10000,\n  \"external_reference\": \"exemplo-123\"\n}"
        }
      }
    },
    {
      "name": "Listar withdrawals",
      "request": {
        "method": "GET",
        "url": "{{base_url}}/withdrawals"
      }
    },
    {
      "name": "Consultar withdrawals",
      "request": {
        "method": "GET",
        "url": "{{base_url}}/withdrawals/{{withdrawal_id}}"
      }
    },
    {
      "name": "Saldo",
      "request": {
        "method": "GET",
        "url": "{{base_url}}/balance"
      }
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "const base=pm.variables.get('base_url');",
          "if(base!=='https://api.althaone.com.br/api/v1/pix') throw new Error('URL LIVE não corresponde à API Altha One');",
          "if(pm.request.method==='POST'&&pm.variables.get('allow_live_writes')!=='true'){pm.execution.skipRequest();}",
          "if(!/^ao_live_[A-Za-z0-9_-]{43}$/.test(pm.variables.get('api_key')||'')) throw new Error('Configure a credencial LIVE privadamente');",
          "if(pm.request.method==='POST'){const name=pm.request.url.toString().includes('withdrawals')?'withdrawals_idempotency_key':'charges_idempotency_key';if(!pm.variables.get(name))throw new Error('Persista a chave de idempotência antes do POST');}"
        ]
      }
    },
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.test('Resposta JSON',()=>pm.response.to.be.json);",
          "const d=pm.response.json();",
          "if(d.id&&pm.response.code<300){pm.collectionVariables.set(pm.request.url.toString().includes('withdrawals')?'withdrawal_id':'charge_id',d.id);}",
          "pm.test('HTTP aceito',()=>pm.expect(pm.response.code).to.be.within(200,299));"
        ]
      }
    }
  ]
}