Skip to content

Commit

Permalink
add isTrial check for pro trial accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Sep 24, 2024
1 parent ff61804 commit 4a63648
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/plus/gk/account/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface SubscriptionPlan {
readonly startedOn: string;
readonly expiresOn?: string | undefined;
readonly organizationId: string | undefined;
readonly isTrial: boolean;
}

export interface SubscriptionAccount {
Expand Down Expand Up @@ -173,6 +174,7 @@ export function getSubscriptionPlan(
expiresOn?: Date,
cancelled: boolean = false,
nextTrialOptInDate?: string,
isTrial: boolean = false,
): SubscriptionPlan {
return {
id: id,
Expand All @@ -184,6 +186,7 @@ export function getSubscriptionPlan(
nextTrialOptInDate: nextTrialOptInDate,
startedOn: (startedOn ?? new Date()).toISOString(),
expiresOn: expiresOn != null ? expiresOn.toISOString() : undefined,
isTrial: isTrial,
};
}

Expand Down Expand Up @@ -244,7 +247,7 @@ export function isSubscriptionExpired(subscription: Optional<Subscription, 'stat
}

export function isSubscriptionTrial(subscription: Optional<Subscription, 'state'>): boolean {
return subscription.plan.actual.id !== subscription.plan.effective.id;
return subscription.plan.effective.isTrial;
}

export function isSubscriptionInProTrial(subscription: Optional<Subscription, 'state'>): boolean {
Expand Down
3 changes: 2 additions & 1 deletion src/plus/gk/account/subscriptionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ export class SubscriptionService implements Disposable {
...this._subscription,
plan: {
...this._subscription.plan,
effective: getSubscriptionPlan(SubscriptionPlanId.Pro, false, 0, undefined, startedOn, expiresOn),
effective: getSubscriptionPlan(SubscriptionPlanId.Pro, false, 0, undefined, startedOn, expiresOn, true),
},
previewTrial: previewTrial,
});
Expand Down Expand Up @@ -1233,6 +1233,7 @@ export class SubscriptionService implements Disposable {
undefined,
new Date(subscription.previewTrial.startedOn),
new Date(subscription.previewTrial.expiresOn),
true,
),
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/plus/gk/checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export function getSubscriptionFromCheckIn(
license.organizationId,
new Date(license.latestStartDate),
new Date(license.latestEndDate),
license.latestStatus === 'trial' || license.latestStatus === 'in_trial',
);
}

Expand Down Expand Up @@ -176,6 +177,7 @@ export function getSubscriptionFromCheckIn(
new Date(license.latestEndDate),
license.latestStatus === 'cancelled',
license.nextOptInDate ?? data.nextOptInDate,
license.latestStatus === 'trial' || license.latestStatus === 'in_trial',
);
}

Expand Down

0 comments on commit 4a63648

Please sign in to comment.