Skip to content

Commit

Permalink
remove expired licenses filter & check actual license expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Sep 20, 2024
1 parent 713ad28 commit 677526d
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/plus/gk/checkin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { Organization } from './account/organization';
import type { Subscription } from './account/subscription';
import {
computeSubscriptionState,
getSubscriptionPlan,
getSubscriptionPlanPriority,
isSubscriptionExpired,
SubscriptionPlanId,
SubscriptionState,
} from './account/subscription';

export interface GKCheckInResponse {
Expand Down Expand Up @@ -72,7 +71,6 @@ export function getSubscriptionFromCheckIn(

let effectiveLicenses = Object.entries(data.licenses.effectiveLicenses) as [GKLicenseType, GKLicense][];
let paidLicenses = Object.entries(data.licenses.paidLicenses) as [GKLicenseType, GKLicense][];
paidLicenses = paidLicenses.filter(license => license[1].latestStatus !== 'cancelled');
if (paidLicenses.length > 1) {
paidLicenses.sort(
(a, b) =>
Expand All @@ -82,6 +80,7 @@ export function getSubscriptionFromCheckIn(
licenseStatusPriority(a[1].latestStatus)),
);
}

if (effectiveLicenses.length > 1) {
effectiveLicenses.sort(
(a, b) =>
Expand Down Expand Up @@ -180,17 +179,10 @@ export function getSubscriptionFromCheckIn(
);
}

const isActualLicenseExpired =
computeSubscriptionState({
plan: {
actual: actual,
effective: actual,
},
account: account,
}) === SubscriptionState.PaidExpired;
if (
effective == null ||
(getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id) && !isActualLicenseExpired)
(getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id) &&
!isSubscriptionExpired(actual))
) {
effective = { ...actual };
}
Expand Down

0 comments on commit 677526d

Please sign in to comment.