{
  "info": {
    "name": "ZiniPay Sandbox API",
    "description": "ZiniPay Sandbox API v1.0 — Create & Verify Invoices",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.zinipay.com",
      "type": "string"
    },
    {
      "key": "api_key",
      "value": "sandbox_test_8f4c9a2e7b31",
      "type": "string"
    },
    {
      "key": "invoice_id",
      "value": "",
      "type": "string",
      "description": "Auto-filled after Create Invoice is run"
    }
  ],
  "item": [
    {
      "name": "Create Invoice",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "const res = pm.response.json();",
              "if (res.payment_url) {",
              "  const id = res.payment_url.split('/').pop();",
              "  pm.collectionVariables.set('invoice_id', id);",
              "  console.log('invoice_id set to:', id);",
              "}",
              "pm.test('Status true', () => pm.expect(res.status).to.be.true);",
              "pm.test('payment_url returned', () => pm.expect(res.payment_url).to.be.a('string'));"
            ],
            "type": "text/javascript"
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "zini-api-key",
            "value": "{{api_key}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"cus_name\": \"John Doe\",\n  \"cus_email\": \"john@example.com\",\n  \"amount\": 1200,\n  \"metadata\": {\n    \"order_id\": \"ORD-1001\",\n    \"customer_id\": \"CUS-9001\"\n  },\n  \"redirect_url\": \"https://merchant.com/payment/success\",\n  \"cancel_url\": \"https://merchant.com/payment/cancel\",\n  \"webhook_url\": \"https://merchant.com/api/zinipay/webhook\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{base_url}}/v1/payment/create",
          "host": ["{{base_url}}"],
          "path": ["v1", "payment", "create"]
        },
        "description": "Creates a hosted invoice and returns a payment_url. The invoice_id is auto-extracted from payment_url and saved to collection variable."
      },
      "response": [
        {
          "name": "Success",
          "originalRequest": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "zini-api-key", "value": "{{api_key}}" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"cus_name\": \"John Doe\",\n  \"cus_email\": \"john@example.com\",\n  \"amount\": 1200,\n  \"metadata\": { \"order_id\": \"ORD-1001\" },\n  \"redirect_url\": \"https://merchant.com/payment/success\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/v1/payment/create",
              "host": ["{{base_url}}"],
              "path": ["v1", "payment", "create"]
            }
          },
          "status": "OK",
          "code": 200,
          "header": [{ "key": "Content-Type", "value": "application/json" }],
          "body": "{\n  \"status\": true,\n  \"message\": \"Invoice created successfully.\",\n  \"payment_url\": \"https://secure.zinipay.com/payment/INVOICE_ID\"\n}"
        }
      ]
    },
    {
      "name": "Verify Invoice",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "const res = pm.response.json();",
              "pm.test('Has invoice_id', () => pm.expect(res.invoice_id).to.be.a('string'));",
              "pm.test('Has status', () => pm.expect(res.status).to.be.oneOf(['PENDING', 'COMPLETED', 'FAILED']));",
              "pm.test('Has amount', () => pm.expect(res.amount).to.be.a('number'));"
            ],
            "type": "text/javascript"
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "zini-api-key",
            "value": "{{api_key}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"invoice_id\": \"{{invoice_id}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{base_url}}/v1/payment/verify",
          "host": ["{{base_url}}"],
          "path": ["v1", "payment", "verify"]
        },
        "description": "Verifies payment status of an invoice. Uses {{invoice_id}} auto-set by Create Invoice. Manually paste an ID to test independently."
      },
      "response": [
        {
          "name": "Completed",
          "originalRequest": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "zini-api-key", "value": "{{api_key}}" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"invoice_id\": \"INVOICE_ID\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/v1/payment/verify",
              "host": ["{{base_url}}"],
              "path": ["v1", "payment", "verify"]
            }
          },
          "status": "OK",
          "code": 200,
          "header": [{ "key": "Content-Type", "value": "application/json" }],
          "body": "{\n  \"cus_name\": \"John Doe\",\n  \"cus_email\": \"john@example.com\",\n  \"amount\": 1200,\n  \"invoice_id\": \"INVOICE_ID\",\n  \"payment_method\": \"bkash\",\n  \"transaction_id\": \"TXN123456789\",\n  \"status\": \"COMPLETED\"\n}"
        }
      ]
    }
  ]
}
