Skip to content

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

Fix subscription cancellation error when no discount exists

Cursor Agent57858fa5c1f2
diff --git a/ee/features/billing/cancellation/api/cancel-route.ts b/ee/features/billing/cancellation/api/cancel-route.ts
index a82f995e..5c2a07e5 100644
--- a/ee/features/billing/cancellation/api/cancel-route.ts
+++ b/ee/features/billing/cancellation/api/cancel-route.ts
@@ -62,7 +62,10 @@ export async function handleRoute(req: NextApiRequest, res: NextApiResponse) {
stripe.subscriptions.update(team.subscriptionId, {
cancel_at_period_end: true,
}),
- stripe.subscriptions.deleteDiscount(team.subscriptionId),
+ // Delete discount if one exists - catch errors since subscription may not have a discount
+ stripe.subscriptions.deleteDiscount(team.subscriptionId).catch(() => {
+ // Ignore error - subscription may not have a discount applied
+ }),
prisma.team.update({
where: { id: teamId },
data: {