{
  "info": {
    "name": "PayVerify API v1",
    "description": "Set variables: baseUrl (https://YOUR_DOMAIN), apiKey (pv_test_… to start), and for webhook testing: webhookUrl + webhookSecret.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://YOUR_DOMAIN"
    },
    {
      "key": "apiKey",
      "value": "pv_test_xxx"
    },
    {
      "key": "orderId",
      "value": ""
    },
    {
      "key": "webhookUrl",
      "value": "https://yoursite.com/payverify/webhook"
    },
    {
      "key": "webhookSecret",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "Create order",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.request.headers.upsert({ key: \"Idempotency-Key\", value: \"order-\" + Date.now() });"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 200 || pm.response.code === 201) { pm.collectionVariables.set(\"orderId\", pm.response.json().id); }"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"amount\": 149,\n  \"order_id\": \"INV-1001\",\n  \"customer_name\": \"Rahul\",\n  \"note\": \"Pro plan\",\n  \"return_url\": \"https://yoursite.com/thanks\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/orders",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "orders"
          ]
        }
      }
    },
    {
      "name": "Get order",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/orders/{{orderId}}",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "orders",
            "{{orderId}}"
          ]
        }
      }
    },
    {
      "name": "List orders",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/orders",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "orders"
          ],
          "query": [
            {
              "key": "status",
              "value": "paid",
              "disabled": true
            },
            {
              "key": "order_id",
              "value": "INV-1001",
              "disabled": true
            },
            {
              "key": "limit",
              "value": "20"
            }
          ]
        }
      }
    },
    {
      "name": "Simulate payment (test key only)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"outcome\": \"paid\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/orders/{{orderId}}/simulate",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "orders",
            "{{orderId}}",
            "simulate"
          ]
        }
      }
    },
    {
      "name": "Send signed test event to my webhook",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const t = Math.floor(Date.now() / 1000);",
              "const body = JSON.stringify({ id: 'evt_postman_test', type: 'order.paid', created: t, livemode: false, data: { order: { id: 'TEST', order_id: 'INV-1', status: 'paid', currency: 'INR', amount: 149.37 } } });",
              "const sig = CryptoJS.HmacSHA256(t + '.' + body, pm.collectionVariables.get('webhookSecret')).toString();",
              "pm.variables.set('rawBody', body);",
              "pm.variables.set('signature', 't=' + t + ',v1=' + sig);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "X-PayVerify-Signature",
            "value": "{{signature}}"
          },
          {
            "key": "X-PayVerify-Event",
            "value": "order.paid"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{{rawBody}}"
        },
        "url": {
          "raw": "{{webhookUrl}}",
          "host": [
            "{{webhookUrl}}"
          ]
        }
      }
    }
  ]
}
