{
  "info": {
    "name": "i-gaming Sandbox — Seamless Wallet",
    "description": "Sandbox collection for testing seamless wallet integration (HMAC-SHA256 signed). Base: https://sandbox.i-gaming.co/api/public/v1/sandbox/wallet",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_postman_id": "igaming-sandbox-v1"
  },
  "variable": [
    { "key": "baseUrl", "value": "https://sandbox.i-gaming.co/api/public/v1/sandbox/wallet" },
    { "key": "hmacSecret", "value": "sk_sandbox_replace_me" },
    { "key": "userId", "value": "demo_1" },
    { "key": "currency", "value": "BRL" }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Auto-sign body with HMAC-SHA256(body, hmacSecret)",
          "const secret = pm.collectionVariables.get('hmacSecret');",
          "const body = pm.request.body && pm.request.body.raw ? pm.request.body.raw : '';",
          "if (body && secret) {",
          "  const sig = CryptoJS.HmacSHA256(body, secret).toString(CryptoJS.enc.Hex);",
          "  pm.request.headers.upsert({ key: 'x-signature', value: sig });",
          "}",
          "pm.request.headers.upsert({ key: 'x-idempotency-key', value: pm.variables.replaceIn('{{$guid}}') });"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Authenticate",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": { "raw": "{{baseUrl}}/authenticate", "host": ["{{baseUrl}}"], "path": ["authenticate"] },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"token\":\"launch_token_demo\"}" }
      }
    },
    {
      "name": "Balance",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": { "raw": "{{baseUrl}}/balance", "host": ["{{baseUrl}}"], "path": ["balance"] },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"currency\":\"{{currency}}\"}" }
      }
    },
    {
      "name": "Debit (bet)",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": { "raw": "{{baseUrl}}/debit", "host": ["{{baseUrl}}"], "path": ["debit"] },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"amount\":100,\"currency\":\"{{currency}}\",\"round_id\":\"r_1\",\"tx_id\":\"tx_debit_1\"}" }
      }
    },
    {
      "name": "Credit (win)",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": { "raw": "{{baseUrl}}/credit", "host": ["{{baseUrl}}"], "path": ["credit"] },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"amount\":250,\"currency\":\"{{currency}}\",\"round_id\":\"r_1\",\"tx_id\":\"tx_credit_1\"}" }
      }
    },
    {
      "name": "Rollback",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": { "raw": "{{baseUrl}}/rollback", "host": ["{{baseUrl}}"], "path": ["rollback"] },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"tx_id\":\"tx_debit_1\",\"round_id\":\"r_1\"}" }
      }
    },
    {
      "name": "Query transaction",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": { "raw": "{{baseUrl}}/query", "host": ["{{baseUrl}}"], "path": ["query"] },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"tx_id\":\"tx_debit_1\"}" }
      }
    },
    {
      "name": "Stats",
      "request": {
        "method": "GET",
        "url": { "raw": "{{baseUrl}}/stats?user_id={{userId}}", "host": ["{{baseUrl}}"], "path": ["stats"], "query": [{ "key": "user_id", "value": "{{userId}}" }] }
      }
    },
    {
      "name": "Reset sandbox user",
      "request": {
        "method": "GET",
        "url": { "raw": "{{baseUrl}}/reset?user_id={{userId}}", "host": ["{{baseUrl}}"], "path": ["reset"], "query": [{ "key": "user_id", "value": "{{userId}}" }] }
      }
    },
    {
      "name": "Failure injection example (500 rate)",
      "request": {
        "method": "POST",
        "header": [{ "key": "content-type", "value": "application/json" }],
        "url": {
          "raw": "{{baseUrl}}/debit?err_rate=0.3&lat_max=800",
          "host": ["{{baseUrl}}"],
          "path": ["debit"],
          "query": [
            { "key": "err_rate", "value": "0.3", "description": "0-1 probability of forced 500" },
            { "key": "lat_max", "value": "800", "description": "max artificial latency in ms" }
          ]
        },
        "body": { "mode": "raw", "raw": "{\"user_id\":\"{{userId}}\",\"amount\":50,\"currency\":\"{{currency}}\",\"round_id\":\"r_fail\",\"tx_id\":\"tx_fail_1\"}" }
      }
    }
  ]
}
