From f82fe92d705b63ba87272e95a7ca57c06959f4ff Mon Sep 17 00:00:00 2001 From: Sidney Gomes Date: Fri, 24 Jul 2026 22:55:14 -0300 Subject: [PATCH] =?UTF-8?q?=20fix:=20resolver=20erro=20de=20libera=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20curso=20em=20pagamento=20por=20cart=C3=A3o=20Asa?= =?UTF-8?q?as=20webhook=20omitindo=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server.ts b/server.ts index 365aebe..3f5cbd6 100644 --- a/server.ts +++ b/server.ts @@ -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 },