{
  "info": {
    "name": "Recurrente: primer pago de prueba",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Primer pago de prueba",
      "description": "Usa una llave de Sandbox. Verifica el ambiente, registra tu webhook, crea el checkout, abre checkoutUrl, paga y consulta el checkout. Guarda signingSecret como secreto local; no sincronices credenciales.",
      "item": [
        {
          "name": "1. Confirmar Sandbox",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-SECRET-KEY",
                "value": "{{sandboxKey}}",
                "type": "text"
              }
            ],
            "url": "{{baseUrl}}/test"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"Named Sandbox\", () => pm.expect(pm.response.json().environment).to.eql(\"sandbox\"));",
                  "pm.collectionVariables.set(\"sandboxId\", pm.response.json().sandbox_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "2. Registrar webhook",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-SECRET-KEY",
                "value": "{{sandboxKey}}",
                "type": "text"
              },
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "url": "{{baseUrl}}/webhook_endpoints",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"url\": \"{{sandboxWebhookUrl}}\",\n  \"description\": \"Primer pago Sandbox\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "3. Crear checkout de Q5",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-SECRET-KEY",
                "value": "{{sandboxKey}}",
                "type": "text"
              },
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "url": "{{baseUrl}}/checkouts",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"items\": [\n    {\n      \"name\": \"Mi primer pago de prueba\",\n      \"amount_in_cents\": 500,\n      \"currency\": \"GTQ\",\n      \"quantity\": 1\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.collectionVariables.set(\"checkoutId\", pm.response.json().id);",
                  "pm.collectionVariables.set(\"checkoutUrl\", pm.response.json().checkout_url);"
                ]
              }
            }
          ]
        },
        {
          "name": "4. Consultar después de pagar",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-SECRET-KEY",
                "value": "{{sandboxKey}}",
                "type": "text"
              }
            ],
            "url": "{{baseUrl}}/checkouts/{{checkoutId}}"
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"Checkout paid\", () => pm.expect(pm.response.json().status).to.eql(\"paid\"));"
                ]
              }
            }
          ]
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://app.recurrente.com/api"
    },
    {
      "key": "sandboxKey",
      "value": ""
    },
    {
      "key": "sandboxWebhookUrl",
      "value": "https://your-domain.example/webhooks/recurrente"
    }
  ]
}
