8
8
using Bit . Core . AdminConsole . Repositories ;
9
9
using Bit . Core . AdminConsole . Services ;
10
10
using Bit . Core . Billing . Enums ;
11
+ using Bit . Core . Billing . Pricing ;
11
12
using Bit . Core . Billing . Services ;
12
13
using Bit . Core . Context ;
13
14
using Bit . Core . Entities ;
@@ -50,6 +51,7 @@ public class ProviderService : IProviderService
50
51
private readonly IDataProtectorTokenFactory < ProviderDeleteTokenable > _providerDeleteTokenDataFactory ;
51
52
private readonly IApplicationCacheService _applicationCacheService ;
52
53
private readonly IProviderBillingService _providerBillingService ;
54
+ private readonly IPricingClient _pricingClient ;
53
55
54
56
public ProviderService ( IProviderRepository providerRepository , IProviderUserRepository providerUserRepository ,
55
57
IProviderOrganizationRepository providerOrganizationRepository , IUserRepository userRepository ,
@@ -58,7 +60,7 @@ public ProviderService(IProviderRepository providerRepository, IProviderUserRepo
58
60
IOrganizationRepository organizationRepository , GlobalSettings globalSettings ,
59
61
ICurrentContext currentContext , IStripeAdapter stripeAdapter , IFeatureService featureService ,
60
62
IDataProtectorTokenFactory < ProviderDeleteTokenable > providerDeleteTokenDataFactory ,
61
- IApplicationCacheService applicationCacheService , IProviderBillingService providerBillingService )
63
+ IApplicationCacheService applicationCacheService , IProviderBillingService providerBillingService , IPricingClient pricingClient )
62
64
{
63
65
_providerRepository = providerRepository ;
64
66
_providerUserRepository = providerUserRepository ;
@@ -77,6 +79,7 @@ public ProviderService(IProviderRepository providerRepository, IProviderUserRepo
77
79
_providerDeleteTokenDataFactory = providerDeleteTokenDataFactory ;
78
80
_applicationCacheService = applicationCacheService ;
79
81
_providerBillingService = providerBillingService ;
82
+ _pricingClient = pricingClient ;
80
83
}
81
84
82
85
public async Task < Provider > CompleteSetupAsync ( Provider provider , Guid ownerUserId , string token , string key , TaxInfo taxInfo = null )
@@ -452,30 +455,31 @@ private async Task ApplyProviderPriceRateAsync(Organization organization, Provid
452
455
453
456
if ( ! string . IsNullOrWhiteSpace ( organization . GatewaySubscriptionId ) )
454
457
{
455
- var subscriptionItem = await GetSubscriptionItemAsync ( organization . GatewaySubscriptionId ,
456
- GetStripeSeatPlanId ( organization . PlanType ) ) ;
458
+ var plan = await _pricingClient . GetPlanOrThrow ( organization . PlanType ) ;
459
+
460
+ var subscriptionItem = await GetSubscriptionItemAsync (
461
+ organization . GatewaySubscriptionId ,
462
+ plan . PasswordManager . StripeSeatPlanId ) ;
463
+
457
464
var extractedPlanType = PlanTypeMappings ( organization ) ;
465
+ var extractedPlan = await _pricingClient . GetPlanOrThrow ( extractedPlanType ) ;
466
+
458
467
if ( subscriptionItem != null )
459
468
{
460
- await UpdateSubscriptionAsync ( subscriptionItem , GetStripeSeatPlanId ( extractedPlanType ) , organization ) ;
469
+ await UpdateSubscriptionAsync ( subscriptionItem , extractedPlan . PasswordManager . StripeSeatPlanId , organization ) ;
461
470
}
462
471
}
463
472
464
473
await _organizationRepository . UpsertAsync ( organization ) ;
465
474
}
466
475
467
- private async Task < Stripe . SubscriptionItem > GetSubscriptionItemAsync ( string subscriptionId , string oldPlanId )
476
+ private async Task < SubscriptionItem > GetSubscriptionItemAsync ( string subscriptionId , string oldPlanId )
468
477
{
469
478
var subscriptionDetails = await _stripeAdapter . SubscriptionGetAsync ( subscriptionId ) ;
470
479
return subscriptionDetails . Items . Data . FirstOrDefault ( item => item . Price . Id == oldPlanId ) ;
471
480
}
472
481
473
- private static string GetStripeSeatPlanId ( PlanType planType )
474
- {
475
- return StaticStore . GetPlan ( planType ) . PasswordManager . StripeSeatPlanId ;
476
- }
477
-
478
- private async Task UpdateSubscriptionAsync ( Stripe . SubscriptionItem subscriptionItem , string extractedPlanType , Organization organization )
482
+ private async Task UpdateSubscriptionAsync ( SubscriptionItem subscriptionItem , string extractedPlanType , Organization organization )
479
483
{
480
484
try
481
485
{
0 commit comments