Spaces:
Build error
Build error
| # ✅ Checklist de Verificación Pre-Producción | |
| ## 📋 Antes de Desplegar a Producción | |
| Marca cada item conforme lo completess: | |
| ### 1️⃣ Base de Datos | |
| - [ ] Ejecuté: `npx prisma migrate dev --name add_stripe_and_renewals` | |
| - [ ] Verifiqué con: `npx prisma studio` (veo campos Stripe) | |
| - [ ] BD migrada sin errores | |
| ### 2️⃣ Variables de Entorno | |
| - [ ] `.env` tiene `STRIPE_SECRET_KEY` (sk_test_...) | |
| - [ ] `.env` tiene `STRIPE_WEBHOOK_SECRET` (whsec_...) | |
| - [ ] `.env` tiene `DATABASE_URL` válida | |
| - [ ] Probé local: `npm run dev` inicia sin errors | |
| ### 3️⃣ Compilación | |
| - [ ] Ejecuté: `npm run build` | |
| - [ ] Resultado: "✓ Compiled successfully" | |
| - [ ] Cero errores de TypeScript | |
| ### 4️⃣ Testing Local | |
| - [ ] Instalé Stripe CLI: `stripe --version` | |
| - [ ] Ejecuté: `stripe listen --forward-to localhost:3000/api/payments/webhook` | |
| - [ ] Obtenía webhook signing secret (whsec_...) | |
| - [ ] Inicié servidor: `npm run dev` | |
| - [ ] Triggee evento: `stripe trigger checkout.session.completed` | |
| - [ ] Vi en consola: "✓ [Webhook] Received checkout.session.completed" | |
| ### 5️⃣ Endpoints Funcionan | |
| - [ ] `POST /api/influencers/subscription` - Crear suscripción ✅ | |
| - [ ] `GET /api/influencers/subscription?userId=X` - Listar ✅ | |
| - [ ] `POST /api/payments/checkout` - Generar session ✅ | |
| - [ ] `POST /api/payments/webhook` - Recibir webhooks ✅ | |
| - [ ] `POST /api/influencers/subscription/cancel` - Cancelar ✅ | |
| - [ ] `GET /api/influencers/report?influencerId=X` - Reportes ✅ | |
| ### 6️⃣ Configuración Stripe Dashboard | |
| - [ ] Fui a [dashboard.stripe.com/webhooks](https://dashboard.stripe.com/webhooks) | |
| - [ ] Agregué endpoint: `https://<mi-dominio>/api/payments/webhook` | |
| - [ ] Seleccioné eventos: | |
| - [ ] checkout.session.completed | |
| - [ ] customer.subscription.created | |
| - [ ] customer.subscription.deleted | |
| - [ ] customer.subscription.updated | |
| - [ ] invoice.payment_succeeded | |
| - [ ] invoice.payment_failed | |
| - [ ] Copié Signing Secret → agregué a `.env.production` | |
| ### 7️⃣ Código Revisado | |
| - [ ] `src/lib/stripe.ts` tiene todas las funciones helper ✅ | |
| - [ ] `src/app/api/payments/webhook/route.ts` valida firma Stripe ✅ | |
| - [ ] `src/app/api/influencers/subscription/route.ts` crea `nextRenewalDate` ✅ | |
| - [ ] `src/app/api/influencers/report/route.ts` agrupa por estatus ✅ | |
| - [ ] `prisma/schema.prisma` tiene campos nuevos ✅ | |
| ### 8️⃣ Seguridad | |
| - [ ] `STRIPE_SECRET_KEY` NO está en GitHub (en `.env`, no en `.env.example`) | |
| - [ ] `STRIPE_WEBHOOK_SECRET` NO está en GitHub | |
| - [ ] `.env` está en `.gitignore` ✅ | |
| - [ ] No hay keys hardcodeadas en `src/` | |
| ### 9️⃣ Documentación | |
| - [ ] Leí: `MIGRATION_GUIDE.md` ✅ | |
| - [ ] Leí: `STRIPE_TESTING_GUIDE.md` ✅ | |
| - [ ] Entiendo el flujo: Cliente → Checkout → Stripe → Webhook → BD | |
| ### 🔟 VPS/Producción | |
| - [ ] URL de dominio lista: `https://<mi-dominio>` | |
| - [ ] SSL/HTTPS configurado ✅ | |
| - [ ] PostgreSQL en producción (o SQLite respaldada) ✅ | |
| - [ ] `.env` en producción tiene: | |
| - [ ] `STRIPE_SECRET_KEY=sk_live_XXX` (clave VIVA, no test) | |
| - [ ] `STRIPE_WEBHOOK_SECRET=whsec_XXX` (del webhook en producción) | |
| - [ ] `DATABASE_URL` apuntando a BD producción | |
| - [ ] Ejecutaré en VPS: `npx prisma migrate deploy` | |
| --- | |
| ## 🚨 Errores Comunes | |
| | Error | Causa | Solución | | |
| |-------|-------|----------| | |
| | "Invalid webhook signature" | `STRIPE_WEBHOOK_SECRET` incorrecto | Copia nuevamente de Stripe Dashboard | | |
| | "Column 'stripeSubscriptionId' does not exist" | Migración no aplicada | `npx prisma migrate dev` | | |
| | "Cannot find module 'stripe'" | No instaló Stripe | `npm install stripe` | | |
| | "STRIPE_SECRET_KEY is undefined" | `.env` no tiene la key | Edita `.env` y agrega `STRIPE_SECRET_KEY` | | |
| | Webhooks no se reciben | Endpoint no existe en Stripe Dashboard | Agrega endpoint en Webhooks settings | | |
| --- | |
| ## 📊 Flujo de Pago Esperado | |
| ``` | |
| 1. Cliente: POST /api/payments/checkout | |
| ↓ | |
| 2. Server: Genera Stripe session | |
| ↓ | |
| 3. Cliente: Redirigen a checkout.stripe.com | |
| ↓ | |
| 4. Cliente: Completa pago en Stripe (tarjeta, etc) | |
| ↓ | |
| 5. Stripe: Envía webhook checkout.session.completed | |
| ↓ | |
| 6. Server: Webhook handler crea InfluencerSubscription + Earning | |
| ↓ | |
| 7. DB: Actualizado con suscripción activa | |
| ↓ | |
| 8. Cliente: Recibe email de Stripe + confirmación | |
| ``` | |
| --- | |
| ## 📞 Soporte | |
| Si algo falla: | |
| 1. **Revisa logs**: `npm run dev` (consola local) | |
| 2. **Stripe Dashboard**: [test/webhooks](https://dashboard.stripe.com/test/webhooks) → ver events | |
| 3. **Prisma Studio**: `npx prisma studio` → verificar datos en BD | |
| 4. **Este checklist**: Marca qué pasos ya hiciste | |
| --- | |
| **¡Cuando todos los items estén marcados ✅, estás listo para producción!** 🚀 | |