fix: auto refresh simulated customer id when real asaas key is set and change 500 status to 400
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 44s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 44s
Details
This commit is contained in:
parent
fb84a2ccb6
commit
ba998abbc7
13
server.ts
13
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' });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue