diff --git a/server.ts b/server.ts index c2ca8cd..542f48e 100644 --- a/server.ts +++ b/server.ts @@ -331,6 +331,10 @@ app.post('/api/courses/:id/unlock', authenticateToken, checkoutRateLimiter, asyn try { let customerId = user.asaasCustomerId; + const apiKey = AsaasService.getApiKey(); + if (apiKey && (customerId?.startsWith('cus_sim_') || customerId?.startsWith('cus_fallback_'))) { + customerId = null; + } if (!customerId) { customerId = await AsaasService.createCustomer(user.name, user.email); user.asaasCustomerId = customerId; @@ -388,7 +392,7 @@ app.post('/api/courses/:id/unlock', authenticateToken, checkoutRateLimiter, asyn res.json({ success: true, payment: newPayment, pixData }); } catch (err: any) { console.error('Course unlock error:', err); - res.status(500).json({ error: err.message || 'Erro ao processar pagamento do curso' }); + res.status(400).json({ error: err.message || 'Erro ao processar pagamento do curso' }); } }); @@ -511,6 +515,10 @@ app.post('/api/subscription/subscribe', authenticateToken, async (req: Authentic try { let customerId = user.asaasCustomerId; + const apiKey = AsaasService.getApiKey(); + if (apiKey && (customerId?.startsWith('cus_sim_') || customerId?.startsWith('cus_fallback_'))) { + customerId = null; + } if (!customerId) { customerId = await AsaasService.createCustomer(user.name, user.email); user.asaasCustomerId = customerId; @@ -554,7 +562,8 @@ app.post('/api/subscription/subscribe', authenticateToken, async (req: Authentic payment: newPayment }); } catch (err: any) { - res.status(500).json({ error: err.message || 'Erro ao processar assinatura' }); + console.error('Subscription error:', err); + res.status(400).json({ error: err.message || 'Erro ao processar assinatura' }); } });