{
  "info": {
    "_postman_id": "siamtechpay-rest-api-collection",
    "name": "SiamTechPay REST API",
    "description": "Official SiamTechPay payment gateway API. Two integrations: (1) the read/control API — set `baseUrl` and `token`, run **Auth › Get Token** first (its test script stores the token into `{{token}}`), list endpoints return `{ data, meta }`. (2) **Live Payments (HMAC-signed)** — the real money-movement API; set `origin`, `apiKey`, `hmacSecret` and `webhookSecret`, and each request's pre-request script signs it automatically.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Auth",
      "item": [
        {
          "name": "Get Token",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Capture the token into the {{token}} collection variable",
                  "const json = pm.response.json();",
                  "if (json && json.token) {",
                  "  pm.collectionVariables.set('token', json.token);",
                  "  pm.test('token saved', function () { pm.expect(json.token).to.be.a('string'); });",
                  "} else {",
                  "  pm.test('token present', function () { pm.expect.fail('no token in response'); });",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"you@example.com\",\n  \"password\": \"your-password\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/auth/token",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "auth",
                "token"
              ]
            },
            "description": "Authenticate with account credentials `{ email, password }` to obtain an opaque bearer token (not a JWT). Rate limited to 10 requests/min/IP; repeated failures lock the account for 15 minutes. Returns `{ token, token_type, user }`."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Account",
      "item": [
        {
          "name": "Current User",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/me",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "me"
              ]
            },
            "description": "Returns the authenticated user. Requires a bearer token or session cookie."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Resources",
      "item": [
        {
          "name": "List Transactions",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/transactions?page=1&per_page=25&status=success",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "transactions"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page (1-200)"
                },
                {
                  "key": "status",
                  "value": "success",
                  "description": "success | pending | failed"
                }
              ]
            },
            "description": "List transactions (module: transactions). Optional `status` filter."
          },
          "response": []
        },
        {
          "name": "List Settlements",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/settlements?page=1&per_page=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "settlements"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page (1-200)"
                }
              ]
            },
            "description": "List settlements (module: settlement)."
          },
          "response": []
        },
        {
          "name": "List Payouts",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/payouts?page=1&per_page=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "payouts"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page (1-200)"
                }
              ]
            },
            "description": "List payouts (module: payout)."
          },
          "response": []
        },
        {
          "name": "List Missing Transactions",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/missing-transactions?page=1&per_page=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "missing-transactions"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page (1-200)"
                }
              ]
            },
            "description": "List missing transactions (module: missing_transactions)."
          },
          "response": []
        },
        {
          "name": "List Alerts",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/alerts?page=1&per_page=25",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "alerts"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page (1-200)"
                }
              ]
            },
            "description": "List alerts (module: alerts)."
          },
          "response": []
        },
        {
          "name": "Update Alerts",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{token}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"action\": \"read_all\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/alerts",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "alerts"
              ]
            },
            "description": "Mark alerts read. Body `{ \"action\": \"read_all\" }` or `{ \"id\": \"AL-01\" }`. Requires manage access to the alerts module."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Live Payments (HMAC-signed)",
      "description": "Real money-movement API. Separate from the bearer-token read/control API. Every request is signed: set the `origin`, `apiKey`, `hmacSecret` and `webhookSecret` collection variables with YOUR own merchant credentials (the defaults below are non-functional placeholders). Each request's pre-request script computes `X-Signature` = HMAC-SHA256(secret, `{METHOD}:{path+query}:{timestamp}:{sha256hex(body)}`) with CryptoJS and sets `{{ts}}` + `{{sig}}` automatically.",
      "item": [
        {
          "name": "Create Payment",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Save the new payment id for the Get Payment / webhook requests.",
                  "const json = pm.response.json();",
                  "if (json && json.data && json.data.id) {",
                  "  pm.collectionVariables.set('paymentId', json.data.id);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 2500,\n  \"channel\": \"QRIS\",\n  \"orderId\": \"ORD-123\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{origin}}/api/v1/payments",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "payments"
              ]
            },
            "description": "Create a payment. `channel` = QRIS (PromptPay) | VA (Bank Transfer, with `method` = the bank code, e.g. SCB). Returns 201 with `{ data: { id, order_id, status: 'UNPAID', amount, fee, net, channel, qr_content, qr_image, va_number, payment_url, expires_at } }`. `qr_image` is a ready-to-display PNG data URI rendered from `qr_content` — no QR library needed on your end. When your account is routed to an acquirer that collects on its own page, `payment_url` is set instead of `qr_content` / `va_number`: send the player to that link. Idempotent on (merchant, orderId) — retrying with the same orderId returns the same payment."
          },
          "response": []
        },
        {
          "name": "Get Payment",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/payments/{{paymentId}}",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "payments",
                "{{paymentId}}"
              ]
            },
            "description": "Fetch a single payment's status and details. GET requests sign an empty body string."
          },
          "response": []
        },
        {
          "name": "List Payments",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/payments?page=1&per_page=25&status=PAID",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "payments"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page"
                },
                {
                  "key": "status",
                  "value": "PAID",
                  "description": "UNPAID | PAID | EXPIRED | CANCELED | REFUNDED | FAILED"
                }
              ]
            },
            "description": "List the merchant's payments (newest first). GET requests sign an empty body string; the signed path includes the query string."
          },
          "response": []
        },
        {
          "name": "Refund Payment",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/payments/{{paymentId}}/refund",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "payments",
                "{{paymentId}}",
                "refund"
              ]
            },
            "description": "Refund a captured (PAID) payment. Reverses the ledger capture; the payment moves to status REFUNDED. Returns `{ data: { id, status: 'REFUNDED', refunded } }`."
          },
          "response": []
        },
        {
          "name": "Cancel Payment",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/payments/{{paymentId}}/cancel",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "payments",
                "{{paymentId}}",
                "cancel"
              ]
            },
            "description": "Cancel (void) an UNPAID payment so its QR / VA can no longer be paid. The payment moves to status CANCELED. Returns `{ data: { id, status: 'CANCELED', canceled } }`."
          },
          "response": []
        },
        {
          "name": "Get Balance",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/balance",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "balance"
              ]
            },
            "description": "Real ledger balance: `{ data: { currency, available, pending, reserved, total } }`."
          },
          "response": []
        },
        {
          "name": "Create Disbursement",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Save the new disbursement id for the Get Disbursement request.",
                  "const json = pm.response.json();",
                  "if (json && json.data && json.data.id) {",
                  "  pm.collectionVariables.set('disbursementId', json.data.id);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{idempotencyKey}}",
                "disabled": true
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 1250,\n  \"bank\": \"Bangkok Bank (BBL)\",\n  \"account\": \"1234567890\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{origin}}/api/v1/disbursements",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "disbursements"
              ]
            },
            "description": "Create a payout. Funds are reserved atomically Returns 201 with `{ data: { id, ref_id, status, amount, fee, total, account_name, idempotency_key } }`. For safe retries, send an idempotency key via the `Idempotency-Key` header (enable it above) or a body field `idempotency_key`. Errors: 402 `insufficient_funds`. No PIN is needed."
          },
          "response": []
        },
        {
          "name": "List Disbursements",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/disbursements?page=1&per_page=25&status=COMPLETED",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "disbursements"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "1-based page number"
                },
                {
                  "key": "per_page",
                  "value": "25",
                  "description": "Items per page"
                },
                {
                  "key": "status",
                  "value": "COMPLETED",
                  "description": "PENDING | PROCESSING | COMPLETED | FAILED | REVIEW"
                }
              ]
            },
            "description": "List disbursements (newest first). GET requests sign an empty body string; the signed path includes the query string."
          },
          "response": []
        },
        {
          "name": "Get Disbursement",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "url": {
              "raw": "{{origin}}/api/v1/disbursements/{{disbursementId}}",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "disbursements",
                "{{disbursementId}}"
              ]
            },
            "description": "Fetch a single payout's status and details so you can poll one disbursement. GET requests sign an empty body string."
          },
          "response": []
        },
        {
          "name": "Provider Webhook (inbound)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('webhookSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"evt_demo_001\",\n  \"type\": \"payment.paid\",\n  \"paymentId\": \"{{paymentId}}\",\n  \"rrn\": \"RRN0001234567\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{origin}}/api/v1/callbacks/provider",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "callbacks",
                "provider"
              ]
            },
            "description": "INBOUND webhook the provider sends to the gateway (signed with the shared `webhookSecret`, not the merchant key). The gateway verifies `X-Signature` over the same canonical string, checks `X-Timestamp` freshness and de-duplicates on the event `id`. `type` = payment.paid | disbursement.completed | disbursement.failed. payment.paid credits PENDING; disbursement.completed moves reserved → out."
          },
          "response": []
        }
      ]
    },
    {
      "name": "Test mode (simulator)",
      "description": "Use your TEST keys (pk_test_…; switch Test mode on in the merchant portal → Developers). Test payments and payouts run on the simulator: no bank, no real money. These requests end one as a provider would and POST the real signed callback to your webhook endpoint; the response tells you whether your endpoint accepted it.",
      "item": [
        {
          "name": "Simulate Payment Outcome",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"outcome\": \"paid\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{origin}}/api/v1/sandbox/payments/{{paymentId}}/simulate",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "sandbox",
                "payments",
                "{{paymentId}}",
                "simulate"
              ]
            },
            "description": "`outcome` = paid | expired. Test mode only (403 live_account with live keys). Returns `{ data: { id, status, callback: { url, event, delivered, code, error } } }`."
          },
          "response": []
        },
        {
          "name": "Simulate Payout Outcome",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// HMAC-SHA256 request signing — canonical: {METHOD}:{path+query}:{timestamp}:{sha256hex(body)}",
                  "const CryptoJS = require('crypto-js');",
                  "const method = pm.request.method;",
                  "// Resolve variables so the signed path (incl. query string) and body match exactly what is sent.",
                  "const path = pm.variables.replaceIn(pm.request.url.getPathWithQuery());",
                  "const ts = new Date().toISOString();",
                  "let body = '';",
                  "if (pm.request.body && pm.request.body.mode === 'raw' && pm.request.body.raw) {",
                  "  body = pm.variables.replaceIn(pm.request.body.raw);",
                  "}",
                  "const secret = pm.collectionVariables.get('hmacSecret');",
                  "const bodyHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Hex);",
                  "const canonical = method + ':' + path + ':' + ts + ':' + bodyHash;",
                  "const sig = CryptoJS.HmacSHA256(canonical, secret).toString(CryptoJS.enc.Hex);",
                  "pm.collectionVariables.set('ts', ts);",
                  "pm.collectionVariables.set('sig', sig);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{apiKey}}"
              },
              {
                "key": "X-Timestamp",
                "value": "{{ts}}"
              },
              {
                "key": "X-Signature",
                "value": "{{sig}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"outcome\": \"completed\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{origin}}/api/v1/sandbox/payouts/{{disbursementId}}/simulate",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "v1",
                "sandbox",
                "payouts",
                "{{disbursementId}}",
                "simulate"
              ]
            },
            "description": "`outcome` = completed | failed. Test mode only. A test payout stays processing until you end it here or in the portal Simulator."
          },
          "response": []
        }
      ]
    },
    {
      "name": "System",
      "item": [
        {
          "name": "Health",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{origin}}/api/health",
              "host": [
                "{{origin}}"
              ],
              "path": [
                "api",
                "health"
              ]
            },
            "description": "Liveness probe. No auth required. Note: served at the root `/api/health`, not under `/api/v1`."
          },
          "response": []
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://siamtechpay.com/api/v1",
      "type": "string"
    },
    {
      "key": "token",
      "value": "",
      "type": "string"
    },
    {
      "key": "origin",
      "value": "https://siamtechpay.com",
      "type": "string"
    },
    {
      "key": "apiKey",
      "value": "pk_live_your_api_key",
      "type": "string"
    },
    {
      "key": "hmacSecret",
      "value": "sk_live_your_hmac_secret",
      "type": "string"
    },
    {
      "key": "webhookSecret",
      "value": "",
      "type": "string"
    },
    {
      "key": "idempotencyKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "paymentId",
      "value": "",
      "type": "string"
    },
    {
      "key": "disbursementId",
      "value": "",
      "type": "string"
    },
    {
      "key": "ts",
      "value": "",
      "type": "string"
    },
    {
      "key": "sig",
      "value": "",
      "type": "string"
    }
  ]
}