{
  "info": {
    "name": "PvP Universe · Partner integration",
    "description": "Every call between your platform and the PvP Universe games (Rummy, Teen Patti, Andar Bahar).\n\n1. Your wallet: the five calls we make to your server, signed exactly as we sign them, with tests for the behaviour we rely on (duplicate txIds, rollbacks of debits you never saw, insufficient funds, bad and stale signatures). Run the folder in order with the Collection Runner.\n2. Launch: the URL your site opens for each game.\n3. Operator API: what your backend can call on us with your API key.\n\nImport the staging environment too, then fill walletSecret, apiKey and token. Every call we make to your wallet also appears in the partner portal under Integration, with the exact body, timestamp, signature and your answer.\n\nAmounts are integers in minor units (paise for INR).",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "1. Your wallet (we call these)",
      "item": [
        {
          "name": "1. authenticate (launch token)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.test('playerId is present', () => pm.expect(String(d.playerId || '')).to.not.eql(''));",
                  "if (d.playerId) pm.environment.set('playerId', String(d.playerId));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"token\": \"{{token}}\",\n  \"game\": \"rummy\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/authenticate",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "authenticate"
              ]
            },
            "description": "We call this once per launch with the one-time token from the launch URL. Put a fresh token from your site in the token variable (tokens are single use)."
          }
        },
        {
          "name": "2. balance",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.environment.set('balanceStart', d.balance);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"playerId\": \"{{playerId}}\",\n  \"game\": \"rummy\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/balance",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "balance"
              ]
            },
            "description": "Lobby and table refresh. Read-only."
          }
        },
        {
          "name": "3. debit (a stake)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.environment.set('txId', 'pm-' + Date.now() + '-' + Math.floor(Math.random() * 1e6));",
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.environment.set('debitTxId', pm.environment.get('txId'));",
                  "pm.environment.set('balanceAfterDebit', d.balance);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"{{txId}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 100,\n  \"currency\": \"{{currency}}\",\n  \"kind\": \"entry\",\n  \"game\": \"rummy\",\n  \"handRef\": null,\n  \"gameId\": \"postman-test\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/debit",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "debit"
              ]
            },
            "description": "Takes 100 minor units. txId is new on every send."
          }
        },
        {
          "name": "4. debit again, same txId (must be DUPLICATE_TX)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('code is DUPLICATE_TX', () => pm.expect(d.code).to.eql('DUPLICATE_TX'));",
                  "pm.test('balance did not move', () => pm.expect(d.balance).to.eql(Number(pm.environment.get('balanceAfterDebit'))));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"{{debitTxId}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 100,\n  \"currency\": \"{{currency}}\",\n  \"kind\": \"entry\",\n  \"game\": \"rummy\",\n  \"handRef\": null,\n  \"gameId\": \"postman-test\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/debit",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "debit"
              ]
            },
            "description": "We retry with the same txId when an answer is lost. You must not take the money twice: answer ok with code DUPLICATE_TX and the balance."
          }
        },
        {
          "name": "5. credit (a win or a cash-out)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.environment.set('txId', 'pm-' + Date.now() + '-' + Math.floor(Math.random() * 1e6) + ':settle');",
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.test('balance went up by 100', () => pm.expect(d.balance).to.eql(Number(pm.environment.get('balanceAfterDebit')) + 100));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"{{txId}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 100,\n  \"currency\": \"{{currency}}\",\n  \"kind\": \"settle\",\n  \"game\": \"rummy\",\n  \"handRef\": null,\n  \"gameId\": \"postman-test\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/credit",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "credit"
              ]
            },
            "description": "Pays 100 minor units back. Credits are retried for up to 24 hours until you answer."
          }
        },
        {
          "name": "6. debit to roll back",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.environment.set('txId', 'pm-' + Date.now() + '-' + Math.floor(Math.random() * 1e6));",
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.environment.set('rollbackTarget', pm.environment.get('txId'));",
                  "pm.environment.set('balanceBeforeRollback', d.balance);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"{{txId}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 250,\n  \"currency\": \"{{currency}}\",\n  \"kind\": \"entry\",\n  \"game\": \"rummy\",\n  \"handRef\": null,\n  \"gameId\": \"postman-test\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/debit",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "debit"
              ]
            },
            "description": ""
          }
        },
        {
          "name": "7. rollback",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.test('the 250 came back', () => pm.expect(d.balance).to.eql(Number(pm.environment.get('balanceBeforeRollback')) + 250));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"{{rollbackTarget}}:rollback\",\n  \"originalTxId\": \"{{rollbackTarget}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 250,\n  \"currency\": \"{{currency}}\",\n  \"game\": \"rummy\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/rollback",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "rollback"
              ]
            },
            "description": "Undoes a debit whose seat never opened. Returns the original amount."
          }
        },
        {
          "name": "8. rollback of a debit you never received",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
                  "pm.test('ok is true', () => pm.expect(d.ok).to.eql(true));",
                  "pm.test('balance is an integer in minor units', () => pm.expect(Number.isInteger(d.balance)).to.eql(true));",
                  "pm.test('balance unchanged', () => pm.expect(d.balance).to.eql(Number(pm.environment.get('balanceBeforeRollback')) + 250));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"pm-never-sent-{{$timestamp}}:rollback\",\n  \"originalTxId\": \"pm-never-sent-{{$timestamp}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 250,\n  \"currency\": \"{{currency}}\",\n  \"game\": \"rummy\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/rollback",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "rollback"
              ]
            },
            "description": "Our debit can time out before it reaches you; we then roll it back. Answer ok and change nothing."
          }
        },
        {
          "name": "9. debit above the balance (must be INSUFFICIENT_FUNDS)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.environment.set('txId', 'pm-' + Date.now() + '-' + Math.floor(Math.random() * 1e6));",
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const d = pm.response.json();",
                  "pm.test('HTTP 402', () => pm.response.to.have.status(402));",
                  "pm.test('code is INSUFFICIENT_FUNDS', () => pm.expect(d.code).to.eql('INSUFFICIENT_FUNDS'));",
                  "pm.test('ok is false', () => pm.expect(d.ok).to.eql(false));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"txId\": \"{{txId}}\",\n  \"playerId\": \"{{playerId}}\",\n  \"amount\": 999999999999,\n  \"currency\": \"{{currency}}\",\n  \"kind\": \"entry\",\n  \"game\": \"rummy\",\n  \"handRef\": null,\n  \"gameId\": \"postman-test\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/debit",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "debit"
              ]
            },
            "description": ""
          }
        },
        {
          "name": "10. wrong signature (must be refused)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now());",
                  "const secret = 'not-your-secret';",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 403', () => pm.response.to.have.status(403));",
                  "pm.test('code is INVALID_SIGNATURE', () => pm.expect(pm.response.json().code).to.eql('INVALID_SIGNATURE'));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"playerId\": \"{{playerId}}\",\n  \"game\": \"rummy\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/balance",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "balance"
              ]
            },
            "description": "Signed with the wrong secret. You must answer 403 INVALID_SIGNATURE and do nothing."
          }
        },
        {
          "name": "11. timestamp 10 minutes old (must be refused)",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Sign exactly what is sent: HMAC-SHA256(secret, timestamp + \".\" + raw body), hex.",
                  "const raw = pm.variables.replaceIn(pm.request.body.raw);",
                  "pm.request.body.update({ mode: 'raw', raw, options: { raw: { language: 'json' } } });",
                  "const ts = String(Date.now() - 600000);",
                  "const secret = pm.variables.get('walletSecret');",
                  "if (!secret) throw new Error('Set walletSecret in the environment first');",
                  "const sig = CryptoJS.HmacSHA256(ts + \".\" + raw, secret).toString(CryptoJS.enc.Hex);",
                  "pm.request.headers.upsert({ key: 'X-PvP-Operator', value: pm.variables.get('operatorId') });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Timestamp', value: ts });",
                  "pm.request.headers.upsert({ key: 'X-PvP-Signature', value: sig });"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 403', () => pm.response.to.have.status(403));",
                  "pm.test('code is INVALID_SIGNATURE', () => pm.expect(pm.response.json().code).to.eql('INVALID_SIGNATURE'));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"playerId\": \"{{playerId}}\",\n  \"game\": \"rummy\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{walletBase}}/wallet/balance",
              "host": [
                "{{walletBase}}"
              ],
              "path": [
                "wallet",
                "balance"
              ]
            },
            "description": "A correct signature on an old timestamp: refuse anything older than 5 minutes (replay protection)."
          }
        }
      ]
    },
    {
      "name": "2. Launch (your site opens these)",
      "item": [
        {
          "name": "Launch Rummy",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{rummyBase}}/launch?operator={{operatorId}}&token={{token}}",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "launch"
              ],
              "query": [
                {
                  "key": "operator",
                  "value": "{{operatorId}}"
                },
                {
                  "key": "token",
                  "value": "{{token}}"
                }
              ]
            },
            "description": "What your site opens (in a new tab or an iframe). We call your /wallet/authenticate with the token, then answer 302 to the game. In Postman, turn off \"Automatically follow redirects\" to see the 302."
          }
        },
        {
          "name": "Launch Teen Patti",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{teenpattiBase}}/launch?operator={{operatorId}}&token={{token}}",
              "host": [
                "{{teenpattiBase}}"
              ],
              "path": [
                "launch"
              ],
              "query": [
                {
                  "key": "operator",
                  "value": "{{operatorId}}"
                },
                {
                  "key": "token",
                  "value": "{{token}}"
                }
              ]
            },
            "description": "What your site opens (in a new tab or an iframe). We call your /wallet/authenticate with the token, then answer 302 to the game. In Postman, turn off \"Automatically follow redirects\" to see the 302."
          }
        },
        {
          "name": "Launch Andar Bahar",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{andarbaharBase}}/launch?operator={{operatorId}}&token={{token}}",
              "host": [
                "{{andarbaharBase}}"
              ],
              "path": [
                "launch"
              ],
              "query": [
                {
                  "key": "operator",
                  "value": "{{operatorId}}"
                },
                {
                  "key": "token",
                  "value": "{{token}}"
                }
              ]
            },
            "description": "What your site opens (in a new tab or an iframe). We call your /wallet/authenticate with the token, then answer 302 to the game. In Postman, turn off \"Automatically follow redirects\" to see the 302."
          }
        }
      ]
    },
    {
      "name": "3. Operator API (you call these)",
      "item": [
        {
          "name": "Your operator profile",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{rummyBase}}/operator/me",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "operator",
                "me"
              ]
            },
            "description": ""
          }
        },
        {
          "name": "Daily settlement (UTC day)",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{rummyBase}}/operator/settlement?date={{date}}",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "operator",
                "settlement"
              ],
              "query": [
                {
                  "key": "date",
                  "value": "{{date}}"
                }
              ]
            },
            "description": "Every wallet transaction of the day for all three games, with totals. Reconcile against your wallet by txId."
          }
        },
        {
          "name": "A player's activity",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{rummyBase}}/operator/players/{{playerId}}/activity",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "operator",
                "players",
                "{{playerId}}",
                "activity"
              ]
            },
            "description": ""
          }
        },
        {
          "name": "A player's risk flags (check before a payout)",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{rummyBase}}/operator/players/{{playerId}}/risk",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "operator",
                "players",
                "{{playerId}}",
                "risk"
              ]
            },
            "description": ""
          }
        },
        {
          "name": "Record KYC and bank details (hashed on arrival)",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"kyc\": \"PAN or Aadhaar number\",\n  \"bank\": \"account number + IFSC\",\n  \"payment\": \"UPI id\",\n  \"phone\": \"+91...\",\n  \"email\": \"player@example.com\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{rummyBase}}/operator/players/{{playerId}}/identity",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "operator",
                "players",
                "{{playerId}}",
                "identity"
              ]
            },
            "description": "Players who share any of these are never seated together. Send only the fields you have."
          }
        },
        {
          "name": "A hand by reference",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{rummyBase}}/operator/hands/{{handRef}}",
              "host": [
                "{{rummyBase}}"
              ],
              "path": [
                "operator",
                "hands",
                "{{handRef}}"
              ]
            },
            "description": ""
          }
        }
      ]
    }
  ]
}
