Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: return 200 when team was deleted

Marc Seitzc09dc2662ee1
diff --git a/ee/stripe/webhooks/customer-subscription-deleted.ts b/ee/stripe/webhooks/customer-subscription-deleted.ts
index 0f200236..87237d14 100644
--- a/ee/stripe/webhooks/customer-subscription-deleted.ts
+++ b/ee/stripe/webhooks/customer-subscription-deleted.ts
@@ -18,38 +18,48 @@ export async function customerSubscriptionDeleted(
// get free plan limits
const freePlanLimits = structuredClone(FREE_PLAN_LIMITS);
- // If a team cancels their subscription, reset their limits to free
- const team = await prisma.team.update({
- where: {
- stripeId,
- subscriptionId,
- },
- data: {
- plan: "free",
- subscriptionId: null,
- endsAt: null,
- startsAt: null,
- limits: freePlanLimits,
- },
- select: { id: true },
- });
-
- if (!team) {
+ try {
+ // If a team cancels their subscription, reset their limits to free
+ const team = await prisma.team.update({
+ where: {
+ stripeId,
+ subscriptionId,
+ },
+ data: {
+ plan: "free",
+ subscriptionId: null,
+ endsAt: null,
+ startsAt: null,
+ limits: freePlanLimits,
+ },
+ select: { id: true },
+ });
+
+ if (!team) {
+ await log({
+ message:
+ "Team with Stripe ID *`" +
+ stripeId +
+ "` and Subscription ID *`" +
+ subscriptionId +
+ "` not found in Stripe webhook `customer.subscription.deleted` callback" +
+ `\n\n Event: https://dashboard.stripe.com/events/${event.id}`,
+ type: "error",
+ });
+ return res.status(200).json({ received: true });
+ }
+
await log({
- message:
- "Team with Stripe ID *`" +
- stripeId +
- "` and Subscription ID *`" +
- subscriptionId +
- "`* not found in Stripe webhook `customer.subscription.deleted` callback" +
- `\n\n Event: https://dashboard.stripe.com/events/${event.id}`,
+ message: ":cry: Team *`" + team.id + "`* deleted their subscription",
+ type: "info",
+ });
+ } catch (error) {
+ await log({
+ message: `Error updating team ${stripeId} subscription ${subscriptionId}: ${error}`,
type: "error",
});
- return res.status(200).json({ received: true });
+ return res
+ .status(200)
+ .send("Team not found in database. Customer deleted their account.");
}
-
- await log({
- message: ":cry: Team *`" + team.id + "`* deleted their subscription",
- type: "info",
- });
}