|
1 | 1 | import { SubscriptionPlanId } from '../../constants.subscription';
|
2 | 2 | import type { Organization } from './account/organization';
|
3 | 3 | 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'; |
5 | 11 |
|
6 | 12 | export interface GKCheckInResponse {
|
7 | 13 | readonly user: GKUser;
|
@@ -67,9 +73,7 @@ export function getSubscriptionFromCheckIn(
|
67 | 73 |
|
68 | 74 | let effectiveLicenses = Object.entries(data.licenses.effectiveLicenses) as [GKLicenseType, GKLicense][];
|
69 | 75 | 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'); |
73 | 77 | if (paidLicenses.length > 1) {
|
74 | 78 | paidLicenses.sort(
|
75 | 79 | (a, b) =>
|
@@ -177,7 +181,18 @@ export function getSubscriptionFromCheckIn(
|
177 | 181 | );
|
178 | 182 | }
|
179 | 183 |
|
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 | + ) { |
181 | 196 | effective = { ...actual };
|
182 | 197 | }
|
183 | 198 |
|
|
0 commit comments