From d7c544a116f549a74d019eb9d5e0b0d3a06d9fc7 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Mon, 23 Oct 2023 11:28:13 +0100 Subject: [PATCH] [AC 1536] Breakdown The SubscriptionUpdate.cs into multiple files (#3356) * Move sub-subscription classes to a separate files * Refactor the sub-class to a separate files * format whitespace * remove directive that is unnecessary * Remove the baseSeat class --- .../Models/Business/SeatSubscriptionUpdate.cs | 49 +++ .../Business/SecretsManagerSubscribeUpdate.cs | 78 +++++ .../ServiceAccountSubscriptionUpdate.cs | 50 +++ .../Business/SmSeatSubscriptionUpdate.cs | 50 +++ .../SponsorOrganizationSubscriptionUpdate.cs | 83 +++++ .../Business/StorageSubscriptionUpdate.cs | 53 +++ .../Models/Business/SubscriptionUpdate.cs | 321 +----------------- ...UpdateSecretsManagerSubscriptionCommand.cs | 2 +- src/Core/Services/IPaymentService.cs | 1 + .../Implementations/StripePaymentService.cs | 5 + ...eSecretsManagerSubscriptionCommandTests.cs | 6 +- 11 files changed, 374 insertions(+), 324 deletions(-) create mode 100644 src/Core/Models/Business/SeatSubscriptionUpdate.cs create mode 100644 src/Core/Models/Business/SecretsManagerSubscribeUpdate.cs create mode 100644 src/Core/Models/Business/ServiceAccountSubscriptionUpdate.cs create mode 100644 src/Core/Models/Business/SmSeatSubscriptionUpdate.cs create mode 100644 src/Core/Models/Business/SponsorOrganizationSubscriptionUpdate.cs create mode 100644 src/Core/Models/Business/StorageSubscriptionUpdate.cs diff --git a/src/Core/Models/Business/SeatSubscriptionUpdate.cs b/src/Core/Models/Business/SeatSubscriptionUpdate.cs new file mode 100644 index 000000000..8b4c613d6 --- /dev/null +++ b/src/Core/Models/Business/SeatSubscriptionUpdate.cs @@ -0,0 +1,49 @@ +using Bit.Core.Entities; +using Stripe; + +namespace Bit.Core.Models.Business; + +public class SeatSubscriptionUpdate : SubscriptionUpdate +{ + private readonly int _previousSeats; + private readonly StaticStore.Plan _plan; + private readonly long? _additionalSeats; + protected override List PlanIds => new() { _plan.PasswordManager.StripeSeatPlanId }; + public SeatSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats) + { + _plan = plan; + _additionalSeats = additionalSeats; + _previousSeats = organization.Seats.GetValueOrDefault(); + } + + public override List UpgradeItemsOptions(Subscription subscription) + { + var item = SubscriptionItem(subscription, PlanIds.Single()); + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = PlanIds.Single(), + Quantity = _additionalSeats, + Deleted = (item?.Id != null && _additionalSeats == 0) ? true : (bool?)null, + } + }; + } + + public override List RevertItemsOptions(Subscription subscription) + { + + var item = SubscriptionItem(subscription, PlanIds.Single()); + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = PlanIds.Single(), + Quantity = _previousSeats, + Deleted = _previousSeats == 0 ? true : (bool?)null, + } + }; + } +} diff --git a/src/Core/Models/Business/SecretsManagerSubscribeUpdate.cs b/src/Core/Models/Business/SecretsManagerSubscribeUpdate.cs new file mode 100644 index 000000000..8f3fb8934 --- /dev/null +++ b/src/Core/Models/Business/SecretsManagerSubscribeUpdate.cs @@ -0,0 +1,78 @@ +using Bit.Core.Entities; +using Stripe; + +namespace Bit.Core.Models.Business; + +public class SecretsManagerSubscribeUpdate : SubscriptionUpdate +{ + private readonly StaticStore.Plan _plan; + private readonly long? _additionalSeats; + private readonly long? _additionalServiceAccounts; + private readonly int _previousSeats; + private readonly int _previousServiceAccounts; + protected override List PlanIds => new() { _plan.SecretsManager.StripeSeatPlanId, _plan.SecretsManager.StripeServiceAccountPlanId }; + public SecretsManagerSubscribeUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats, long? additionalServiceAccounts) + { + _plan = plan; + _additionalSeats = additionalSeats; + _additionalServiceAccounts = additionalServiceAccounts; + _previousSeats = organization.SmSeats.GetValueOrDefault(); + _previousServiceAccounts = organization.SmServiceAccounts.GetValueOrDefault(); + } + + public override List RevertItemsOptions(Subscription subscription) + { + var updatedItems = new List(); + + RemovePreviousSecretsManagerItems(updatedItems); + + return updatedItems; + } + + public override List UpgradeItemsOptions(Subscription subscription) + { + var updatedItems = new List(); + + AddNewSecretsManagerItems(updatedItems); + + return updatedItems; + } + + private void AddNewSecretsManagerItems(List updatedItems) + { + if (_additionalSeats > 0) + { + updatedItems.Add(new SubscriptionItemOptions + { + Price = _plan.SecretsManager.StripeSeatPlanId, + Quantity = _additionalSeats + }); + } + + if (_additionalServiceAccounts > 0) + { + updatedItems.Add(new SubscriptionItemOptions + { + Price = _plan.SecretsManager.StripeServiceAccountPlanId, + Quantity = _additionalServiceAccounts + }); + } + } + + private void RemovePreviousSecretsManagerItems(List updatedItems) + { + updatedItems.Add(new SubscriptionItemOptions + { + Price = _plan.SecretsManager.StripeSeatPlanId, + Quantity = _previousSeats, + Deleted = _previousSeats == 0 ? true : (bool?)null, + }); + + updatedItems.Add(new SubscriptionItemOptions + { + Price = _plan.SecretsManager.StripeServiceAccountPlanId, + Quantity = _previousServiceAccounts, + Deleted = _previousServiceAccounts == 0 ? true : (bool?)null, + }); + } +} diff --git a/src/Core/Models/Business/ServiceAccountSubscriptionUpdate.cs b/src/Core/Models/Business/ServiceAccountSubscriptionUpdate.cs new file mode 100644 index 000000000..b49c9cd6c --- /dev/null +++ b/src/Core/Models/Business/ServiceAccountSubscriptionUpdate.cs @@ -0,0 +1,50 @@ +using Bit.Core.Entities; +using Stripe; + +namespace Bit.Core.Models.Business; + +public class ServiceAccountSubscriptionUpdate : SubscriptionUpdate +{ + private long? _prevServiceAccounts; + private readonly StaticStore.Plan _plan; + private readonly long? _additionalServiceAccounts; + protected override List PlanIds => new() { _plan.SecretsManager.StripeServiceAccountPlanId }; + + public ServiceAccountSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalServiceAccounts) + { + _plan = plan; + _additionalServiceAccounts = additionalServiceAccounts; + _prevServiceAccounts = organization.SmServiceAccounts ?? 0; + } + + public override List UpgradeItemsOptions(Subscription subscription) + { + var item = SubscriptionItem(subscription, PlanIds.Single()); + _prevServiceAccounts = item?.Quantity ?? 0; + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = PlanIds.Single(), + Quantity = _additionalServiceAccounts, + Deleted = (item?.Id != null && _additionalServiceAccounts == 0) ? true : (bool?)null, + } + }; + } + + public override List RevertItemsOptions(Subscription subscription) + { + var item = SubscriptionItem(subscription, PlanIds.Single()); + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = PlanIds.Single(), + Quantity = _prevServiceAccounts, + Deleted = _prevServiceAccounts == 0 ? true : (bool?)null, + } + }; + } +} diff --git a/src/Core/Models/Business/SmSeatSubscriptionUpdate.cs b/src/Core/Models/Business/SmSeatSubscriptionUpdate.cs new file mode 100644 index 000000000..ddc126a26 --- /dev/null +++ b/src/Core/Models/Business/SmSeatSubscriptionUpdate.cs @@ -0,0 +1,50 @@ +using Bit.Core.Entities; +using Stripe; + +namespace Bit.Core.Models.Business; + +public class SmSeatSubscriptionUpdate : SubscriptionUpdate +{ + private readonly int _previousSeats; + private readonly StaticStore.Plan _plan; + private readonly long? _additionalSeats; + protected override List PlanIds => new() { _plan.SecretsManager.StripeSeatPlanId }; + + public SmSeatSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats) + { + _plan = plan; + _additionalSeats = additionalSeats; + _previousSeats = organization.SmSeats.GetValueOrDefault(); + } + + public override List UpgradeItemsOptions(Subscription subscription) + { + var item = SubscriptionItem(subscription, PlanIds.Single()); + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = PlanIds.Single(), + Quantity = _additionalSeats, + Deleted = (item?.Id != null && _additionalSeats == 0) ? true : (bool?)null, + } + }; + } + + public override List RevertItemsOptions(Subscription subscription) + { + + var item = SubscriptionItem(subscription, PlanIds.Single()); + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = PlanIds.Single(), + Quantity = _previousSeats, + Deleted = _previousSeats == 0 ? true : (bool?)null, + } + }; + } +} diff --git a/src/Core/Models/Business/SponsorOrganizationSubscriptionUpdate.cs b/src/Core/Models/Business/SponsorOrganizationSubscriptionUpdate.cs new file mode 100644 index 000000000..88af72f19 --- /dev/null +++ b/src/Core/Models/Business/SponsorOrganizationSubscriptionUpdate.cs @@ -0,0 +1,83 @@ +using Stripe; + +namespace Bit.Core.Models.Business; + +public class SponsorOrganizationSubscriptionUpdate : SubscriptionUpdate +{ + private readonly string _existingPlanStripeId; + private readonly string _sponsoredPlanStripeId; + private readonly bool _applySponsorship; + protected override List PlanIds => new() { _existingPlanStripeId, _sponsoredPlanStripeId }; + + public SponsorOrganizationSubscriptionUpdate(StaticStore.Plan existingPlan, StaticStore.SponsoredPlan sponsoredPlan, bool applySponsorship) + { + _existingPlanStripeId = existingPlan.PasswordManager.StripePlanId; + _sponsoredPlanStripeId = sponsoredPlan?.StripePlanId; + _applySponsorship = applySponsorship; + } + + public override List RevertItemsOptions(Subscription subscription) + { + var result = new List(); + if (!string.IsNullOrWhiteSpace(AddStripePlanId)) + { + result.Add(new SubscriptionItemOptions + { + Id = AddStripeItem(subscription)?.Id, + Plan = AddStripePlanId, + Quantity = 0, + Deleted = true, + }); + } + + if (!string.IsNullOrWhiteSpace(RemoveStripePlanId)) + { + result.Add(new SubscriptionItemOptions + { + Id = RemoveStripeItem(subscription)?.Id, + Plan = RemoveStripePlanId, + Quantity = 1, + Deleted = false, + }); + } + return result; + } + + public override List UpgradeItemsOptions(Subscription subscription) + { + var result = new List(); + if (RemoveStripeItem(subscription) != null) + { + result.Add(new SubscriptionItemOptions + { + Id = RemoveStripeItem(subscription)?.Id, + Plan = RemoveStripePlanId, + Quantity = 0, + Deleted = true, + }); + } + + if (!string.IsNullOrWhiteSpace(AddStripePlanId)) + { + result.Add(new SubscriptionItemOptions + { + Id = AddStripeItem(subscription)?.Id, + Plan = AddStripePlanId, + Quantity = 1, + Deleted = false, + }); + } + return result; + } + + private string RemoveStripePlanId => _applySponsorship ? _existingPlanStripeId : _sponsoredPlanStripeId; + private string AddStripePlanId => _applySponsorship ? _sponsoredPlanStripeId : _existingPlanStripeId; + private Stripe.SubscriptionItem RemoveStripeItem(Subscription subscription) => + _applySponsorship ? + SubscriptionItem(subscription, _existingPlanStripeId) : + SubscriptionItem(subscription, _sponsoredPlanStripeId); + private Stripe.SubscriptionItem AddStripeItem(Subscription subscription) => + _applySponsorship ? + SubscriptionItem(subscription, _sponsoredPlanStripeId) : + SubscriptionItem(subscription, _existingPlanStripeId); +} diff --git a/src/Core/Models/Business/StorageSubscriptionUpdate.cs b/src/Core/Models/Business/StorageSubscriptionUpdate.cs new file mode 100644 index 000000000..30ab2428e --- /dev/null +++ b/src/Core/Models/Business/StorageSubscriptionUpdate.cs @@ -0,0 +1,53 @@ +using Stripe; + +namespace Bit.Core.Models.Business; + +public class StorageSubscriptionUpdate : SubscriptionUpdate +{ + private long? _prevStorage; + private readonly string _plan; + private readonly long? _additionalStorage; + protected override List PlanIds => new() { _plan }; + + public StorageSubscriptionUpdate(string plan, long? additionalStorage) + { + _plan = plan; + _additionalStorage = additionalStorage; + } + + public override List UpgradeItemsOptions(Subscription subscription) + { + var item = SubscriptionItem(subscription, PlanIds.Single()); + _prevStorage = item?.Quantity ?? 0; + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = _plan, + Quantity = _additionalStorage, + Deleted = (item?.Id != null && _additionalStorage == 0) ? true : (bool?)null, + } + }; + } + + public override List RevertItemsOptions(Subscription subscription) + { + if (!_prevStorage.HasValue) + { + throw new Exception("Unknown previous value, must first call UpgradeItemsOptions"); + } + + var item = SubscriptionItem(subscription, PlanIds.Single()); + return new() + { + new SubscriptionItemOptions + { + Id = item?.Id, + Plan = _plan, + Quantity = _prevStorage.Value, + Deleted = _prevStorage.Value == 0 ? true : (bool?)null, + } + }; + } +} diff --git a/src/Core/Models/Business/SubscriptionUpdate.cs b/src/Core/Models/Business/SubscriptionUpdate.cs index 0dcf696db..497a455d6 100644 --- a/src/Core/Models/Business/SubscriptionUpdate.cs +++ b/src/Core/Models/Business/SubscriptionUpdate.cs @@ -1,5 +1,4 @@ -using Bit.Core.Entities; -using Stripe; +using Stripe; namespace Bit.Core.Models.Business; @@ -28,321 +27,3 @@ public abstract class SubscriptionUpdate protected static SubscriptionItem SubscriptionItem(Subscription subscription, string planId) => planId == null ? null : subscription.Items?.Data?.FirstOrDefault(i => i.Plan.Id == planId); } - -public abstract class BaseSeatSubscriptionUpdate : SubscriptionUpdate -{ - private readonly int _previousSeats; - protected readonly StaticStore.Plan Plan; - private readonly long? _additionalSeats; - - protected BaseSeatSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats, int previousSeats) - { - Plan = plan; - _additionalSeats = additionalSeats; - _previousSeats = previousSeats; - } - - protected abstract string GetPlanId(); - - protected override List PlanIds => new() { GetPlanId() }; - - public override List UpgradeItemsOptions(Subscription subscription) - { - var item = SubscriptionItem(subscription, PlanIds.Single()); - return new() - { - new SubscriptionItemOptions - { - Id = item?.Id, - Plan = PlanIds.Single(), - Quantity = _additionalSeats, - Deleted = (item?.Id != null && _additionalSeats == 0) ? true : (bool?)null, - } - }; - } - - public override List RevertItemsOptions(Subscription subscription) - { - - var item = SubscriptionItem(subscription, PlanIds.Single()); - return new() - { - new SubscriptionItemOptions - { - Id = item?.Id, - Plan = PlanIds.Single(), - Quantity = _previousSeats, - Deleted = _previousSeats == 0 ? true : (bool?)null, - } - }; - } -} - -public class SeatSubscriptionUpdate : BaseSeatSubscriptionUpdate -{ - public SeatSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats) - : base(organization, plan, additionalSeats, organization.Seats.GetValueOrDefault()) - { } - - protected override string GetPlanId() => Plan.PasswordManager.StripeSeatPlanId; -} - -public class SmSeatSubscriptionUpdate : BaseSeatSubscriptionUpdate -{ - public SmSeatSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats) - : base(organization, plan, additionalSeats, organization.SmSeats.GetValueOrDefault()) - { } - - protected override string GetPlanId() => Plan.SecretsManager.StripeSeatPlanId; -} - -public class ServiceAccountSubscriptionUpdate : SubscriptionUpdate -{ - private long? _prevServiceAccounts; - private readonly StaticStore.Plan _plan; - private readonly long? _additionalServiceAccounts; - protected override List PlanIds => new() { _plan.SecretsManager.StripeServiceAccountPlanId }; - - public ServiceAccountSubscriptionUpdate(Organization organization, StaticStore.Plan plan, long? additionalServiceAccounts) - { - _plan = plan; - _additionalServiceAccounts = additionalServiceAccounts; - _prevServiceAccounts = organization.SmServiceAccounts ?? 0; - } - - public override List UpgradeItemsOptions(Subscription subscription) - { - var item = SubscriptionItem(subscription, PlanIds.Single()); - _prevServiceAccounts = item?.Quantity ?? 0; - return new() - { - new SubscriptionItemOptions - { - Id = item?.Id, - Plan = PlanIds.Single(), - Quantity = _additionalServiceAccounts, - Deleted = (item?.Id != null && _additionalServiceAccounts == 0) ? true : (bool?)null, - } - }; - } - - public override List RevertItemsOptions(Subscription subscription) - { - var item = SubscriptionItem(subscription, PlanIds.Single()); - return new() - { - new SubscriptionItemOptions - { - Id = item?.Id, - Plan = PlanIds.Single(), - Quantity = _prevServiceAccounts, - Deleted = _prevServiceAccounts == 0 ? true : (bool?)null, - } - }; - } -} - -public class StorageSubscriptionUpdate : SubscriptionUpdate -{ - private long? _prevStorage; - private readonly string _plan; - private readonly long? _additionalStorage; - protected override List PlanIds => new() { _plan }; - - public StorageSubscriptionUpdate(string plan, long? additionalStorage) - { - _plan = plan; - _additionalStorage = additionalStorage; - } - - public override List UpgradeItemsOptions(Subscription subscription) - { - var item = SubscriptionItem(subscription, PlanIds.Single()); - _prevStorage = item?.Quantity ?? 0; - return new() - { - new SubscriptionItemOptions - { - Id = item?.Id, - Plan = _plan, - Quantity = _additionalStorage, - Deleted = (item?.Id != null && _additionalStorage == 0) ? true : (bool?)null, - } - }; - } - - public override List RevertItemsOptions(Subscription subscription) - { - if (!_prevStorage.HasValue) - { - throw new Exception("Unknown previous value, must first call UpgradeItemsOptions"); - } - - var item = SubscriptionItem(subscription, PlanIds.Single()); - return new() - { - new SubscriptionItemOptions - { - Id = item?.Id, - Plan = _plan, - Quantity = _prevStorage.Value, - Deleted = _prevStorage.Value == 0 ? true : (bool?)null, - } - }; - } -} - -public class SponsorOrganizationSubscriptionUpdate : SubscriptionUpdate -{ - private readonly string _existingPlanStripeId; - private readonly string _sponsoredPlanStripeId; - private readonly bool _applySponsorship; - protected override List PlanIds => new() { _existingPlanStripeId, _sponsoredPlanStripeId }; - - public SponsorOrganizationSubscriptionUpdate(StaticStore.Plan existingPlan, StaticStore.SponsoredPlan sponsoredPlan, bool applySponsorship) - { - _existingPlanStripeId = existingPlan.PasswordManager.StripePlanId; - _sponsoredPlanStripeId = sponsoredPlan?.StripePlanId; - _applySponsorship = applySponsorship; - } - - public override List RevertItemsOptions(Subscription subscription) - { - var result = new List(); - if (!string.IsNullOrWhiteSpace(AddStripePlanId)) - { - result.Add(new SubscriptionItemOptions - { - Id = AddStripeItem(subscription)?.Id, - Plan = AddStripePlanId, - Quantity = 0, - Deleted = true, - }); - } - - if (!string.IsNullOrWhiteSpace(RemoveStripePlanId)) - { - result.Add(new SubscriptionItemOptions - { - Id = RemoveStripeItem(subscription)?.Id, - Plan = RemoveStripePlanId, - Quantity = 1, - Deleted = false, - }); - } - return result; - } - - public override List UpgradeItemsOptions(Subscription subscription) - { - var result = new List(); - if (RemoveStripeItem(subscription) != null) - { - result.Add(new SubscriptionItemOptions - { - Id = RemoveStripeItem(subscription)?.Id, - Plan = RemoveStripePlanId, - Quantity = 0, - Deleted = true, - }); - } - - if (!string.IsNullOrWhiteSpace(AddStripePlanId)) - { - result.Add(new SubscriptionItemOptions - { - Id = AddStripeItem(subscription)?.Id, - Plan = AddStripePlanId, - Quantity = 1, - Deleted = false, - }); - } - return result; - } - - private string RemoveStripePlanId => _applySponsorship ? _existingPlanStripeId : _sponsoredPlanStripeId; - private string AddStripePlanId => _applySponsorship ? _sponsoredPlanStripeId : _existingPlanStripeId; - private Stripe.SubscriptionItem RemoveStripeItem(Subscription subscription) => - _applySponsorship ? - SubscriptionItem(subscription, _existingPlanStripeId) : - SubscriptionItem(subscription, _sponsoredPlanStripeId); - private Stripe.SubscriptionItem AddStripeItem(Subscription subscription) => - _applySponsorship ? - SubscriptionItem(subscription, _sponsoredPlanStripeId) : - SubscriptionItem(subscription, _existingPlanStripeId); - -} - -public class SecretsManagerSubscribeUpdate : SubscriptionUpdate -{ - private readonly StaticStore.Plan _plan; - private readonly long? _additionalSeats; - private readonly long? _additionalServiceAccounts; - private readonly int _previousSeats; - private readonly int _previousServiceAccounts; - protected override List PlanIds => new() { _plan.SecretsManager.StripeSeatPlanId, _plan.SecretsManager.StripeServiceAccountPlanId }; - public SecretsManagerSubscribeUpdate(Organization organization, StaticStore.Plan plan, long? additionalSeats, long? additionalServiceAccounts) - { - _plan = plan; - _additionalSeats = additionalSeats; - _additionalServiceAccounts = additionalServiceAccounts; - _previousSeats = organization.SmSeats.GetValueOrDefault(); - _previousServiceAccounts = organization.SmServiceAccounts.GetValueOrDefault(); - } - - public override List RevertItemsOptions(Subscription subscription) - { - var updatedItems = new List(); - - RemovePreviousSecretsManagerItems(updatedItems); - - return updatedItems; - } - - public override List UpgradeItemsOptions(Subscription subscription) - { - var updatedItems = new List(); - - AddNewSecretsManagerItems(updatedItems); - - return updatedItems; - } - - private void AddNewSecretsManagerItems(List updatedItems) - { - if (_additionalSeats > 0) - { - updatedItems.Add(new SubscriptionItemOptions - { - Price = _plan.SecretsManager.StripeSeatPlanId, - Quantity = _additionalSeats - }); - } - - if (_additionalServiceAccounts > 0) - { - updatedItems.Add(new SubscriptionItemOptions - { - Price = _plan.SecretsManager.StripeServiceAccountPlanId, - Quantity = _additionalServiceAccounts - }); - } - } - - private void RemovePreviousSecretsManagerItems(List updatedItems) - { - updatedItems.Add(new SubscriptionItemOptions - { - Price = _plan.SecretsManager.StripeSeatPlanId, - Quantity = _previousSeats, - Deleted = _previousSeats == 0 ? true : (bool?)null, - }); - - updatedItems.Add(new SubscriptionItemOptions - { - Price = _plan.SecretsManager.StripeServiceAccountPlanId, - Quantity = _previousServiceAccounts, - Deleted = _previousServiceAccounts == 0 ? true : (bool?)null, - }); - } -} diff --git a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs index aeaac974d..30ccbe578 100644 --- a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs +++ b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs @@ -66,7 +66,7 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs { if (update.SmSeatsChanged) { - await _paymentService.AdjustSeatsAsync(update.Organization, update.Plan, update.SmSeatsExcludingBase, update.ProrationDate); + await _paymentService.AdjustSmSeatsAsync(update.Organization, update.Plan, update.SmSeatsExcludingBase, update.ProrationDate); // TODO: call ReferenceEventService - see AC-1481 } diff --git a/src/Core/Services/IPaymentService.cs b/src/Core/Services/IPaymentService.cs index 03c2e93dd..82386a1cf 100644 --- a/src/Core/Services/IPaymentService.cs +++ b/src/Core/Services/IPaymentService.cs @@ -18,6 +18,7 @@ public interface IPaymentService Task PurchasePremiumAsync(User user, PaymentMethodType paymentMethodType, string paymentToken, short additionalStorageGb, TaxInfo taxInfo); Task AdjustSeatsAsync(Organization organization, Plan plan, int additionalSeats, DateTime? prorationDate = null); + Task AdjustSmSeatsAsync(Organization organization, Plan plan, int additionalSeats, DateTime? prorationDate = null); Task AdjustStorageAsync(IStorableSubscriber storableSubscriber, int additionalStorage, string storagePlanId, DateTime? prorationDate = null); Task AdjustServiceAccountsAsync(Organization organization, Plan plan, int additionalServiceAccounts, diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index e1ac1ef77..dc6d4dd6f 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -863,6 +863,11 @@ public class StripePaymentService : IPaymentService return FinalizeSubscriptionChangeAsync(organization, new SeatSubscriptionUpdate(organization, plan, additionalSeats), prorationDate); } + public Task AdjustSmSeatsAsync(Organization organization, StaticStore.Plan plan, int additionalSeats, DateTime? prorationDate = null) + { + return FinalizeSubscriptionChangeAsync(organization, new SmSeatSubscriptionUpdate(organization, plan, additionalSeats), prorationDate); + } + public Task AdjustServiceAccountsAsync(Organization organization, StaticStore.Plan plan, int additionalServiceAccounts, DateTime? prorationDate = null) { return FinalizeSubscriptionChangeAsync(organization, new ServiceAccountSubscriptionUpdate(organization, plan, additionalServiceAccounts), prorationDate); diff --git a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs index 5a689f39b..16508bd25 100644 --- a/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs +++ b/test/Core.Test/OrganizationFeatures/OrganizationSubscriptionUpdate/UpdateSecretsManagerSubscriptionCommandTests.cs @@ -54,7 +54,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests var plan = StaticStore.GetPlan(organization.PlanType); await sutProvider.GetDependency().Received(1) - .AdjustSeatsAsync(organization, plan, update.SmSeatsExcludingBase); + .AdjustSmSeatsAsync(organization, plan, update.SmSeatsExcludingBase); await sutProvider.GetDependency().Received(1) .AdjustServiceAccountsAsync(organization, plan, update.SmServiceAccountsExcludingBase); @@ -98,7 +98,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests var plan = StaticStore.GetPlan(organization.PlanType); await sutProvider.GetDependency().Received(1) - .AdjustSeatsAsync(organization, plan, update.SmSeatsExcludingBase); + .AdjustSmSeatsAsync(organization, plan, update.SmSeatsExcludingBase); await sutProvider.GetDependency().Received(1) .AdjustServiceAccountsAsync(organization, plan, update.SmServiceAccountsExcludingBase); @@ -599,7 +599,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests private static async Task VerifyDependencyNotCalledAsync(SutProvider sutProvider) { await sutProvider.GetDependency().DidNotReceive() - .AdjustSeatsAsync(Arg.Any(), Arg.Any(), Arg.Any()); + .AdjustSmSeatsAsync(Arg.Any(), Arg.Any(), Arg.Any()); await sutProvider.GetDependency().DidNotReceive() .AdjustServiceAccountsAsync(Arg.Any(), Arg.Any(), Arg.Any()); // TODO: call ReferenceEventService - see AC-1481