Skip to content

Commit 38cd896

Browse files
fix(pricing): update LemonSqueezy variant selection logic (#432)
* fix(pricing): update LemonSqueezy variant selection logic Conditionally set lemonVariantId based on NEXT_PUBLIC_AUTHORIZED_TRIAL_AMOUNT to ensure the correct variant (with or without setup fee) is used for trials. * fix(pricing): improve LemonSqueezy variant fallback logic Update pricing configuration to robustly handle LemonSqueezy variant selection. When 'NEXT_PUBLIC_AUTHORIZED_TRIAL_AMOUNT' is enabled, the code now checks if the specific setup-fee variant ID exists. If it is missing, it gracefully falls back to the standard variant ID, preventing potential runtime errors.
1 parent b930ca7 commit 38cd896

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/types.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ export const defaultPricingConfig: PricingPlanConfig = {
7272
envKey: 'STANDARD_PLAN',
7373
trialPeriodDays: 4,
7474

75-
// LemonSqueezy configuration - uses variant with setup fees if trial amount is configured
76-
lemonVariantId: process.env.NEXT_PUBLIC_STANDARD_TRIAL_AMOUNT_ID
77-
? process.env.NEXT_PUBLIC_LEMONSQUEEZY_STANDARD_WITH_SETUP_VARIANT_ID
78-
: process.env.NEXT_PUBLIC_LEMONSQUEEZY_STANDARD_VARIANT_ID,
75+
// LemonSqueezy configuration - selects the setup-fee variant when the authorization flag is true
76+
lemonVariantId:
77+
process.env.NEXT_PUBLIC_AUTHORIZED_TRIAL_AMOUNT === 'true' &&
78+
process.env.NEXT_PUBLIC_LEMONSQUEEZY_STANDARD_WITH_SETUP_VARIANT_ID
79+
? process.env.NEXT_PUBLIC_LEMONSQUEEZY_STANDARD_WITH_SETUP_VARIANT_ID
80+
: process.env.NEXT_PUBLIC_LEMONSQUEEZY_STANDARD_VARIANT_ID || '',
7981

8082
lemonCheckoutUrl: '',
8183

@@ -111,10 +113,12 @@ export const defaultPricingConfig: PricingPlanConfig = {
111113

112114
envKey: 'PREMIUM_PLAN',
113115

114-
// LemonSqueezy configuration - uses variant with setup fees if trial amount is configured
115-
lemonVariantId: process.env.NEXT_PUBLIC_PREMIUM_TRIAL_AMOUNT_ID
116-
? process.env.NEXT_PUBLIC_LEMONSQUEEZY_PREMIUM_WITH_SETUP_VARIANT_ID
117-
: process.env.NEXT_PUBLIC_LEMONSQUEEZY_PREMIUM_VARIANT_ID,
116+
// LemonSqueezy configuration - selects the setup-fee variant when the authorization flag is true
117+
lemonVariantId:
118+
process.env.NEXT_PUBLIC_AUTHORIZED_TRIAL_AMOUNT === 'true' &&
119+
process.env.NEXT_PUBLIC_LEMONSQUEEZY_PREMIUM_WITH_SETUP_VARIANT_ID
120+
? process.env.NEXT_PUBLIC_LEMONSQUEEZY_PREMIUM_WITH_SETUP_VARIANT_ID
121+
: process.env.NEXT_PUBLIC_LEMONSQUEEZY_PREMIUM_VARIANT_ID || '',
118122

119123
lemonCheckoutUrl: '',
120124

0 commit comments

Comments
 (0)