144 lines
4.4 KiB
Markdown
144 lines
4.4 KiB
Markdown
# MongoDB Plans Seed Script
|
|
|
|
## ⚠️ IMPORTANTE - LEIA ANTES DE EXECUTAR
|
|
|
|
Este script cria **2 planos** no MongoDB:
|
|
1. **Premium Mensal** - Cobrança recorrente mensal
|
|
2. **Premium Anual** - Cobrança anual com 20% de desconto
|
|
|
|
**VOCÊ PRECISA ATUALIZAR OS STRIPE PRICE IDs** antes de executar em produção!
|
|
|
|
## 📋 Pré-requisitos
|
|
|
|
### 1. Criar Produto no Stripe
|
|
|
|
1. Acesse [Stripe Dashboard](https://dashboard.stripe.com/products)
|
|
2. Crie um produto "QR Rapido Premium"
|
|
3. Anote o Product ID (ex: `prod_SnfQTxwE3i8r5L`)
|
|
|
|
### 2. Criar Price IDs no Stripe
|
|
|
|
Para **CADA PAÍS** (BR, PY, US), crie **2 preços** (mensal e anual):
|
|
|
|
#### Brasil (BRL):
|
|
- **Mensal**: R$ 9,90/mês
|
|
- No Stripe: "Premium Mensal - Brasil"
|
|
- Copie o Price ID: `price_xxxxx_monthly_br`
|
|
- **Anual**: R$ 95,04/ano (economia de 20%)
|
|
- No Stripe: "Premium Anual - Brasil"
|
|
- Copie o Price ID: `price_xxxxx_yearly_br`
|
|
|
|
#### Paraguai (PYG):
|
|
- **Mensal**: 35.000 Gs/mês
|
|
- No Stripe: "Premium Mensal - Paraguay"
|
|
- Copie o Price ID: `price_xxxxx_monthly_py`
|
|
- **Anual**: 336.000 Gs/ano (economia de 20%)
|
|
- No Stripe: "Premium Anual - Paraguay"
|
|
- Copie o Price ID: `price_xxxxx_yearly_py`
|
|
|
|
#### EUA/Internacional (USD):
|
|
- **Mensal**: $1,99/mês
|
|
- No Stripe: "Premium Monthly - USA"
|
|
- Copie o Price ID: `price_xxxxx_monthly_us`
|
|
- **Anual**: $19,10/ano (economia de 20%)
|
|
- No Stripe: "Premium Yearly - USA"
|
|
- Copie o Price ID: `price_xxxxx_yearly_us`
|
|
|
|
### 3. Atualizar appsettings.json
|
|
|
|
**Edite `appsettings.json`** (para desenvolvimento/teste):
|
|
```json
|
|
"Stripe": {
|
|
"Plans": {
|
|
"Monthly": {
|
|
"BR": "price_xxxxx_monthly_br", // ← Cole seu Price ID aqui
|
|
"PY": "price_xxxxx_monthly_py", // ← Cole seu Price ID aqui
|
|
"US": "price_xxxxx_monthly_us" // ← Cole seu Price ID aqui
|
|
},
|
|
"Yearly": {
|
|
"BR": "price_xxxxx_yearly_br", // ← Cole seu Price ID aqui
|
|
"PY": "price_xxxxx_yearly_py", // ← Cole seu Price ID aqui
|
|
"US": "price_xxxxx_yearly_us" // ← Cole seu Price ID aqui
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
**Edite `appsettings.Production.json`** (para produção) com os Price IDs **de produção** (mode live)
|
|
|
|
## 🚀 Como Executar
|
|
|
|
### Ambiente Local (Development)
|
|
|
|
```bash
|
|
# Se MongoDB estiver rodando localmente
|
|
mongosh "mongodb://localhost:27017/QrRapido" Scripts/seed-mongodb-plans.js
|
|
```
|
|
|
|
### Ambiente de Produção
|
|
|
|
```bash
|
|
# Conectar ao MongoDB de produção e executar o script
|
|
mongosh "mongodb://admin:c4rn31r0@129.146.116.218:27017,141.148.162.114:27017/QrRapido?replicaSet=rs0&authSource=admin" Scripts/seed-mongodb-plans.js
|
|
```
|
|
|
|
**OU via SSH no servidor:**
|
|
|
|
```bash
|
|
# Conectar ao servidor
|
|
ssh ubuntu@141.148.162.114
|
|
|
|
# Copiar o script para o servidor
|
|
# (você pode usar scp ou copiar o conteúdo manualmente)
|
|
|
|
# Executar o script
|
|
mongosh "mongodb://admin:c4rn31r0@localhost:27017/QrRapido?authSource=admin" seed-mongodb-plans.js
|
|
```
|
|
|
|
## ✅ Verificar se Funcionou
|
|
|
|
```bash
|
|
# Conectar ao MongoDB
|
|
mongosh "mongodb://admin:c4rn31r0@129.146.116.218:27017,141.148.162.114:27017/QrRapido?replicaSet=rs0&authSource=admin"
|
|
|
|
# Verificar os planos inseridos
|
|
use QrRapido
|
|
db.Plans.find().pretty()
|
|
```
|
|
|
|
Você deve ver um documento com:
|
|
- `name`: Nomes em pt-BR, es-PY, en
|
|
- `stripePriceId`: O Price ID padrão do Stripe
|
|
- `pricesByCountry`: Preços por país (BR, PY, US)
|
|
- `isActive`: true
|
|
|
|
## 🔧 Troubleshooting
|
|
|
|
### Erro: "Authentication failed"
|
|
- Verifique se a senha do MongoDB está correta no connection string
|
|
- Verifique se o usuário `admin` tem permissões no banco `QrRapido`
|
|
|
|
### Erro: "MongoServerError: E11000 duplicate key error"
|
|
- Já existe um plano com o mesmo ID
|
|
- Execute `db.Plans.deleteMany({})` primeiro para limpar (CUIDADO em produção!)
|
|
|
|
### Stripe retorna erro "No such price"
|
|
- Você não atualizou os `stripePriceId` no script
|
|
- Os Price IDs no script não existem no seu Stripe Dashboard
|
|
- Verifique se está usando as chaves corretas (test vs live mode)
|
|
|
|
## 📝 Próximos Passos
|
|
|
|
Após executar este script:
|
|
|
|
1. ✅ Verificar no MongoDB que o plano foi criado: `db.Plans.find()`
|
|
2. ✅ Testar o fluxo de assinatura em `/Pagamento/SelecaoPlano`
|
|
3. ✅ Confirmar que o Stripe recebe o checkout com o Price ID correto
|
|
4. ✅ Testar o webhook após pagamento bem-sucedido
|
|
|
|
## 🔗 Links Úteis
|
|
|
|
- [Stripe Dashboard - Products](https://dashboard.stripe.com/products)
|
|
- [Stripe Dashboard - Prices](https://dashboard.stripe.com/prices)
|
|
- [Stripe Webhooks](https://dashboard.stripe.com/webhooks)
|