chore: Discard unused Platform stripe events (#14822)

* chore: discard unused webhooks

* chore: discard early
This commit is contained in:
Erik authored and GitHub committed 2024-05-02 16:31:50 +00:00
1 parent 6c8fced247
commit 00372b6b3b
1 file changed
+13 -2
@@ -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",
};
}
}