{
  "info": {
    "name": "Rekurra API",
    "description": "Colección de ejemplo de la API de Rekurra (capa de billing recurrente sobre Wompi). Configura las variables `baseUrl` y `apiKey` en el entorno. Todos los montos van en centavos COP.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{apiKey}}", "type": "string" }]
  },
  "variable": [
    { "key": "baseUrl", "value": "https://api.rekurra.dev", "type": "string" },
    { "key": "apiKey", "value": "rk_test_XXXXXXXXXXXXXXXXXXXXXXXX", "type": "string" },
    { "key": "planId", "value": "plan_01HZXK7QJ5M8Z9X2R3TVQ7A1B2", "type": "string" },
    { "key": "customerId", "value": "cus_01HZXK7QJ5M8Z9X2R3TVQ7A1B2", "type": "string" },
    { "key": "subscriptionId", "value": "sub_01HZXK7QJ5M8Z9X2R3TVQ7A1B2", "type": "string" },
    { "key": "checkoutSessionId", "value": "cs_01HZXK7QJ5M8Z9X2R3TVQ7A1B2", "type": "string" }
  ],
  "item": [
    {
      "name": "Plans",
      "item": [
        {
          "name": "Crear plan",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/plans", "host": ["{{baseUrl}}"], "path": ["v1", "plans"] },
            "body": { "mode": "raw", "raw": "{\n  \"code\": \"pro-mensual\",\n  \"name\": \"Plan Pro\",\n  \"price_monthly_cents\": 5000000,\n  \"price_annual_cents\": 50000000,\n  \"trial_days\": 7,\n  \"description\": \"Acceso completo a todas las funciones\",\n  \"active\": true\n}" }
          }
        },
        {
          "name": "Listar planes",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/plans?limit=25", "host": ["{{baseUrl}}"], "path": ["v1", "plans"], "query": [{ "key": "limit", "value": "25" }] }
          }
        },
        {
          "name": "Obtener plan",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/plans/{{planId}}", "host": ["{{baseUrl}}"], "path": ["v1", "plans", "{{planId}}"] }
          }
        },
        {
          "name": "Actualizar plan",
          "request": {
            "method": "PATCH",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/plans/{{planId}}", "host": ["{{baseUrl}}"], "path": ["v1", "plans", "{{planId}}"] },
            "body": { "mode": "raw", "raw": "{\n  \"name\": \"Plan Pro (nuevo nombre)\"\n}" }
          }
        },
        {
          "name": "Desactivar plan",
          "request": {
            "method": "DELETE",
            "url": { "raw": "{{baseUrl}}/v1/plans/{{planId}}", "host": ["{{baseUrl}}"], "path": ["v1", "plans", "{{planId}}"] }
          }
        }
      ]
    },
    {
      "name": "Checkout sessions",
      "item": [
        {
          "name": "Crear suscripción — cliente nuevo (customer)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/checkout-sessions", "host": ["{{baseUrl}}"], "path": ["v1", "checkout-sessions"] },
            "body": { "mode": "raw", "raw": "{\n  \"plan_id\": \"{{planId}}\",\n  \"cycle\": \"monthly\",\n  \"customer\": { \"email\": \"cliente@ejemplo.com\", \"name\": \"María Pérez\" },\n  \"success_url\": \"https://tuapp.com/gracias\",\n  \"cancel_url\": \"https://tuapp.com/checkout\",\n  \"metadata\": { \"origen\": \"landing\" }\n}" }
          }
        },
        {
          "name": "Crear suscripción — cliente existente (customer_id)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/checkout-sessions", "host": ["{{baseUrl}}"], "path": ["v1", "checkout-sessions"] },
            "body": { "mode": "raw", "raw": "{\n  \"plan_id\": \"{{planId}}\",\n  \"cycle\": \"monthly\",\n  \"customer_id\": \"{{customerId}}\",\n  \"success_url\": \"https://tuapp.com/gracias\",\n  \"cancel_url\": \"https://tuapp.com/checkout\"\n}" }
          }
        },
        {
          "name": "Obtener sesión de checkout",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/checkout-sessions/{{checkoutSessionId}}", "host": ["{{baseUrl}}"], "path": ["v1", "checkout-sessions", "{{checkoutSessionId}}"] }
          }
        },
        {
          "name": "Consultar estado (polling)",
          "request": {
            "method": "GET",
            "description": "Verifica el resultado del checkout (estado + subscription_id) si no llegó el webhook subscription.created. Rate limit dedicado: 20/min por API key.",
            "url": { "raw": "{{baseUrl}}/v1/checkout-sessions/{{checkoutSessionId}}/status", "host": ["{{baseUrl}}"], "path": ["v1", "checkout-sessions", "{{checkoutSessionId}}", "status"] }
          }
        }
      ]
    },
    {
      "name": "Subscriptions",
      "item": [
        {
          "name": "Listar suscripciones",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/subscriptions?status=active", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions"], "query": [{ "key": "status", "value": "active" }] }
          }
        },
        {
          "name": "Obtener suscripción",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}"] }
          }
        },
        {
          "name": "Cancelar suscripción",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}/cancel", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}", "cancel"] },
            "body": { "mode": "raw", "raw": "{\n  \"at_period_end\": true\n}" }
          }
        },
        {
          "name": "Pausar suscripción",
          "request": {
            "method": "POST",
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}/pause", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}", "pause"] }
          }
        },
        {
          "name": "Reanudar suscripción",
          "request": {
            "method": "POST",
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}/resume", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}", "resume"] }
          }
        },
        {
          "name": "Cambiar de plan",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}/change-plan", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}", "change-plan"] },
            "body": { "mode": "raw", "raw": "{\n  \"plan_id\": \"{{planId}}\",\n  \"cycle\": \"annual\",\n  \"prorate\": true\n}" }
          }
        },
        {
          "name": "Previsualizar cambio de plan",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "description": "Dry-run del cambio de plan sobre el ciclo actual. No aplica ningún cambio; solo calcula el prorrateo.",
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}/change-plan/preview", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}", "change-plan", "preview"] },
            "body": { "mode": "raw", "raw": "{\n  \"plan_id\": \"{{planId}}\"\n}" }
          }
        },
        {
          "name": "Forzar cobro",
          "request": {
            "method": "POST",
            "url": { "raw": "{{baseUrl}}/v1/subscriptions/{{subscriptionId}}/charge-now", "host": ["{{baseUrl}}"], "path": ["v1", "subscriptions", "{{subscriptionId}}", "charge-now"] }
          }
        }
      ]
    },
    {
      "name": "Customers",
      "item": [
        {
          "name": "Crear cliente",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/customers", "host": ["{{baseUrl}}"], "path": ["v1", "customers"] },
            "body": { "mode": "raw", "raw": "{\n  \"email\": \"cliente@ejemplo.com\",\n  \"name\": \"María Pérez\",\n  \"external_id\": \"user_42\"\n}" }
          }
        },
        {
          "name": "Buscar cliente por email",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/customers?email=cliente@ejemplo.com", "host": ["{{baseUrl}}"], "path": ["v1", "customers"], "query": [{ "key": "email", "value": "cliente@ejemplo.com" }] }
          }
        },
        {
          "name": "Obtener cliente",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/customers/{{customerId}}", "host": ["{{baseUrl}}"], "path": ["v1", "customers", "{{customerId}}"] }
          }
        }
      ]
    },
    {
      "name": "Payment methods",
      "item": [
        {
          "name": "Obtener configuración de tokenización",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/payment-methods/setup", "host": ["{{baseUrl}}"], "path": ["v1", "payment-methods", "setup"] }
          }
        },
        {
          "name": "Crear método de pago",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/payment-methods", "host": ["{{baseUrl}}"], "path": ["v1", "payment-methods"] },
            "body": { "mode": "raw", "raw": "{\n  \"customer_id\": \"{{customerId}}\",\n  \"type\": \"CARD\",\n  \"token\": \"tok_test_1234_abcd\",\n  \"acceptance_token\": \"eyJhbGciOi...\",\n  \"accept_personal_auth\": \"eyJhbGciOi...\",\n  \"set_default\": true\n}" }
          }
        }
      ]
    },
    {
      "name": "Webhook endpoints",
      "item": [
        {
          "name": "Crear webhook endpoint",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "url": { "raw": "{{baseUrl}}/v1/webhook-endpoints", "host": ["{{baseUrl}}"], "path": ["v1", "webhook-endpoints"] },
            "body": { "mode": "raw", "raw": "{\n  \"url\": \"https://tuapp.com/webhooks/rekurra\",\n  \"events\": [\"subscription.created\", \"charge.approved\", \"charge.declined\", \"subscription.canceled\"]\n}" }
          }
        },
        {
          "name": "Listar webhook endpoints",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/webhook-endpoints", "host": ["{{baseUrl}}"], "path": ["v1", "webhook-endpoints"] }
          }
        }
      ]
    },
    {
      "name": "Balance",
      "item": [
        {
          "name": "Consultar saldo",
          "request": {
            "method": "GET",
            "url": { "raw": "{{baseUrl}}/v1/balance", "host": ["{{baseUrl}}"], "path": ["v1", "balance"] }
          }
        }
      ]
    }
  ]
}
