Skip to content

Commit

Permalink
take into account expired paid licenses in getSubscriptionFromCheckIn
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Sep 19, 2024
1 parent 9588318 commit 713ad28
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/plus/gk/checkin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { Organization } from './account/organization';
import type { Subscription } from './account/subscription';
import { getSubscriptionPlan, getSubscriptionPlanPriority, SubscriptionPlanId } from './account/subscription';
import {
computeSubscriptionState,
getSubscriptionPlan,
getSubscriptionPlanPriority,
SubscriptionPlanId,
SubscriptionState,
} from './account/subscription';

export interface GKCheckInResponse {
readonly user: GKUser;
Expand Down Expand Up @@ -66,9 +72,7 @@ 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 !== 'expired' && license[1].latestStatus !== 'cancelled',
);
paidLicenses = paidLicenses.filter(license => license[1].latestStatus !== 'cancelled');
if (paidLicenses.length > 1) {
paidLicenses.sort(
(a, b) =>
Expand Down Expand Up @@ -176,7 +180,18 @@ export function getSubscriptionFromCheckIn(
);
}

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

Expand Down

0 comments on commit 713ad28

Please sign in to comment.