Skip to content

Commit 294cdb5

Browse files
committed
take into account expired paid licenses in getSubscriptionFromCheckIn
1 parent b8466b7 commit 294cdb5

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 interface GKCheckInResponse {
713
readonly user: GKUser;
@@ -67,9 +73,7 @@ export function getSubscriptionFromCheckIn(
6773

6874
let effectiveLicenses = Object.entries(data.licenses.effectiveLicenses) as [GKLicenseType, GKLicense][];
6975
let paidLicenses = Object.entries(data.licenses.paidLicenses) as [GKLicenseType, GKLicense][];
70-
paidLicenses = paidLicenses.filter(
71-
license => license[1].latestStatus !== 'expired' && license[1].latestStatus !== 'cancelled',
72-
);
76+
paidLicenses = paidLicenses.filter(license => license[1].latestStatus !== 'cancelled');
7377
if (paidLicenses.length > 1) {
7478
paidLicenses.sort(
7579
(a, b) =>
@@ -177,7 +181,18 @@ export function getSubscriptionFromCheckIn(
177181
);
178182
}
179183

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

0 commit comments

Comments
 (0)