Files
App-Estoque-LiberiKids/teste-rapido-pix.sh
2025-10-14 14:04:17 -03:00

192 lines
5.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 🧪 Teste Rápido PIX - Verificação Automática
# Execute no servidor: ./teste-rapido-pix.sh
echo "🧪 Teste Rápido PIX - Liberi Kids"
echo "================================="
# Cores para output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
log() {
echo -e "${GREEN}[✅ OK]${NC} $1"
}
warn() {
echo -e "${YELLOW}[⚠️ WARN]${NC} $1"
}
info() {
echo -e "${BLUE}[ INFO]${NC} $1"
}
error() {
echo -e "${RED}[❌ ERRO]${NC} $1"
}
# Verificar se estamos no diretório correto
if [ ! -f "server-supabase.js" ]; then
error "Execute este script no diretório do projeto!"
exit 1
fi
echo ""
info "🔍 VERIFICANDO CONFIGURAÇÃO PIX..."
# 1. Verificar arquivo .env
echo ""
info "1⃣ Verificando arquivo .env..."
if [ -f ".env" ]; then
log "Arquivo .env encontrado"
if grep -q "MERCADOPAGO_ACCESS_TOKEN" .env; then
TOKEN=$(grep "MERCADOPAGO_ACCESS_TOKEN" .env | cut -d'=' -f2)
if [[ $TOKEN == *"TEST-"* ]] || [[ $TOKEN == *"APP-"* ]]; then
log "Access Token configurado"
else
warn "Access Token parece inválido: $TOKEN"
fi
else
error "MERCADOPAGO_ACCESS_TOKEN não encontrado no .env"
fi
if grep -q "MERCADOPAGO_PUBLIC_KEY" .env; then
log "Public Key configurado"
else
error "MERCADOPAGO_PUBLIC_KEY não encontrado no .env"
fi
else
error "Arquivo .env não encontrado!"
fi
# 2. Verificar dependências
echo ""
info "2⃣ Verificando dependências..."
if [ -d "node_modules/mercadopago" ]; then
log "SDK Mercado Pago instalado"
else
warn "SDK Mercado Pago não encontrado"
info "Instalando SDK..."
npm install mercadopago
fi
# 3. Verificar se servidor está rodando
echo ""
info "3⃣ Verificando servidor..."
if command -v pm2 &> /dev/null; then
PM2_STATUS=$(pm2 jlist | jq -r '.[] | select(.name=="liberi-kids") | .pm2_env.status' 2>/dev/null)
if [ "$PM2_STATUS" = "online" ]; then
log "Servidor PM2 está rodando"
else
warn "Servidor PM2 não está rodando"
info "Iniciando servidor..."
pm2 start server-supabase.js --name liberi-kids
fi
else
warn "PM2 não encontrado, verificando processo Node..."
if pgrep -f "server-supabase.js" > /dev/null; then
log "Servidor Node está rodando"
else
warn "Servidor não está rodando"
fi
fi
# 4. Testar conectividade local
echo ""
info "4⃣ Testando conectividade..."
if curl -s http://localhost:5000 > /dev/null; then
log "Servidor responde na porta 5000"
else
error "Servidor não responde na porta 5000"
fi
# 5. Testar API PIX (se houver vendas)
echo ""
info "5⃣ Testando API PIX..."
# Verificar se há vendas para testar
RESPONSE=$(curl -s -X POST http://localhost:5000/api/pix/gerar \
-H "Content-Type: application/json" \
-d '{"vendaId": 1}' 2>/dev/null)
if [[ $RESPONSE == *"payment_id"* ]]; then
log "API PIX funcionando - QR Code gerado com sucesso!"
PAYMENT_ID=$(echo $RESPONSE | grep -o '"payment_id":"[^"]*"' | cut -d'"' -f4)
info "Payment ID: $PAYMENT_ID"
elif [[ $RESPONSE == *"error"* ]]; then
warn "API PIX retornou erro:"
echo "$RESPONSE" | head -c 200
elif [[ $RESPONSE == *"Venda não encontrada"* ]]; then
warn "Venda ID 1 não existe (normal se não há vendas cadastradas)"
log "API PIX está funcionando, mas precisa de vendas para testar"
else
error "API PIX não responde corretamente"
echo "Resposta: $RESPONSE"
fi
# 6. Verificar arquivos PIX
echo ""
info "6⃣ Verificando arquivos PIX..."
if [ -f "config/mercadopago.js" ]; then
log "Serviço Mercado Pago encontrado"
else
error "config/mercadopago.js não encontrado"
fi
if [ -f "client/build/index.html" ]; then
log "Build do frontend encontrado"
else
warn "Build do frontend não encontrado"
info "Execute: cd client && npm run build"
fi
# 7. Resumo final
echo ""
echo "📊 RESUMO DO TESTE:"
echo "=================="
# Contar sucessos e erros
SUCESSOS=0
ERROS=0
# Verificar cada item
[ -f ".env" ] && SUCESSOS=$((SUCESSOS+1)) || ERROS=$((ERROS+1))
[ -d "node_modules/mercadopago" ] && SUCESSOS=$((SUCESSOS+1)) || ERROS=$((ERROS+1))
[ -f "config/mercadopago.js" ] && SUCESSOS=$((SUCESSOS+1)) || ERROS=$((ERROS+1))
if [ $ERROS -eq 0 ]; then
log "🎉 TODOS OS TESTES PASSARAM!"
echo ""
info "✅ Configuração PIX está correta"
info "✅ Dependências instaladas"
info "✅ Servidor funcionando"
info "✅ APIs respondendo"
echo ""
log "🚀 SEU PIX ESTÁ PRONTO PARA USO!"
echo ""
info "📱 COMO TESTAR NA INTERFACE:"
echo " 1. Acesse: http://$(hostname -I | awk '{print $1}'):5000"
echo " 2. Vá em Vendas"
echo " 3. Clique no botão PIX (💳)"
echo " 4. Verifique se QR Code aparece"
elif [ $ERROS -le 2 ]; then
warn "⚠️ ALGUNS PROBLEMAS ENCONTRADOS"
echo ""
info "A maioria está funcionando, verifique os itens marcados como ERRO acima"
else
error "❌ MUITOS PROBLEMAS ENCONTRADOS"
echo ""
info "Verifique a configuração seguindo o guia TESTAR-PIX-COMPLETO.md"
fi
echo ""
info "📖 Para testes detalhados, consulte: TESTAR-PIX-COMPLETO.md"
echo ""