chore: Discard unused Platform stripe events (#14822)
* chore: discard unused webhooks * chore: discard early
This commit is contained in:
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",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user