fix: resolver erro de liberação de curso em pagamento por cartão Asaas webhook omitindo description
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m2s Details

This commit is contained in:
Sidney Gomes 2026-07-24 22:55:14 -03:00
parent 00f12e721d
commit f82fe92d70
1 changed files with 8 additions and 8 deletions

View File

@ -1757,7 +1757,7 @@ app.post('/api/webhooks/asaas', async (req: Request, res: Response) => {
if (existingPayment) {
if (newStatus) {
await prisma.payment.update({
existingPayment = await prisma.payment.update({
where: { id: payment.id },
data: {
status: newStatus as any,
@ -1771,7 +1771,7 @@ app.post('/api/webhooks/asaas', async (req: Request, res: Response) => {
orderBy: { createdAt: 'desc' }
});
await prisma.payment.create({
existingPayment = await prisma.payment.create({
data: {
id: payment.id,
userId: user.id,
@ -1788,20 +1788,20 @@ app.post('/api/webhooks/asaas', async (req: Request, res: Response) => {
}
const description = payment.description || '';
const isCoursePayment = description.startsWith('unlock_course_');
const isCoursePayment = existingPayment?.courseId ? true : description.startsWith('unlock_course_');
const courseIdToUnlock = existingPayment?.courseId || description.replace('unlock_course_', '');
if (isPaid) {
if (isCoursePayment) {
const courseId = description.replace('unlock_course_', '');
if (isCoursePayment && courseIdToUnlock) {
let newUnlocked = user.unlockedCourses || [];
if (!newUnlocked.includes(courseId)) {
newUnlocked.push(courseId);
if (!newUnlocked.includes(courseIdToUnlock)) {
newUnlocked.push(courseIdToUnlock);
}
await prisma.user.update({
where: { id: user.id },
data: { unlockedCourses: newUnlocked }
});
console.log(`Webhook: Curso ${courseId} LIBERADO para usuário ${user.email}`);
console.log(`Webhook: Curso ${courseIdToUnlock} LIBERADO para usuário ${user.email}`);
} else {
await prisma.user.update({
where: { id: user.id },