{
  "info": {
    "_postman_id": "chytapay-integration-api",
    "name": "Chytapay Integration API",
    "description": "Colección completa de endpoints para la API de integración de Chytapay",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Admin",
      "item": [
        {
          "name": "Auth",
          "item": [
            {
              "name": "Login",
              "event": [
                {
                  "listen": "test",
                  "script": {
                    "exec": [
                      "if (pm.response.code === 200) {",
                      "    var jsonData = pm.response.json();",
                      "    if (jsonData.idToken) {",
                      "        pm.environment.set('admin_id_token', jsonData.idToken);",
                      "    }",
                      "}"
                    ],
                    "type": "text/javascript"
                  }
                }
              ],
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"email\": \"admin@example.com\",\n  \"password\": \"YourPassword123!\"\n}"
                },
                "url": {
                  "raw": "{{auth-api-url}}/integration/admin/login",
                  "host": [
                    "{{auth-api-url}}"
                  ],
                  "path": [
                    "integration",
                    "admin",
                    "login"
                  ]
                },
                "description": "Iniciar sesión como administrador de integración. La respuesta incluye `idToken` y `refreshToken`."
              },
              "response": []
            },
            {
              "name": "Change Password",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"email\": \"admin@example.com\",\n  \"currentPassword\": \"TempPassword123!\",\n  \"newPassword\": \"NewPassword123!\"\n}"
                },
                "url": {
                  "raw": "{{auth-api-url}}/integration/admin/change-password",
                  "host": [
                    "{{auth-api-url}}"
                  ],
                  "path": [
                    "integration",
                    "admin",
                    "change-password"
                  ]
                },
                "description": "Cambiar contraseña temporal por una nueva"
              },
              "response": []
            },
            {
              "name": "Forgot Password",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"email\": \"admin@example.com\"\n}"
                },
                "url": {
                  "raw": "{{auth-api-url}}/integration/admin/forgot-password",
                  "host": [
                    "{{auth-api-url}}"
                  ],
                  "path": [
                    "integration",
                    "admin",
                    "forgot-password"
                  ]
                },
                "description": "Solicitar código de recuperación de contraseña"
              },
              "response": []
            },
            {
              "name": "Reset Password",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"email\": \"admin@example.com\",\n  \"code\": \"123456\",\n  \"newPassword\": \"NewPassword123!\"\n}"
                },
                "url": {
                  "raw": "{{auth-api-url}}/integration/admin/reset-password",
                  "host": [
                    "{{auth-api-url}}"
                  ],
                  "path": [
                    "integration",
                    "admin",
                    "reset-password"
                  ]
                },
                "description": "Restablecer contraseña con código de verificación"
              },
              "response": []
            }
          ],
          "description": "Endpoints de autenticación para administradores de integración"
        },
        {
          "name": "URL Configuration",
          "item": [
            {
              "name": "Get Client URLs",
              "request": {
                "auth": {
                  "type": "bearer",
                  "bearer": [
                    {
                      "key": "token",
                      "value": "{{admin_id_token}}",
                      "type": "string"
                    }
                  ]
                },
                "method": "GET",
                "header": [],
                "url": {
                  "raw": "{{integration-admin-url}}/my-integration/url",
                  "host": [
                    "{{integration-admin-url}}"
                  ],
                  "path": [
                    "my-integration",
                    "url"
                  ]
                },
                "description": "Obtener las URLs configuradas (webhook y redirect_uri)"
              },
              "response": []
            },
            {
              "name": "Create Client URL",
              "request": {
                "auth": {
                  "type": "bearer",
                  "bearer": [
                    {
                      "key": "token",
                      "value": "{{admin_id_token}}",
                      "type": "string"
                    }
                  ]
                },
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"url\": \"https://your-app.com/webhook\",\n  \"urlType\": \"webhook\",\n  \"validationToken\": \"optional-secret-token-min-16-chars\"\n}"
                },
                "url": {
                  "raw": "{{integration-admin-url}}/my-integration/url",
                  "host": [
                    "{{integration-admin-url}}"
                  ],
                  "path": [
                    "my-integration",
                    "url"
                  ]
                },
                "description": "Crear una nueva URL. `urlType` debe ser 'webhook' o 'redirect_uri'. `validationToken` es opcional pero debe tener al menos 16 caracteres si se proporciona."
              },
              "response": []
            },
            {
              "name": "Update Client URL",
              "request": {
                "auth": {
                  "type": "bearer",
                  "bearer": [
                    {
                      "key": "token",
                      "value": "{{admin_id_token}}",
                      "type": "string"
                    }
                  ]
                },
                "method": "PUT",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n  \"url\": \"https://your-app.com/webhook-updated\",\n  \"validationToken\": \"optional-updated-secret-token\"\n}"
                },
                "url": {
                  "raw": "{{integration-admin-url}}/my-integration/url/:clientUrlId",
                  "host": [
                    "{{integration-admin-url}}"
                  ],
                  "path": [
                    "my-integration",
                    "url",
                    ":clientUrlId"
                  ],
                  "variable": [
                    {
                      "key": "clientUrlId",
                      "value": "your-url-id"
                    }
                  ]
                },
                "description": "Actualizar una URL existente. `url` y `validationToken` son opcionales."
              },
              "response": []
            },
            {
              "name": "Delete Client URL",
              "request": {
                "auth": {
                  "type": "bearer",
                  "bearer": [
                    {
                      "key": "token",
                      "value": "{{admin_id_token}}",
                      "type": "string"
                    }
                  ]
                },
                "method": "DELETE",
                "header": [],
                "url": {
                  "raw": "{{integration-admin-url}}/my-integration/url/:clientUrlId",
                  "host": [
                    "{{integration-admin-url}}"
                  ],
                  "path": [
                    "my-integration",
                    "url",
                    ":clientUrlId"
                  ],
                  "variable": [
                    {
                      "key": "clientUrlId",
                      "value": "your-url-id"
                    }
                  ]
                },
                "description": "Eliminar una URL configurada"
              },
              "response": []
            }
          ],
          "description": "Endpoints para configurar URLs de webhook y redirect_uri"
        }
      ],
      "description": "Endpoints de administración de integración"
    },
    {
      "name": "OAuth2",
      "item": [
        {
          "name": "Authorize",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{auth-api-url}}/integration/oauth2/authorize?clientId={{client_id}}&redirectUri={{redirect_uri}}&responseType=code&state=random_state_string&scope=openid%20profile",
              "host": [
                "{{auth-api-url}}"
              ],
              "path": [
                "integration",
                "oauth2",
                "authorize"
              ],
              "query": [
                {
                  "key": "clientId",
                  "value": "{{client_id}}",
                  "description": "Client ID de tu integración"
                },
                {
                  "key": "redirectUri",
                  "value": "{{redirect_uri}}",
                  "description": "URL de callback registrada"
                },
                {
                  "key": "responseType",
                  "value": "code",
                  "description": "Debe ser 'code'"
                },
                {
                  "key": "state",
                  "value": "random_state_string",
                  "description": "String aleatorio para prevenir CSRF"
                },
                {
                  "key": "scope",
                  "value": "openid profile",
                  "description": "Opcional: 'openid profile'"
                }
              ]
            },
            "description": "Iniciar flujo OAuth2 para autorización del usuario. Redirige al usuario a la página de login de Chytapay."
          },
          "response": []
        },
        {
          "name": "Get Tokens",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 200) {",
                  "    var jsonData = pm.response.json();",
                  "    if (jsonData.idToken) {",
                  "        pm.environment.set('user_id_token', jsonData.idToken);",
                  "    }",
                  "    if (jsonData.refreshToken) {",
                  "        pm.environment.set('refresh_token', jsonData.refreshToken);",
                  "    }",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"code\": \"AUTHORIZATION_CODE\",\n  \"clientId\": \"{{client_id}}\",\n  \"clientSecret\": \"{{client_secret}}\",\n  \"redirectUri\": \"{{redirect_uri}}\"\n}"
            },
            "url": {
              "raw": "{{auth-api-url}}/integration/oauth2/token",
              "host": [
                "{{auth-api-url}}"
              ],
              "path": [
                "integration",
                "oauth2",
                "token"
              ]
            },
            "description": "Intercambiar código de autorización por tokens. Respuesta incluye: `idToken`, `refreshToken`, `tokenType`, `expiresIn`. Usa el `idToken` como Bearer token en los endpoints de Payment Request."
          },
          "response": []
        },
        {
          "name": "Refresh Token",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 200) {",
                  "    var jsonData = pm.response.json();",
                  "    if (jsonData.idToken) {",
                  "        pm.environment.set('user_id_token', jsonData.idToken);",
                  "    }",
                  "    if (jsonData.refreshToken) {",
                  "        pm.environment.set('refresh_token', jsonData.refreshToken);",
                  "    }",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"refreshToken\": \"{{refresh_token}}\",\n  \"clientId\": \"{{client_id}}\",\n  \"clientSecret\": \"{{client_secret}}\"\n}"
            },
            "url": {
              "raw": "{{auth-api-url}}/integration/oauth2/refresh",
              "host": [
                "{{auth-api-url}}"
              ],
              "path": [
                "integration",
                "oauth2",
                "refresh"
              ]
            },
            "description": "Refrescar access token usando refresh token. Retorna un nuevo `idToken` y opcionalmente un nuevo `refreshToken`."
          },
          "response": []
        },
        {
          "name": "Revoke Token",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"token\": \"{{access_token}}\",\n  \"clientId\": \"{{client_id}}\",\n  \"clientSecret\": \"{{client_secret}}\",\n  \"tokenTypeHint\": \"access_token\"\n}"
            },
            "url": {
              "raw": "{{auth-api-url}}/integration/oauth2/revoke",
              "host": [
                "{{auth-api-url}}"
              ],
              "path": [
                "integration",
                "oauth2",
                "revoke"
              ]
            },
            "description": "Revocar un access token o refresh token. `tokenTypeHint` es opcional: 'access_token' o 'refresh_token'."
          },
          "response": []
        }
      ],
      "description": "Endpoints de OAuth2 para autorización de usuarios de Chytapay. Todos los parámetros deben estar en camelCase."
    },
    {
      "name": "Payment Request",
      "item": [
        {
          "name": "Get All Payment Requests",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{user_id_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{integration-url}}/payment-request?startDate=2025-01-01&endDate=2025-01-31",
              "host": [
                "{{integration-url}}"
              ],
              "path": [
                "payment-request"
              ],
              "query": [
                {
                  "key": "startDate",
                  "value": "2025-01-01",
                  "description": "Opcional: formato YYYY-MM-DD"
                },
                {
                  "key": "endDate",
                  "value": "2025-01-31",
                  "description": "Opcional: formato YYYY-MM-DD"
                }
              ]
            },
            "description": "Obtener todas las solicitudes de pago del usuario autenticado. `startDate` y `endDate` son opcionales y permiten filtrar por rango de fechas."
          },
          "response": []
        },
        {
          "name": "Get Payment Request by Reference ID",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{user_id_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{integration-url}}/payment-request/:referenceId",
              "host": [
                "{{integration-url}}"
              ],
              "path": [
                "payment-request",
                ":referenceId"
              ],
              "variable": [
                {
                  "key": "referenceId",
                  "value": "invoice-001"
                }
              ]
            },
            "description": "Obtener una solicitud de pago por su `referenceId`. El `referenceId` es el identificador único que proporcionaste al crear el payment request."
          },
          "response": []
        },
        {
          "name": "Create Payment Request",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{user_id_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"referenceId\": \"invoice-001\",\n  \"amount\": 1000,\n  \"description\": \"Cuota mensual - Enero 2025\",\n  \"dueDates\": [\n    \"2025-01-15\",\n    \"2025-01-30\"\n  ],\n  \"surcharge\": {\n    \"type\": \"%\",\n    \"value\": 10\n  },\n  \"sendWhatsappNotification\": true,\n  \"sendEmailNotification\": true,\n  \"reminderNotificationDate\": \"2025-01-10\",\n  \"deferredInitialNotificationDate\": \"2025-01-05\",\n  \"customer\": {\n    \"name\": \"Juan Pérez\",\n    \"phoneNumber\": {\n      \"countryCode\": \"+54\",\n      \"number\": \"1112345678\"\n    },\n    \"email\": \"juan@example.com\"\n  }\n}"
            },
            "url": {
              "raw": "{{integration-url}}/payment-request",
              "host": [
                "{{integration-url}}"
              ],
              "path": [
                "payment-request"
              ]
            },
            "description": "Crear una nueva solicitud de pago. Si `amount` no se proporciona, se crea en estado 'draft'. `reminderNotificationDate` y `deferredInitialNotificationDate` son opcionales. Si hay más de un `dueDate`, `surcharge` es requerido cuando `amount` está presente."
          },
          "response": []
        },
        {
          "name": "Create Payment Request — CUIL mode (CUIL explícito)",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{user_id_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"referenceId\": \"invoice-cuil-001\",\n  \"amount\": 5000,\n  \"description\": \"Cuota con conciliación por CUIL\",\n  \"dueDates\": [\n    \"2025-02-15\"\n  ],\n  \"conciliationType\": \"cuil\",\n  \"customer\": {\n    \"name\": \"María García\",\n    \"email\": \"maria@example.com\",\n    \"taxDocument\": \"27304050604\"\n  }\n}"
            },
            "url": {
              "raw": "{{integration-url}}/payment-request",
              "host": [
                "{{integration-url}}"
              ],
              "path": [
                "payment-request"
              ]
            },
            "description": "Crear una solicitud de pago en modo CUIL. El campo `conciliationType` debe ser `\"cuil\"` y `customer.taxDocument` debe contener un CUIL válido de 11 dígitos (con dígito verificador correcto). La respuesta incluye `customer.taxDocument` con el mismo valor enviado."
          },
          "response": []
        },
        {
          "name": "Create Payment Request — CUIL mode (DNI → par de candidatos)",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{user_id_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"referenceId\": \"invoice-dni-001\",\n  \"amount\": 5000,\n  \"description\": \"Cuota con conciliación por DNI\",\n  \"dueDates\": [\n    \"2025-02-15\"\n  ],\n  \"conciliationType\": \"cuil\",\n  \"customer\": {\n    \"name\": \"Carlos López\",\n    \"email\": \"carlos@example.com\",\n    \"taxDocument\": \"30405060\"\n  }\n}"
            },
            "url": {
              "raw": "{{integration-url}}/payment-request",
              "host": [
                "{{integration-url}}"
              ],
              "path": [
                "payment-request"
              ]
            },
            "description": "Crear una solicitud de pago en modo CUIL con DNI como taxDocument (7-8 dígitos). El sistema genera automáticamente los dos candidatos CUIL (prefijo 20 y 27) y los registra como payer contacts del cliente. La respuesta devuelve `customer.taxDocument` con el DNI original, no los CUILs derivados."
          },
          "response": []
        },
        {
          "name": "Update Payment Request Amount",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{user_id_token}}",
                  "type": "string"
                }
              ]
            },
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"amount\": 1500\n}"
            },
            "url": {
              "raw": "{{integration-url}}/payment-request/:referenceId",
              "host": [
                "{{integration-url}}"
              ],
              "path": [
                "payment-request",
                ":referenceId"
              ],
              "variable": [
                {
                  "key": "referenceId",
                  "value": "invoice-001"
                }
              ]
            },
            "description": "Modificar el monto de una solicitud de pago. Solo se puede modificar si está en estado 'draft' o 'pending'. Los montos calculados se recalculan automáticamente."
          },
          "response": []
        }
      ],
      "description": "Endpoints para crear y gestionar solicitudes de pago. Requieren autenticación con `idToken` obtenido mediante OAuth2."
    }
  ],
  "variable": [
    {
      "key": "auth-api-url",
      "value": "https://auth-api.test.chytapay.com.ar",
      "type": "string"
    },
    {
      "key": "integration-admin-url",
      "value": "https://integration-admin-api.test.chytapay.com.ar",
      "type": "string"
    },
    {
      "key": "integration-url",
      "value": "https://integration-api.test.chytapay.com.ar",
      "type": "string"
    },
    {
      "key": "admin_id_token",
      "value": "",
      "type": "string",
      "description": "ID Token obtenido del login de admin (endpoint Admin > Auth > Login)"
    },
    {
      "key": "user_id_token",
      "value": "",
      "type": "string",
      "description": "ID Token obtenido mediante OAuth2 (endpoint OAuth2 > Get Tokens)"
    },
    {
      "key": "refresh_token",
      "value": "",
      "type": "string",
      "description": "Refresh token obtenido mediante OAuth2"
    },
    {
      "key": "client_id",
      "value": "",
      "type": "string",
      "description": "Client ID de tu integración (recibido por email)"
    },
    {
      "key": "client_secret",
      "value": "",
      "type": "string",
      "description": "Client Secret de tu integración (recibido por email)"
    },
    {
      "key": "redirect_uri",
      "value": "",
      "type": "string",
      "description": "URL de callback OAuth registrada en tu integración"
    }
  ]
}