{
  "info": {
    "name": "PayIran API v1",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.payiran.org/v1"
    },
    {
      "key": "api_key",
      "value": ""
    },
    {
      "key": "api_secret",
      "value": ""
    },
    {
      "key": "timestamp",
      "value": ""
    },
    {
      "key": "nonce",
      "value": ""
    },
    {
      "key": "signature",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "Balance",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-PIS-Key",
            "value": "{{api_key}}"
          },
          {
            "key": "X-PIS-Timestamp",
            "value": "{{timestamp}}"
          },
          {
            "key": "X-PIS-Nonce",
            "value": "{{nonce}}"
          },
          {
            "key": "X-PIS-Signature-Version",
            "value": "2"
          },
          {
            "key": "X-PIS-Signature",
            "value": "{{signature}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{base_url}}/balance"
      }
    },
    {
      "name": "Daily Summary",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-PIS-Key",
            "value": "{{api_key}}"
          },
          {
            "key": "X-PIS-Timestamp",
            "value": "{{timestamp}}"
          },
          {
            "key": "X-PIS-Nonce",
            "value": "{{nonce}}"
          },
          {
            "key": "X-PIS-Signature-Version",
            "value": "2"
          },
          {
            "key": "X-PIS-Signature",
            "value": "{{signature}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{base_url}}/daily-summary?date=2026-10-07"
      }
    },
    {
      "name": "Create Payment",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-PIS-Key",
            "value": "{{api_key}}"
          },
          {
            "key": "X-PIS-Timestamp",
            "value": "{{timestamp}}"
          },
          {
            "key": "X-PIS-Nonce",
            "value": "{{nonce}}"
          },
          {
            "key": "X-PIS-Signature-Version",
            "value": "2"
          },
          {
            "key": "X-PIS-Signature",
            "value": "{{signature}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "order-12345678"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\"order_id\": \"ORDER-123\", \"amount\": 2500000, \"card\": \"6037991234567890\", \"callback\": \"https://example.com/payiran/webhook\", \"return_url\": \"https://example.com/result\"}"
        },
        "url": "{{base_url}}/payments"
      }
    },
    {
      "name": "Get Payment",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-PIS-Key",
            "value": "{{api_key}}"
          },
          {
            "key": "X-PIS-Timestamp",
            "value": "{{timestamp}}"
          },
          {
            "key": "X-PIS-Nonce",
            "value": "{{nonce}}"
          },
          {
            "key": "X-PIS-Signature-Version",
            "value": "2"
          },
          {
            "key": "X-PIS-Signature",
            "value": "{{signature}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{base_url}}/payments/ORDER-123"
      }
    },
    {
      "name": "Sandbox Card Mismatch",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-PIS-Key",
            "value": "{{api_key}}"
          },
          {
            "key": "X-PIS-Timestamp",
            "value": "{{timestamp}}"
          },
          {
            "key": "X-PIS-Nonce",
            "value": "{{nonce}}"
          },
          {
            "key": "X-PIS-Signature-Version",
            "value": "2"
          },
          {
            "key": "X-PIS-Signature",
            "value": "{{signature}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\"order_id\": \"SANDBOX-001\", \"amount\": 100000, \"card\": \"6037991234567890\", \"paid_card\": \"6219861111111111\", \"callback\": \"https://example.com/payiran/webhook\", \"scenario\": \"card_mismatch\"}"
        },
        "url": "{{base_url}}/sandbox/payments"
      }
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "const ts=Math.floor(Date.now()/1000).toString();",
          "const nonce='pm-'+pm.variables.replaceIn('{{$guid}}').replace(/-/g,'');",
          "const raw=(pm.request.body&&pm.request.body.mode==='raw')?pm.variables.replaceIn(pm.request.body.raw||''):'';",
          "const bh=CryptoJS.SHA256(raw).toString(CryptoJS.enc.Hex);",
          "const path='/'+pm.request.url.path.join('/');",
          "const canonical=[ts,nonce,pm.request.method.toUpperCase(),path,bh].join('\\n');",
          "const key=pm.collectionVariables.get('api_secret')||'';",
          "const sig=CryptoJS.HmacSHA256(canonical,key).toString(CryptoJS.enc.Hex);",
          "pm.collectionVariables.set('timestamp',ts);",
          "pm.collectionVariables.set('nonce',nonce);",
          "pm.collectionVariables.set('signature',sig);"
        ]
      }
    }
  ]
}