Skip to content

Commit d349d68

Browse files
committed
take into account expired paid licenses in getSubscriptionFromCheckIn
1 parent 0e91b3e commit d349d68

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/plus/gk/checkin.ts

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

612
export type GKLicenses = Partial<Record<GKLicenseType, GKLicense>>;
713

@@ -69,9 +75,7 @@ export function getSubscriptionFromCheckIn(
6975

7076
let effectiveLicenses = Object.entries(data.licenses.effectiveLicenses) as [GKLicenseType, GKLicense][];
7177
let paidLicenses = Object.entries(data.licenses.paidLicenses) as [GKLicenseType, GKLicense][];
72-
paidLicenses = paidLicenses.filter(
73-
license => license[1].latestStatus !== 'expired' && license[1].latestStatus !== 'cancelled',
74-
);
78+
paidLicenses = paidLicenses.filter(license => license[1].latestStatus !== 'cancelled');
7579
if (paidLicenses.length > 1) {
7680
paidLicenses.sort(
7781
(a, b) =>
@@ -179,7 +183,18 @@ export function getSubscriptionFromCheckIn(
179183
);
180184
}
181185

182-
if (effective == null || getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id)) {
186+
const isActualLicenseExpired =
187+
computeSubscriptionState({
188+
plan: {
189+
actual: actual,
190+
effective: actual,
191+
},
192+
account: account,
193+
}) === SubscriptionState.PaidExpired;
194+
if (
195+
effective == null ||
196+
(getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id) && !isActualLicenseExpired)
197+
) {
183198
effective = { ...actual };
184199
}
185200

0 commit comments

Comments
 (0)