{
  "info": {
    "name": "CheapOTP Customer API",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Set apiKey and service/country IDs from the catalogue. maxPriceUsdt is optional: leave empty to accept the current price, or set a positive USDT cap. Keep requestId unchanged for retries of the same purchase."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://cheapestotp.com/api/v1"
    },
    {
      "key": "apiKey",
      "value": ""
    },
    {
      "key": "countryId",
      "value": ""
    },
    {
      "key": "serviceId",
      "value": ""
    },
    {
      "key": "maxPriceUsdt",
      "value": ""
    },
    {
      "key": "requestId",
      "value": ""
    },
    {
      "key": "orderId",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "Account",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/account",
        "header": []
      }
    },
    {
      "name": "Countries",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/countries",
        "header": []
      }
    },
    {
      "name": "Services",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/services",
        "header": []
      }
    },
    {
      "name": "Rent",
      "request": {
        "method": "POST",
        "url": "{{baseUrl}}/orders",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{requestId}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\"serviceId\": {{serviceId}}, \"countryId\": {{countryId}}}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const service = String(pm.variables.get(\"serviceId\") || \"\");",
              "const country = String(pm.variables.get(\"countryId\") ?? \"\");",
              "if (!/^[1-9][0-9]*$/.test(service) || !/^[0-9]+$/.test(country)) throw new Error(\"Set serviceId and countryId from the catalogue first\");",
              "const body = {serviceId: Number(service), countryId: Number(country)};",
              "const cap = String(pm.variables.get(\"maxPriceUsdt\") ?? \"\").trim();",
              "if (cap) body.maxPriceUsdt = cap;",
              "pm.request.body.update(JSON.stringify(body));"
            ]
          }
        }
      ]
    },
    {
      "name": "Order status",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/orders/{{orderId}}",
        "header": []
      }
    },
    {
      "name": "Cancel",
      "request": {
        "method": "POST",
        "url": "{{baseUrl}}/orders/{{orderId}}/cancel",
        "header": []
      }
    },
    {
      "name": "Orders",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/orders",
        "header": []
      }
    },
    {
      "name": "Transactions",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/transactions",
        "header": []
      }
    }
  ]
}
