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