{
  "info": {
    "_postman_id": "a4db732c-8e82-4e10-b7ea-0a00b881a1ad",
    "name": "Owem Pay - API Externa",
    "description": "API externa Owem Pay para integração de parceiros.\n\n## Autenticação\n- Header: `Authorization: ApiKey <client_id>:<client_secret>`\n- IP Whitelist obrigatório (403 se IP não cadastrado)\n\n## HMAC (apenas POST)\n- Header: `hmac: <hex_sha512>`\n- Algoritmo: HMAC-SHA512 do body JSON com client_secret\n- IMPORTANTE: O backend normaliza o body (JSON parse → re-encode). Erlang ordena keys alfabeticamente para maps pequenos. Use sort_keys no seu SDK.\n- GET/DELETE não precisam de HMAC (sem body para assinar)\n\n## Valores Monetários\n### Entrada (request body)\n- **amount** é integer em **centavos** (1/100 do Real)\n- R$1,00 = 100 | R$5,00 = 500 | R$0,50 = 50\n\n### Saída (response body)\n- **amount** é integer em **subcentavos** (1/10.000 do Real, ou 1/100 do centavo)\n- R$1,00 = 10.000 | R$5,00 = 50.000 | R$0,035 (tarifa) = 350\n- **balance** (saldo) também retorna em subcentavos\n- Para converter subcentavos → Reais: dividir por 10.000\n- Para converter subcentavos → centavos: dividir por 100\n\n## Respostas\n- POST PIX Cash-Out: {worked, transaction_id, end_to_end_id, amount (subcentavos), status, detail}\n- POST PIX Cash-In: {worked, transaction_id, qrcode_emv, amount (subcentavos)}\n- GET /balance: {balance (subcentavos), available (subcentavos)}\n- GET /transactions: lista com amount em subcentavos\n- Erros: {errors: {status_key: message}} ou {worked: false, detail: msg}",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "6885436"
  },
  "item": [
    {
      "name": "Health & Auth",
      "item": [
        {
          "name": "Health Check (sem auth)",
          "request": {
            "auth": {
              "type": "noauth"
            },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "https://api.owem.com.br/health",
              "protocol": "https",
              "host": [
                "api",
                "owem",
                "com",
                "br"
              ],
              "path": [
                "health"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Consultar Saldo",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/balance",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "balance"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Extrato",
      "item": [
        {
          "name": "Consultar Extrato",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/statement?date_from=2026-03-01&date_to=2026-03-31",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "statement"
              ],
              "query": [
                {
                  "key": "date_from",
                  "value": "2026-03-01"
                },
                {
                  "key": "date_to",
                  "value": "2026-03-31"
                }
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "PIX",
      "item": [
        {
          "name": "PIX Cash-Out (Enviar por Chave DICT)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200 || pm.response.code === 202) {",
                  "    const resp = pm.response.json();",
                  "    if (resp.transaction_id) pm.collectionVariables.set('last_transaction_id', resp.transaction_id);",
                  "    if (resp.end_to_end_id) pm.collectionVariables.set('last_e2e_id', resp.end_to_end_id);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 100,\n  \"pix_key\": \"07615661986\",\n  \"description\": \"Pagamento via API\",\n  \"external_id\": \"payment-001\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/pix/cash-out",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "cash-out"
              ]
            }
          },
          "response": []
        },
        {
          "name": "PIX Cash-Out (Enviar por Email)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 500,\n  \"pix_key\": \"email@destinatario.com.br\",\n  \"description\": \"Pagamento R$5 via email\",\n  \"external_id\": \"payment-002\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/pix/cash-out",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "cash-out"
              ]
            }
          },
          "response": []
        },
        {
          "name": "PIX Cash-Out (Enviar por Copia e Cola)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"emv\": \"COLE_O_CODIGO_COPIA_E_COLA_AQUI\",\n  \"amount\": 100,\n  \"description\": \"Pagamento R$1 via copia e cola\",\n  \"external_id\": \"payment-003\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/pix/cash-out",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "cash-out"
              ]
            }
          },
          "response": []
        },
        {
          "name": "PIX Cash-In (Gerar QR Code)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200) {",
                  "    const resp = pm.response.json();",
                  "    if (resp.transaction_id) pm.collectionVariables.set('last_qr_tx_id', resp.transaction_id);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 500,\n  \"description\": \"Cobranca R$5,00\",\n  \"external_id\": \"order-12345\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/pix/cash-in",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "cash-in"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Aprovar Cash-Out",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"transaction_id\": \"{{last_transaction_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/pix/cash-out/approve",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "cash-out",
                "approve"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Listar Transações",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/transactions?page=1&per_page=20",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "transactions"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "per_page",
                  "value": "20"
                },
                {
                  "key": "status",
                  "value": "",
                  "disabled": true
                },
                {
                  "key": "type",
                  "value": "",
                  "disabled": true
                },
                {
                  "key": "date_from",
                  "value": "2026-03-01",
                  "disabled": true
                },
                {
                  "key": "date_to",
                  "value": "2026-03-31",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Consultar Transação por ID",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/transactions/{{last_transaction_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "transactions",
                "{{last_transaction_id}}"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Consultar Transação por E2E",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/transactions/e2e/{{last_e2e_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "transactions",
                "e2e",
                "{{last_e2e_id}}"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Consultar por Tag",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/transactions/tag/PIXIN2026",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "transactions",
                "tag",
                "PIXIN2026"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Consultar por External ID",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200) {",
                  "    const resp = pm.response.json();",
                  "    console.log(\"Found:\", resp.data?.transaction_id);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/transactions/ref/order-12345",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "transactions",
                "ref",
                "order-12345"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Comprovante (Receipt)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/transactions/{{last_transaction_id}}/receipt",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "transactions",
                "{{last_transaction_id}}",
                "receipt"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Listar Chaves PIX",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/pix/keys",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "keys"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Solicitar Devolução (Refund)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"original_transaction_id\": \"{{last_e2e_id}}\",\n  \"amount\": 100,\n  \"reason\": \"Devolucao solicitada pelo cliente\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/pix/refund",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "pix",
                "refund"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Webhooks",
      "item": [
        {
          "name": "Listar Webhooks",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/webhooks",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "webhooks"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Registrar Webhook",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"url\": \"https://seu-servidor.com/webhook\",\n  \"events\": [\"pix.charge.paid\", \"pix.payout.confirmed\", \"pix.payout.failed\", \"pix.payout.returned\", \"pix.return.received\", \"pix.charge.expired\"],\n  \"description\": \"Webhook principal\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/webhooks",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "webhooks"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Remover Webhook",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{base_url}}/webhooks/WEBHOOK_ID_AQUI",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "webhooks",
                "WEBHOOK_ID_AQUI"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "MED",
      "item": [
        {
          "name": "Listar MEDs",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/med",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "med"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Detalhe MED",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/med/MED_ID_AQUI",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "med",
                "MED_ID_AQUI"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Validação",
      "item": [
        {
          "name": "Validar CPF",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"cpf\": \"12345678909\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "Valida um CPF. O campo principal é `cpf`, mas `document_number` também é aceito como alternativa.",
            "url": {
              "raw": "{{base_url}}/cpf/validate",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "cpf",
                "validate"
              ]
            }
          },
          "response": []
        }
      ]
    }
  ],
  "auth": {
    "type": "apikey",
    "apikey": [
      {
        "key": "key",
        "value": "Authorization",
        "type": "string"
      },
      {
        "key": "value",
        "value": "ApiKey {{client_id}}:{{client_secret}}",
        "type": "string"
      },
      {
        "key": "in",
        "value": "header",
        "type": "string"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// HMAC-SHA512 — only for POST requests with body",
          "const method = pm.request.method;",
          "const body = pm.request.body ? pm.request.body.raw || '' : '';",
          "const secret = pm.collectionVariables.get('client_secret');",
          "",
          "if (method === 'POST' && body && secret) {",
          "    // Parse and re-encode with sorted keys (Erlang small maps are key-sorted)",
          "    try {",
          "        const parsed = JSON.parse(body);",
          "        const sorted = JSON.stringify(parsed, Object.keys(parsed).sort());",
          "        const hmac = CryptoJS.HmacSHA512(sorted, secret).toString(CryptoJS.enc.Hex);",
          "        pm.request.headers.add({ key: 'hmac', value: hmac });",
          "    } catch(e) {",
          "        // If body isn't valid JSON, HMAC the raw body",
          "        const hmac = CryptoJS.HmacSHA512(body, secret).toString(CryptoJS.enc.Hex);",
          "        pm.request.headers.add({ key: 'hmac', value: hmac });",
          "    }",
          "}"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.owem.com.br/api/external"
    },
    {
      "key": "client_id",
      "value": "YOUR_CLIENT_ID_HERE"
    },
    {
      "key": "client_secret",
      "value": "YOUR_CLIENT_SECRET_HERE"
    },
    {
      "key": "last_qr_tx_id",
      "value": ""
    },
    {
      "key": "last_transaction_id",
      "value": ""
    },
    {
      "key": "last_e2e_id",
      "value": ""
    }
  ]
}