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 Oct 4, 2024
1 parent 5bfa775 commit d3ce2e1
Show file tree
Hide file tree
Showing 3 changed files with 7 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 @@ -40,6 +40,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 @@ -169,6 +170,7 @@ export function getSubscriptionPlan(
expiresOn?: Date,
cancelled: boolean = false,
nextTrialOptInDate?: string,
isTrial: boolean = false,
): SubscriptionPlan {
return {
id: id,
Expand All @@ -180,6 +182,7 @@ export function getSubscriptionPlan(
nextTrialOptInDate: nextTrialOptInDate,
startedOn: (startedOn ?? new Date()).toISOString(),
expiresOn: expiresOn != null ? expiresOn.toISOString() : undefined,
isTrial: isTrial,
};
}

Expand Down Expand Up @@ -240,7 +243,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
2 changes: 1 addition & 1 deletion src/plus/gk/account/subscriptionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ export class SubscriptionService implements Disposable {
const days = proPreviewLengthInDays;
const subscription = getPreviewSubscription(days, this._subscription);
this.changeSubscription(subscription);

setTimeout(async () => {
const confirm: MessageItem = { title: 'Continue' };
const learn: MessageItem = { title: 'See Pro Features' };
Expand Down Expand Up @@ -1235,6 +1234,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 @@ -143,6 +143,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 @@ -179,6 +180,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 d3ce2e1

Please sign in to comment.