From fa45dcb0d1877883ac9cbb53596827382b90476f Mon Sep 17 00:00:00 2001 From: isra el Date: Sat, 15 Feb 2025 14:28:54 +0300 Subject: [PATCH] chore(api): add more logs to billing webhook --- api/src/billing/billing.controller.ts | 10 +++++++--- api/src/billing/billing.service.ts | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/src/billing/billing.controller.ts b/api/src/billing/billing.controller.ts index 4e12817..289c918 100644 --- a/api/src/billing/billing.controller.ts +++ b/api/src/billing/billing.controller.ts @@ -42,15 +42,19 @@ export class BillingController { // Handle Polar.sh webhook events switch (payload.type) { case 'subscription.created': + console.log('polar subscription.created') + console.log(payload) await this.billingService.switchPlan({ - userId: payload.data.userId, - newPlanName: payload.data?.product?.name || 'pro', + userId: payload.data.customerId, + newPlanName: payload.data?.product?.name?.split(' ')[payload.data?.product?.name?.length - 1] || 'pro', newPlanPolarProductId: payload.data?.product?.id, }) break // @ts-ignore case 'subscription.cancelled': + console.log('polar subscription.cancelled') + console.log(payload) await this.billingService.switchPlan({ // @ts-ignore userId: payload?.data?.userId, @@ -58,7 +62,7 @@ export class BillingController { }) break default: - console.log('Unhandled event type:', payload.type) + console.log('Unhandled polar event type:', payload.type) break } } diff --git a/api/src/billing/billing.service.ts b/api/src/billing/billing.service.ts index 7b8224b..19807e3 100644 --- a/api/src/billing/billing.service.ts +++ b/api/src/billing/billing.service.ts @@ -105,8 +105,10 @@ export class BillingService { customerEmail: user.email, customerName: user.name, customerIpAddress: req.ip, + customerId: user._id?.toString(), metadata: { userId: user._id?.toString(), + customerId: user._id?.toString(), }, } const discount = await this.polarApi.discounts.get({