Skip to content

Commit

Permalink
chore: Discard unused Platform stripe events (calcom#14822)
Browse files Browse the repository at this point in the history
* chore: discard unused webhooks

* chore: discard early
  • Loading branch information
exception authored May 2, 2024
1 parent 6c8fced commit 00372b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions apps/api/v2/src/modules/billing/controllers/billing.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -121,6 +130,8 @@ export class BillingController {
};
}

throw new BadRequestException(`Unhandled event type ${event.type}`);
return {
status: "success",
};
}
}

0 comments on commit 00372b6

Please sign in to comment.