From 00372b6b3bbbf0e2c7fd2a000dac6313e1e5d13f Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 2 May 2024 13:31:50 -0300 Subject: [PATCH] chore: Discard unused Platform stripe events (#14822) * chore: discard unused webhooks * chore: discard early --- .../billing/controllers/billing.controller.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/api/v2/src/modules/billing/controllers/billing.controller.ts b/apps/api/v2/src/modules/billing/controllers/billing.controller.ts index 00bca4190a..00319098f3 100644 --- a/apps/api/v2/src/modules/billing/controllers/billing.controller.ts +++ b/apps/api/v2/src/modules/billing/controllers/billing.controller.ts @@ -104,10 +104,19 @@ export class BillingController { if (event.type === "customer.subscription.created" || event.type === "customer.subscription.updated") { const subscription = event.data.object as Stripe.Subscription; + if (!subscription.metadata?.teamId) { + return { + status: "success", + }; + } + const teamId = Number.parseInt(subscription.metadata.teamId); const plan = subscription.metadata.plan; if (!plan || !teamId) { - throw new Error("Invalid webhook received."); + this.logger.log("Webhook received but not pertaining to Platform, discarding."); + return { + status: "success", + }; } await this.billingService.setSubscriptionForTeam( @@ -121,6 +130,8 @@ export class BillingController { }; } - throw new BadRequestException(`Unhandled event type ${event.type}`); + return { + status: "success", + }; } }