Skip to content

Commit d439669

Browse files
committed
take into account expired paid licenses in getSubscriptionFromCheckIn
1 parent 758423a commit d439669

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/plus/gk/account/subscriptionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ export class SubscriptionService implements Disposable {
872872
if (
873873
!options?.force &&
874874
this._lastValidatedDate != null &&
875-
Date.now() - this._lastValidatedDate.getTime() < 12 * 60 * 60 * 1000 &&
875+
Date.now() - this._lastValidatedDate.getTime() < 1000 &&
876876
!isSubscriptionExpired(this._subscription)
877877
) {
878878
setLogScopeExit(scope, ` (${fromNow(this._lastValidatedDate.getTime(), true)})...`, 'skipped');

src/plus/gk/checkin.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { Organization } from './account/organization';
22
import type { Subscription } from './account/subscription';
3-
import { getSubscriptionPlan, getSubscriptionPlanPriority, SubscriptionPlanId } from './account/subscription';
3+
import {
4+
computeSubscriptionState,
5+
getSubscriptionPlan,
6+
getSubscriptionPlanPriority,
7+
SubscriptionPlanId,
8+
SubscriptionState,
9+
} from './account/subscription';
410

511
export interface GKCheckInResponse {
612
readonly user: GKUser;
@@ -66,9 +72,7 @@ export function getSubscriptionFromCheckIn(
6672

6773
let effectiveLicenses = Object.entries(data.licenses.effectiveLicenses) as [GKLicenseType, GKLicense][];
6874
let paidLicenses = Object.entries(data.licenses.paidLicenses) as [GKLicenseType, GKLicense][];
69-
paidLicenses = paidLicenses.filter(
70-
license => license[1].latestStatus !== 'expired' && license[1].latestStatus !== 'cancelled',
71-
);
75+
paidLicenses = paidLicenses.filter(license => license[1].latestStatus !== 'cancelled');
7276
if (paidLicenses.length > 1) {
7377
paidLicenses.sort(
7478
(a, b) =>
@@ -176,7 +180,18 @@ export function getSubscriptionFromCheckIn(
176180
);
177181
}
178182

179-
if (effective == null || getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id)) {
183+
const isActualLicenseExpired =
184+
computeSubscriptionState({
185+
plan: {
186+
actual: actual,
187+
effective: actual,
188+
},
189+
account: account,
190+
}) === SubscriptionState.PaidExpired;
191+
if (
192+
effective == null ||
193+
(getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id) && !isActualLicenseExpired)
194+
) {
180195
effective = { ...actual };
181196
}
182197

0 commit comments

Comments
 (0)