Skip to content

Commit 317555e

Browse files
committed
refactor(billing): enforce minimum term for starter and managed plans
- Added a minimum term of 12 months for both starter and managed plans in the billing settings. - Updated logic to calculate if the minimum term has been met, considering free trials. - Adjusted cancellation date calculation to reflect the new minimum term requirements. - Enhanced user messaging to clarify the commitment needed for the starter plan.
1 parent 2ac788d commit 317555e

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

  • apps/app/src/app/(app)/[orgId]/settings/billing

apps/app/src/app/(app)/[orgId]/settings/billing/page.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default function BillingPage() {
8080
'Community Support',
8181
],
8282
trialDays: 14,
83+
minimumTermMonths: 12,
8384
},
8485
managed: {
8586
displayName: 'Done For You',
@@ -98,10 +99,16 @@ export default function BillingPage() {
9899

99100
const currentPlanConfig = planConfig[planType];
100101

101-
// Calculate if minimum term has been met for managed plans
102+
// Calculate if minimum term has been met for both starter and managed plans
102103
const hasMetMinimumTerm = () => {
104+
// Free trials can be cancelled anytime
105+
if (isTrialing) {
106+
return true;
107+
}
108+
109+
// Only enforce minimum term for starter and managed plans
103110
if (
104-
planType !== 'managed' ||
111+
(planType !== 'starter' && planType !== 'managed') ||
105112
!('currentPeriodStart' in subscription) ||
106113
subscription.currentPeriodStart == null
107114
) {
@@ -113,15 +120,25 @@ export default function BillingPage() {
113120
const monthsElapsed =
114121
(now.getFullYear() - startDate.getFullYear()) * 12 + (now.getMonth() - startDate.getMonth());
115122

116-
return monthsElapsed >= (planConfig.managed.minimumTermMonths || 12);
123+
const minimumTermMonths =
124+
planType === 'starter'
125+
? planConfig.starter.minimumTermMonths
126+
: planConfig.managed.minimumTermMonths;
127+
128+
return monthsElapsed >= (minimumTermMonths || 12);
117129
};
118130

119131
const canCancelSubscription = hasMetMinimumTerm();
120132

121133
// Calculate when cancellation will be available
122134
const getCancellationAvailableDate = () => {
135+
// Free trials don't have minimum term
136+
if (isTrialing) {
137+
return null;
138+
}
139+
123140
if (
124-
planType !== 'managed' ||
141+
(planType !== 'starter' && planType !== 'managed') ||
125142
!('currentPeriodStart' in subscription) ||
126143
subscription.currentPeriodStart == null
127144
) {
@@ -130,9 +147,12 @@ export default function BillingPage() {
130147

131148
const startDate = new Date(subscription.currentPeriodStart * 1000);
132149
const cancellationDate = new Date(startDate);
133-
cancellationDate.setMonth(
134-
cancellationDate.getMonth() + (planConfig.managed.minimumTermMonths || 12),
135-
);
150+
const minimumTermMonths =
151+
planType === 'starter'
152+
? planConfig.starter.minimumTermMonths
153+
: planConfig.managed.minimumTermMonths;
154+
155+
cancellationDate.setMonth(cancellationDate.getMonth() + (minimumTermMonths || 12));
136156

137157
return cancellationDate;
138158
};
@@ -349,8 +369,8 @@ export default function BillingPage() {
349369
</p>
350370
{planType === 'starter' && (
351371
<p className="text-sm">
352-
Add a payment method now to continue after your 14-day trial. You won't be charged
353-
until the trial ends.
372+
Add a payment method now to continue after your trial. You won't be charged until
373+
the trial ends. Note: This plan requires a 12-month minimum commitment.
354374
</p>
355375
)}
356376
{planType === 'managed' && (
@@ -469,7 +489,7 @@ export default function BillingPage() {
469489
</div>
470490
)}
471491

472-
{planType === 'managed' &&
492+
{(planType === 'starter' || planType === 'managed') &&
473493
!canCancelSubscription &&
474494
getCancellationAvailableDate() && (
475495
<div className="flex items-center justify-between">

0 commit comments

Comments
 (0)