Spaces:
Build error
Build error
File size: 4,673 Bytes
3eebcd0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | # ✅ 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!** 🚀
|