Skip to content

Commit 713ad28

Browse files
committed
take into account expired paid licenses in getSubscriptionFromCheckIn
1 parent 9588318 commit 713ad28

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,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)