{
  "info": {
    "name": "Matrix Pay - Gateway API (v2)",
    "description": "# Matrix Pay - Gateway API (v2)\n\nDedicated collection for Matrix Pay payment gateway infrastructure.\nSupports UPI dynamic order generation, UPI status checking, Web3 Crypto (USDT) order generation, and on-chain block confirmation status checks.\n\n### Automated HMAC Signature Generation\nThis collection includes a built-in **Pre-request Script** that executes automatically before every request:\n1. Canonically sorts JSON keys and minifies the payload body\n2. Generates a fresh UNIX timestamp (`X-Timestamp`)\n3. Generates a cryptographic 16-byte random nonce (`X-Nonce`)\n4. Computes the HMAC-SHA256 signature (`X-Signature`) using your `client_secret`\n5. Automatically attaches them directly to the outgoing HTTP headers via `pm.request.headers.upsert`\n6. Logs generation details to the Postman Console for full visibility\n\n### Direct Secret Authentication (Alternative)\nYou can also omit headers and pass `client_id` and `client_secret` directly inside the JSON request body.\n\n### Variables Required (Set in your Environment):\n- `base_url`: `https://matrixpay.vercel.app` (or your custom domain)\n- `client_id`: Your merchant Client ID (`mp_live_...` or `mp_test_...`)\n- `client_secret`: Your merchant Secret (`sk_live_...` or `sk_test_...`)",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://matrixpay.vercel.app",
      "type": "string"
    },
    {
      "key": "client_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "client_secret",
      "value": "",
      "type": "string"
    },
    {
      "key": "last_upi_order_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "last_crypto_order_id",
      "value": "",
      "type": "string"
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "const CryptoJS = require('crypto-js');",
          "const clientId = pm.variables.get('client_id') || (pm.environment && pm.environment.get('client_id'));",
          "const secret = pm.variables.get('client_secret') || (pm.environment && pm.environment.get('client_secret'));",
          "const rawBody = pm.request.body ? (pm.request.body.raw || '') : '';",
          "const timestamp = Math.floor(Date.now() / 1000).toString();",
          "const nonce = CryptoJS.lib.WordArray.random(16).toString();",
          "",
          "pm.variables.set('timestamp', timestamp);",
          "pm.variables.set('nonce', nonce);",
          "if (pm.environment) {",
          "    pm.environment.set('timestamp', timestamp);",
          "    pm.environment.set('nonce', nonce);",
          "}",
          "",
          "if (clientId) {",
          "    pm.request.headers.upsert({ key: 'X-Client-Id', value: clientId });",
          "}",
          "pm.request.headers.upsert({ key: 'X-Timestamp', value: timestamp });",
          "pm.request.headers.upsert({ key: 'X-Nonce', value: nonce });",
          "",
          "if (secret) {",
          "    let minifiedBody = '{}';",
          "    if (rawBody && rawBody.trim()) {",
          "        try {",
          "            const parsed = JSON.parse(rawBody);",
          "            const sorted = {};",
          "            Object.keys(parsed).sort().forEach(key => {",
          "                sorted[key] = parsed[key];",
          "            });",
          "            minifiedBody = JSON.stringify(sorted);",
          "        } catch (e) {",
          "            minifiedBody = rawBody.trim();",
          "        }",
          "    }",
          "    const message = `${minifiedBody}.${timestamp}.${nonce}`;",
          "    const signature = CryptoJS.HmacSHA256(message, secret).toString();",
          "    pm.variables.set('signature', signature);",
          "    if (pm.environment) {",
          "        pm.environment.set('signature', signature);",
          "    }",
          "    pm.request.headers.upsert({ key: 'X-Signature', value: signature });",
          "    console.log('[Matrix Pay] Auto-generated X-Signature:', signature);",
          "    console.log('[Matrix Pay] Auto-generated X-Timestamp:', timestamp);",
          "    console.log('[Matrix Pay] Auto-generated X-Nonce:', nonce);",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "UPI Gateway",
      "description": "Endpoints to create UPI dynamic payment links and query real-time transaction statuses.",
      "item": [
        {
          "name": "Create UPI Order",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status code is 201 Created', function () {",
                  "    pm.response.to.have.status(201);",
                  "});",
                  "const res = pm.response.json();",
                  "const orderId = (res && res.data && res.data.order_id) || (res && res.order_id);",
                  "if (orderId) {",
                  "    pm.variables.set('last_upi_order_id', orderId);",
                  "    if (pm.environment) {",
                  "        pm.environment.set('last_upi_order_id', orderId);",
                  "    }",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Client-Id",
                "value": "{{client_id}}",
                "description": "Your Merchant Client ID"
              },
              {
                "key": "X-Signature",
                "value": "{{signature}}",
                "description": "Auto-calculated HMAC-SHA256 signature"
              },
              {
                "key": "X-Timestamp",
                "value": "{{timestamp}}",
                "description": "Current UNIX timestamp"
              },
              {
                "key": "X-Nonce",
                "value": "{{nonce}}",
                "description": "Random nonce string"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": \"100.00\",\n  \"customer_name\": \"John Doe\",\n  \"customer_email\": \"john@gmail.com\",\n  \"customer_mobile\": \"9876543210\",\n  \"redirect_url\": \"https://matrixpay.vercel.app/success\",\n  \"remark\": \"Payment for Order #1001\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/api/v2/payment_gateway/create_upi_order",
              "host": ["{{base_url}}"],
              "path": ["api", "v2", "payment_gateway", "create_upi_order"]
            },
            "description": "Generates a dynamic UPI payment link, QR payload, and intent URL."
          },
          "response": []
        },
        {
          "name": "Check UPI Order Status",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status code is 200 or 202', function () {",
                  "    pm.expect(pm.response.code).to.be.oneOf([200, 202]);",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Client-Id",
                "value": "{{client_id}}",
                "description": "Your Merchant Client ID"
              },
              {
                "key": "X-Signature",
                "value": "{{signature}}",
                "description": "Auto-calculated HMAC-SHA256 signature"
              },
              {
                "key": "X-Timestamp",
                "value": "{{timestamp}}",
                "description": "Current UNIX timestamp"
              },
              {
                "key": "X-Nonce",
                "value": "{{nonce}}",
                "description": "Random nonce string"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"order_id\": \"{{last_upi_order_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/api/v2/payment_gateway/check_upi_order_status",
              "host": ["{{base_url}}"],
              "path": ["api", "v2", "payment_gateway", "check_upi_order_status"]
            },
            "description": "Retrieve status details of an existing UPI payment link or transaction."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Crypto Gateway (USDT)",
      "description": "Endpoints to accept USDT on BNB Smart Chain (BEP20), Polygon, and TRON with automated block confirmation indexing.",
      "item": [
        {
          "name": "Create Crypto Order",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status code is 201 Created', function () {",
                  "    pm.response.to.have.status(201);",
                  "});",
                  "const res = pm.response.json();",
                  "const orderId = (res && res.data && res.data.order_id) || (res && res.order_id);",
                  "if (orderId) {",
                  "    pm.variables.set('last_crypto_order_id', orderId);",
                  "    if (pm.environment) {",
                  "        pm.environment.set('last_crypto_order_id', orderId);",
                  "    }",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Client-Id",
                "value": "{{client_id}}",
                "description": "Your Merchant Client ID"
              },
              {
                "key": "X-Signature",
                "value": "{{signature}}",
                "description": "Auto-calculated HMAC-SHA256 signature"
              },
              {
                "key": "X-Timestamp",
                "value": "{{timestamp}}",
                "description": "Current UNIX timestamp"
              },
              {
                "key": "X-Nonce",
                "value": "{{nonce}}",
                "description": "Random nonce string"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": \"25.5000\",\n  \"redirect_url\": \"https://matrixpay.vercel.app/success\",\n  \"customer_name\": \"John Doe\",\n  \"customer_email\": \"john@gmail.com\",\n  \"customer_mobile\": \"9876543210\",\n  \"selected_network\": \"BEP20\",\n  \"comment\": \"Crypto Order #2048\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/api/v2/payment_gateway/create_crypto_order",
              "host": ["{{base_url}}"],
              "path": ["api", "v2", "payment_gateway", "create_crypto_order"]
            },
            "description": "Generates a dynamic Web3 USDT crypto payment address and checkout URL."
          },
          "response": []
        },
        {
          "name": "Check Crypto Order Status",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Status code is 200 or 202', function () {",
                  "    pm.expect(pm.response.code).to.be.oneOf([200, 202]);",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Client-Id",
                "value": "{{client_id}}",
                "description": "Your Merchant Client ID"
              },
              {
                "key": "X-Signature",
                "value": "{{signature}}",
                "description": "Auto-calculated HMAC-SHA256 signature"
              },
              {
                "key": "X-Timestamp",
                "value": "{{timestamp}}",
                "description": "Current UNIX timestamp"
              },
              {
                "key": "X-Nonce",
                "value": "{{nonce}}",
                "description": "Random nonce string"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"order_id\": \"{{last_crypto_order_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/api/v2/payment_gateway/check_crypto_order_status",
              "host": ["{{base_url}}"],
              "path": ["api", "v2", "payment_gateway", "check_crypto_order_status"]
            },
            "description": "Check the on-chain confirmation and settlement status of an existing crypto order."
          },
          "response": []
        }
      ]
    }
  ]
}
