11import { SubscriptionPlanId } from '../../constants.subscription' ;
22import type { Organization } from './account/organization' ;
33import type { Subscription } from './account/subscription' ;
4- import {
5- getSubscriptionPlan ,
6- getSubscriptionPlanPriority ,
7- isSubscriptionExpired ,
8- SubscriptionPlanId ,
9- } from './account/subscription' ;
4+ import { getSubscriptionPlan , getSubscriptionPlanPriority , isSubscriptionExpired } from './account/subscription' ;
105
116export type GKLicenses = Partial < Record < GKLicenseType , GKLicense > > ;
127
@@ -136,14 +131,21 @@ export function getSubscriptionFromCheckIn(
136131 organizationId != null ? paidLicensesByOrganizationId . get ( organizationId ) ?? bestPaidLicense : bestPaidLicense ;
137132 if ( chosenPaidLicense != null ) {
138133 const [ licenseType , license ] = chosenPaidLicense ;
134+ const latestStartDate = new Date ( license . latestStartDate ) ;
135+ const latestEndDate = new Date ( license . latestEndDate ) ;
136+ const today = new Date ( ) ;
139137 actual = getSubscriptionPlan (
140138 convertLicenseTypeToPlanId ( licenseType ) ,
141139 isBundleLicenseType ( licenseType ) ,
142140 license . reactivationCount ?? 0 ,
143141 license . organizationId ,
144- new Date ( license . latestStartDate ) ,
145- new Date ( license . latestEndDate ) ,
146- license . latestStatus === 'trial' || license . latestStatus === 'in_trial' ,
142+ latestStartDate ,
143+ latestEndDate ,
144+ undefined ,
145+ undefined ,
146+ ( license . latestStatus === 'in_trial' || license . latestStatus === 'trial' ) &&
147+ latestEndDate > today &&
148+ today > latestStartDate ,
147149 ) ;
148150 }
149151
@@ -161,6 +163,7 @@ export function getSubscriptionFromCheckIn(
161163 undefined ,
162164 undefined ,
163165 data . nextOptInDate ,
166+ false ,
164167 ) ;
165168 }
166169
@@ -171,6 +174,9 @@ export function getSubscriptionFromCheckIn(
171174 : bestEffectiveLicense ;
172175 if ( chosenEffectiveLicense != null ) {
173176 const [ licenseType , license ] = chosenEffectiveLicense ;
177+ const latestStartDate = new Date ( license . latestStartDate ) ;
178+ const latestEndDate = new Date ( license . latestEndDate ) ;
179+ const today = new Date ( ) ;
174180 effective = getSubscriptionPlan (
175181 convertLicenseTypeToPlanId ( licenseType ) ,
176182 isBundleLicenseType ( licenseType ) ,
@@ -180,7 +186,9 @@ export function getSubscriptionFromCheckIn(
180186 new Date ( license . latestEndDate ) ,
181187 license . latestStatus === 'cancelled' ,
182188 license . nextOptInDate ?? data . nextOptInDate ,
183- license . latestStatus === 'trial' || license . latestStatus === 'in_trial' ,
189+ ( license . latestStatus === 'in_trial' || license . latestStatus === 'trial' ) &&
190+ latestEndDate > today &&
191+ today > latestStartDate ,
184192 ) ;
185193 }
186194
0 commit comments