Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: stop pausing retroactively
Marc Seitzffa4908294c6
diff --git a/ee/features/billing/cancellation/api/pause-route.ts b/ee/features/billing/cancellation/api/pause-route.tsindex 67f04ba3..944bdf7b 100644--- a/ee/features/billing/cancellation/api/pause-route.ts+++ b/ee/features/billing/cancellation/api/pause-route.ts@@ -64,7 +64,18 @@ export async function handleRoute(req: NextApiRequest, res: NextApiResponse) {const isOldAccount = team.plan.includes("+old");const stripe = stripeInstance(isOldAccount);- const pauseStartsAt = team.endsAt ? new Date(team.endsAt) : new Date();+ // Fetch the subscription from Stripe to get the actual current_period_end+ // This ensures we don't use stale data from the database+ const subscription = await stripe.subscriptions.retrieve(+ team.subscriptionId,+ );++ // Use the actual current_period_end from Stripe, ensuring pause starts at next billing cycle+ // Never allow retroactive pausing - pauseStartsAt must be in the future+ const now = new Date();+ const stripePeriodEnd = new Date(subscription.current_period_end * 1000);+ const pauseStartsAt = stripePeriodEnd > now ? stripePeriodEnd : now;+const pauseEndsAt = new Date(pauseStartsAt);pauseEndsAt.setDate(pauseStartsAt.getDate() + 90);const reminderAt = new Date(pauseEndsAt);@@ -132,6 +143,8 @@ export async function handleRoute(req: NextApiRequest, res: NextApiResponse) {res.status(200).json({success: true,message: "Subscription paused successfully",+ pauseStartsAt: pauseStartsAt.toISOString(),+ pauseEndsAt: pauseEndsAt.toISOString(),});} catch (error) {console.error("Error pausing subscription:", error);diff --git a/ee/features/billing/cancellation/components/pause-subscription-modal.tsx b/ee/features/billing/cancellation/components/pause-subscription-modal.tsxindex 08ea5e42..bd830bbd 100644--- a/ee/features/billing/cancellation/components/pause-subscription-modal.tsx+++ b/ee/features/billing/cancellation/components/pause-subscription-modal.tsx@@ -54,16 +54,14 @@ export function PauseSubscriptionModal({throw new Error("Failed to pause subscription");}- const pauseStartsAt = endsAt ? new Date(endsAt) : new Date();- const pauseEndsAt = new Date(pauseStartsAt);- pauseEndsAt.setDate(pauseStartsAt.getDate() + 90);+ const data = await response.json();- // Track the pause event for analytics+ // Track the pause event for analytics using actual dates from APIanalytics.capture("Subscription Paused", {teamId: currentTeamId,plan: plan,- pauseStartsAt: pauseStartsAt.toISOString(),- pauseEndsAt: pauseEndsAt.toISOString(),+ pauseStartsAt: data.pauseStartsAt,+ pauseEndsAt: data.pauseEndsAt,pauseDurationDays: 90,});@@ -79,7 +77,10 @@ export function PauseSubscriptionModal({}};- const pauseStartsAt = endsAt ? new Date(endsAt) : new Date();+ // Ensure pauseStartsAt is never in the past - pause should start at next billing cycle+ const now = new Date();+ const endsAtDate = endsAt ? new Date(endsAt) : now;+ const pauseStartsAt = endsAtDate > now ? endsAtDate : now;const pauseEndsAt = new Date(pauseStartsAt);pauseEndsAt.setDate(pauseStartsAt.getDate() + 90);