{
  "info": {
    "name": "IOPAY API - Starter",
    "description": "Starter collection para autenticação e primeiros requests na API IOPAY.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.iopay.com.br/api"
    },
    {
      "key": "auth_email",
      "value": ""
    },
    {
      "key": "auth_secret",
      "value": ""
    },
    {
      "key": "io_seller_id",
      "value": ""
    },
    {
      "key": "iopay_token",
      "value": ""
    },
    {
      "key": "customer_id",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "Autenticação",
      "item": [
        {
          "name": "Obter access token",
          "request": {
            "auth": {
              "type": "noauth"
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"{{auth_email}}\",\n  \"secret\": \"{{auth_secret}}\",\n  \"io_seller_id\": \"{{io_seller_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/auth/login",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "auth",
                "login"
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "const response = pm.response.json();",
                  "",
                  "if (response.access_token) {",
                  "    pm.collectionVariables.set('iopay_token', response.access_token);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "response": []
        }
      ]
    },
    {
      "name": "Customers",
      "item": [
        {
          "name": "Criar customer",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{iopay_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"first_name\": \"Maria\",\n  \"last_name\": \"Oliveira\",\n  \"customer_type\": \"person_natural\",\n  \"email\": \"maria@exemplo.com\",\n  \"taxpayer_id\": \"12345678909\",\n  \"phone_number\": \"+5511999999999\",\n  \"address\": {\n    \"line1\": \"Av. Paulista\",\n    \"line2\": \"1000\",\n    \"line3\": \"Apto 101\",\n    \"neighborhood\": \"Bela Vista\",\n    \"city\": \"São Paulo\",\n    \"state\": \"SP\",\n    \"postal_code\": \"01310100\",\n    \"country_code\": \"BR\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/v1/customer/new",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "customer",
                "new"
              ]
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "const response = pm.response.json();",
                  "",
                  "if (response.success && response.success.id) {",
                  "    pm.collectionVariables.set('customer_id', response.success.id);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "response": []
        }
      ]
    },
    {
      "name": "Transações",
      "item": [
        {
          "name": "PIX - Criar cobrança",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{iopay_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 24990,\n  \"currency\": \"BRL\",\n  \"description\": \"Pedido #84217\",\n  \"statement_descriptor\": \"IOPAY STORE\",\n  \"io_seller_id\": \"{{io_seller_id}}\",\n  \"payment_type\": \"pix\",\n  \"reference_id\": \"pedido_84217\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/v1/transaction/new/{{customer_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "v1",
                "transaction",
                "new",
                "{{customer_id}}"
              ]
            }
          },
          "response": []
        }
      ]
    }
  ]
}