{
  "info": {
    "name": "QRIS Pay Integration",
    "description": "Koleksi Postman untuk integrasi QRIS Pay: buat QR, cek status, dan simulasi webhook pembayaran. Gunakan variabel collection; jangan simpan API key di frontend.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "base_url", "value": "https://qris.teknomadani.biz.id" },
    { "key": "api_key", "value": "qris_live_XXXXXXXXXXXXXXXXXXXXXXXX" },
    { "key": "reference", "value": "QRS-261123-XXXXXXXX" },
    { "key": "webhook_url", "value": "https://app-anda.id/webhooks/qris" },
    { "key": "webhook_secret", "value": "secret-anda-min-8-karakter" },
    { "key": "merchant_webhook_secret", "value": "rahasia-test-123" }
  ],
  "item": [
    {
      "name": "Health",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{base_url}}/api/health"
      }
    },
    {
      "name": "1. Buat Charge / QR",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 201) {",
              "  const j = pm.response.json();",
              "  pm.collectionVariables.set('reference', j.data.reference);",
              "  pm.collectionVariables.set('amount_pay', j.data.amount_pay);",
              "  console.log('Simpan reference:', j.data.reference);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Authorization", "value": "Bearer {{api_key}}" },
          { "key": "Content-Type", "value": "application/json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"amount\": 50000,\n  \"customer_name\": \"Budi\",\n  \"customer_phone\": \"081234567890\",\n  \"webhook_url\": \"{{webhook_url}}\",\n  \"webhook_secret\": \"{{webhook_secret}}\"\n}"
        },
        "url": "{{base_url}}/api/charges"
      }
    },
    {
      "name": "2. Cek Status",
      "request": {
        "method": "GET",
        "header": [
          { "key": "Authorization", "value": "Bearer {{api_key}}" }
        ],
        "url": "{{base_url}}/api/charges/{{reference}}"
      }
    },
    {
      "name": "3. Simulasi Webhook Masuk (paid)",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = JSON.stringify({",
              "  reference: pm.collectionVariables.get('reference'),",
              "  status: 'paid',",
              "  amount_pay: Number(pm.collectionVariables.get('amount_pay') || 0),",
              "  payer: { name: 'Simulasi' }",
              "});",
              "pm.collectionVariables.set('incoming_body', body);",
              "pm.collectionVariables.set('incoming_sig', CryptoJS.HmacSHA256(body, pm.collectionVariables.get('merchant_webhook_secret')).toString());"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-QRIS-Signature", "value": "{{incoming_sig}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{{incoming_body}}"
        },
        "url": "{{base_url}}/api/webhook/incoming"
      }
    },
    {
      "name": "4. Ambil PNG QR (publik)",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{base_url}}/qr/{{reference}}.png"
      }
    }
  ]
}
