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
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 1m2s
Details
This commit is contained in:
parent
00f12e721d
commit
f82fe92d70
16
server.ts
16
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 },
|
||||
|
|
|
|||
Loading…
Reference in New Issue