@@ -71,19 +71,20 @@ import { authenticationProviderScopes } from './authenticationProvider';
7171import type { GKCheckInResponse } from './models/checkin' ;
7272import type { Organization } from './models/organization' ;
7373import type { Promo } from './models/promo' ;
74- import type { Subscription } from './models/subscription' ;
74+ import type { Subscription , SubscriptionUpgradeCommandArgs } from './models/subscription' ;
7575import type { ServerConnection } from './serverConnection' ;
7676import { ensurePlusFeaturesEnabled } from './utils/-webview/plus.utils' ;
7777import { getConfiguredActiveOrganizationId , updateActiveOrganizationId } from './utils/-webview/subscription.utils' ;
7878import { getSubscriptionFromCheckIn } from './utils/checkin.utils' ;
7979import {
8080 assertSubscriptionState ,
81+ compareSubscriptionPlans ,
8182 computeSubscriptionState ,
8283 getCommunitySubscription ,
8384 getPreviewSubscription ,
8485 getSubscriptionPlan ,
8586 getSubscriptionPlanName ,
86- getSubscriptionPlanPriority ,
87+ getSubscriptionPlanTierType ,
8788 getSubscriptionStateString ,
8889 getSubscriptionTimeRemaining ,
8990 getTimeRemaining ,
@@ -357,11 +358,8 @@ export class SubscriptionService implements Disposable {
357358 registerCommand ( 'gitlens.plus.startPreviewTrial' , ( src ?: Source ) => this . startPreviewTrial ( src ) ) ,
358359 registerCommand ( 'gitlens.plus.reactivateProTrial' , ( src ?: Source ) => this . reactivateProTrial ( src ) ) ,
359360 registerCommand ( 'gitlens.plus.resendVerification' , ( src ?: Source ) => this . resendVerification ( src ) ) ,
360- registerCommand ( 'gitlens.plus.upgrade' , ( srcAndPlan ?: Source & { plan ?: SubscriptionPlanId } ) =>
361- this . upgrade (
362- srcAndPlan ? { source : srcAndPlan . source , detail : srcAndPlan . detail } : undefined ,
363- srcAndPlan ?. plan ,
364- ) ,
361+ registerCommand ( 'gitlens.plus.upgrade' , ( args ?: SubscriptionUpgradeCommandArgs ) =>
362+ this . upgrade ( args ?. plan , args ? { source : args . source , detail : args . detail } : undefined ) ,
365363 ) ,
366364
367365 registerCommand ( 'gitlens.plus.hide' , ( src ?: Source ) => this . setProFeaturesVisibility ( false , src ) ) ,
@@ -548,7 +546,7 @@ export class SubscriptionService implements Disposable {
548546 ) ;
549547
550548 if ( result === upgrade ) {
551- void this . upgrade ( source ) ;
549+ void this . upgrade ( SubscriptionPlanId . Pro , source ) ;
552550 } else if ( result === learn ) {
553551 void this . learnAboutPro ( { source : 'prompt' , detail : { action : 'trial-ended' } } , source ) ;
554552 }
@@ -657,9 +655,10 @@ export class SubscriptionService implements Disposable {
657655 @gate ( ( ) => '' )
658656 @log ( )
659657 async reactivateProTrial ( source : Source | undefined ) : Promise < void > {
660- if ( ! ( await ensurePlusFeaturesEnabled ( ) ) ) return ;
661658 const scope = getLogScope ( ) ;
662659
660+ if ( ! ( await ensurePlusFeaturesEnabled ( ) ) ) return ;
661+
663662 if ( this . container . telemetry . enabled ) {
664663 this . container . telemetry . sendEvent ( 'subscription/action' , { action : 'reactivate' } , source ) ;
665664 }
@@ -892,11 +891,13 @@ export class SubscriptionService implements Disposable {
892891 }
893892
894893 @log ( )
895- async upgrade ( source : Source | undefined , plan ?: SubscriptionPlanId ) : Promise < boolean > {
894+ async upgrade ( plan : SubscriptionPlanId | undefined , source : Source | undefined ) : Promise < boolean > {
896895 const scope = getLogScope ( ) ;
897896
898897 if ( ! ( await ensurePlusFeaturesEnabled ( ) ) ) return false ;
899898
899+ plan ??= SubscriptionPlanId . Pro ;
900+
900901 let aborted = false ;
901902 const promo = await this . container . productConfig . getApplicablePromo ( this . _subscription . state ) ;
902903
@@ -920,14 +921,13 @@ export class SubscriptionService implements Disposable {
920921
921922 const hasAccount = this . _subscription . account != null ;
922923 if ( hasAccount ) {
923- // Do a pre-check-in to see if we've already upgraded to a paid plan.
924+ // Do a pre-check-in to see if we've already upgraded to a paid plan
924925 try {
925926 const session = await this . ensureSession ( false , source ) ;
926927 if ( session != null ) {
927928 if (
928929 ( await this . checkUpdatedSubscription ( source ) ) === SubscriptionState . Paid &&
929- getSubscriptionPlanPriority ( this . _subscription . plan . effective . id ) >=
930- getSubscriptionPlanPriority ( plan ?? SubscriptionPlanId . Pro )
930+ compareSubscriptionPlans ( this . _subscription . plan . effective . id , plan ) >= 0
931931 ) {
932932 return true ;
933933 }
@@ -938,20 +938,7 @@ export class SubscriptionService implements Disposable {
938938 const query = new URLSearchParams ( ) ;
939939 query . set ( 'source' , 'gitlens' ) ;
940940 query . set ( 'product' , 'gitlens' ) ;
941-
942- let planType = 'PRO' ;
943- switch ( plan ) {
944- case SubscriptionPlanId . Advanced :
945- planType = 'ADVANCED' ;
946- break ;
947- case SubscriptionPlanId . Teams :
948- planType = 'TEAMS' ;
949- break ;
950- case SubscriptionPlanId . Enterprise :
951- planType = 'ENTERPRISE' ;
952- break ;
953- }
954- query . set ( 'planType' , planType ) ;
941+ query . set ( 'planType' , getSubscriptionPlanTierType ( plan ) ) ;
955942
956943 if ( promo ?. code != null ) {
957944 query . set ( 'promoCode' , promo . code ) ;
0 commit comments