Files
gruperly/apps/backend/.env.example
Jose Selesan aac142d324 feat(billing): configurable plans from the backoffice and MP payment notifications
Plans:
- Plan limits and Pro prices per country live in the database
  (plan_configs, plan_prices, seeded with the previous constants) and are
  read through PlanCatalog (30 s cache, defaults as fallback).
- /admin/plans edits limits (with the count of accounts that would become
  read-only) and prices, optionally pushing the new price to live
  subscriptions from their next charge (MP preapproval amount, Stripe item
  without proration) via the ApplyPriceChanges job, with an email and a
  notice on /billing.
- GET /billing/plans feeds the onboarding and the billing screen.

Mercado Pago:
- The Pro checkout returns through GET /billing/return on API_PUBLIC_URL,
  since MP refuses a back_url on localhost.
- The OAuth callback bounces from the tunnel to BETTER_AUTH_URL to find the
  session, requires the session to own the state, and redirects instead of
  answering JSON on unexpected errors.
- Checkout Pro links skip auto_return off public HTTPS and carry a
  notification_url to POST /payments/webhooks/mp/:paymentId, which confirms
  the payment with the owner's token (same rule as the polling job, which
  stays as fallback). The search now prefers the approved attempt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 07:50:14 -03:00

102 lines
4.4 KiB
Plaintext

# PostgreSQL connection string
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/gruperly?schema=public"
# Frontend origin (CORS + CSRF)
WEB_URL="http://localhost:6173"
# Better Auth
BETTER_AUTH_SECRET="replace-with-a-strong-secret"
BETTER_AUTH_URL="http://localhost:4000"
# Social providers
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
# Email (SMTP por ahora; migrar a un proveedor transaccional en el futuro)
EMAIL_PROVIDER="smtp"
EMAIL_SERVER_HOST=""
EMAIL_SERVER_PORT="587"
EMAIL_SERVER_USER=""
EMAIL_SERVER_PASSWORD=""
EMAIL_FROM="Gruperly <no-reply@gruperly.com>"
# Mercado Pago (OAuth, Authorization Code + PKCE)
MP_CLIENT_ID=""
MP_CLIENT_SECRET=""
# Debe coincidir exactamente con la "Redirect URL" de la app en el panel de MP.
# El panel exige HTTPS (rechaza http://localhost): en local usá un túnel
# (p. ej. ngrok http --url=https://TU-DOMINIO.ngrok-free.app 4000) y cargá
# la URL del túnel acá y en el panel.
MP_REDIRECT_URI=""
# Clave de 32 bytes en base64 para cifrar los tokens de MP en reposo (AES-256-GCM).
# Generar con: openssl rand -base64 32
TOKEN_ENCRYPTION_KEY=""
# Suscripción a Gruperly Pro (ver docs/billing.md). Argentina la cobra con
# Suscripciones de Mercado Pago; el resto de los países, con Stripe.
# Mercado Pago: credenciales de la cuenta de MP **de Gruperly** en Argentina (no
# son las del OAuth del profesor). Sin las dos, Pro queda "no disponible" (503).
MP_PLATFORM_ACCESS_TOKEN_AR=""
MP_PLATFORM_WEBHOOK_SECRET_AR=""
# Origen público de esta API, adonde MP y Stripe devuelven el navegador después
# del checkout de Pro (GET /api/v1/billing/return, que redirige a la web). MP
# rechaza localhost: en local poné el túnel (https://TU-DOMINIO.ngrok-free.app).
# Vacío = BETTER_AUTH_URL.
API_PUBLIC_URL=""
# Stripe: una sola cuenta para BR, CL, CO, MX, PE y UY, cobrando en la moneda
# de cada país. Secret key (sk_test_… en local) y el signing secret del webhook
# (whsec_…; en local lo imprime `stripe listen`). Sin las dos, 503 en esos países.
STRIPE_SECRET_KEY=""
STRIPE_WEBHOOK_SECRET=""
# on = aplica los límites del plan Free. Cualquier otro valor (o vacío): todos Pro.
BILLING_ENFORCEMENT="off"
# Días que un Pro vencido (cancelado o con el cobro rechazado) sigue funcionando.
BILLING_GRACE_DAYS="7"
# Backoffice (/admin): emails del equipo de Gruperly, separados por coma. Vacío = nadie.
ADMIN_EMAILS=""
# WhatsApp: recordatorios de pago y reenganche semanales (ver docs/whatsapp.md).
# Proveedor: openwa (MVP, gateway self-hosted con QR) | kapso (API oficial de Meta).
WHATSAPP_PROVIDER="openwa"
# Pausa entre dos envíos del mismo profesor, en ms (OpenWA recomienda < 15 msg/min).
WHATSAPP_SEND_INTERVAL_MS="5000"
# OpenWA (se instala aparte). En local: docker run, ver docs/whatsapp.md.
OPENWA_API_URL="http://localhost:2785/api"
# Key OPERATOR sin allowedSessions, creada con la key ADMIN de /app/data/.api-key.
OPENWA_API_KEY=""
# Opcional. Sin webhook la vinculación funciona (el status hace polling), pero no
# llegan las confirmaciones de entrega/lectura. Si lo cargás, el secreto es obligatorio.
OPENWA_WEBHOOK_URL=""
# 16+ caracteres. Generar con: openssl rand -hex 24
OPENWA_WEBHOOK_SECRET=""
# Kapso (WHATSAPP_PROVIDER="kapso"). Las URLs tienen que ser públicas (túnel en local).
KAPSO_API_KEY=""
KAPSO_CALLBACK_URL=""
KAPSO_WEBHOOK_URL=""
# El mismo secreto del project webhook configurado en el dashboard de Kapso.
KAPSO_WEBHOOK_SECRET=""
# KAPSO_API_URL="https://api.kapso.ai"
# App de alumnos (acceso sin contraseña por link de un solo uso; ver AGENTS.md).
# Comprobantes de pago: storage privado compatible con S3 (RustFS, MinIO, R2, AWS).
# Sin estas cuatro variables, "Informar pago" responde 503 storage_not_available.
S3_ENDPOINT="http://localhost:9000"
S3_BUCKET="gruperly-receipts"
S3_ACCESS_KEY_ID=""
S3_SECRET_ACCESS_KEY=""
S3_REGION="us-east-1"
# on = URLs estilo AWS (bucket.endpoint). RustFS/MinIO usan path-style: dejalo vacío.
S3_VIRTUAL_HOSTED=""
# Días que se guarda un comprobante después de que el profe lo revisó. 0 = para siempre.
RECEIPT_RETENTION_DAYS="0"
# WebAuthn (Face ID / huella del alumno). Por defecto salen de WEB_URL; cambialos
# solo si la web se sirve desde otro origen (p. ej. un túnel para probar en el teléfono).
# WEBAUTHN_RP_ID="localhost"
# WEBAUTHN_ORIGIN="http://localhost:6173"
# Proxies delante de la API que agregan X-Forwarded-For (1 = solo nginx; 2 = Traefik + nginx).
# Define qué IP cuenta para el rate limit de "Pedir un link a mi mail".
TRUSTED_PROXY_HOPS="1"