From f411bb2676d3cc035479d3a20c64f2ea4c0470eb Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 27 Feb 2023 13:57:11 -0500 Subject: [PATCH] Fixes issue w/ preview trial "winning" over paid --- src/plus/subscription/subscriptionService.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/plus/subscription/subscriptionService.ts b/src/plus/subscription/subscriptionService.ts index b003101..2ce8571 100644 --- a/src/plus/subscription/subscriptionService.ts +++ b/src/plus/subscription/subscriptionService.ts @@ -846,30 +846,34 @@ export class SubscriptionService implements Disposable { }; } - // Check if the preview has expired, if not apply it - if (subscription.previewTrial != null && (getTimeRemaining(subscription.previewTrial.expiresOn) ?? 0) > 0) { + // If the effective plan has expired, then replace it with the actual plan + if (isSubscriptionExpired(subscription)) { subscription = { ...subscription, plan: { ...subscription.plan, - effective: getSubscriptionPlan( - SubscriptionPlanId.Pro, - false, - undefined, - new Date(subscription.previewTrial.startedOn), - new Date(subscription.previewTrial.expiresOn), - ), + effective: subscription.plan.actual, }, }; } - // If the effective plan has expired, then replace it with the actual plan - if (isSubscriptionExpired(subscription)) { + // If we don't have a paid plan (or a non-preview trial), check if the preview trial has expired, if not apply it + if ( + !isSubscriptionPaid(subscription) && + subscription.previewTrial != null && + (getTimeRemaining(subscription.previewTrial.expiresOn) ?? 0) > 0 + ) { subscription = { ...subscription, plan: { ...subscription.plan, - effective: subscription.plan.actual, + effective: getSubscriptionPlan( + SubscriptionPlanId.Pro, + false, + undefined, + new Date(subscription.previewTrial.startedOn), + new Date(subscription.previewTrial.expiresOn), + ), }, }; }