From 39d344f74298486ab2415bd96aaee801a51f81fa Mon Sep 17 00:00:00 2001 From: Jonas Hendrickx Date: Tue, 18 Mar 2025 14:03:08 +0100 Subject: [PATCH] doc --- .../IIndividualAutomaticTaxStrategy.cs | 8 +++++ .../IOrganizationAutomaticTaxStrategy.cs | 8 +++++ .../IndividualAutomaticTaxStrategy.cs | 10 +++--- .../OrganizationAutomaticTaxStrategy.cs | 33 +++++-------------- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs b/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs index 46f8e09224..4c2422d4fa 100644 --- a/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs @@ -5,6 +5,14 @@ namespace Bit.Core.Billing.Services; public interface IIndividualAutomaticTaxStrategy { + /// + /// + /// + /// + /// + /// Returns if changes are to be applied to the subscription, returns null + /// otherwise. + /// SubscriptionUpdateOptions? GetUpdateOptions(Subscription subscription); void SetCreateOptions(SubscriptionCreateOptions options, Customer customer); void SetUpdateOptions(SubscriptionUpdateOptions options, Subscription subscription); diff --git a/src/Core/Billing/Services/IOrganizationAutomaticTaxStrategy.cs b/src/Core/Billing/Services/IOrganizationAutomaticTaxStrategy.cs index 3b15c73a45..5f0bb55e3d 100644 --- a/src/Core/Billing/Services/IOrganizationAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/IOrganizationAutomaticTaxStrategy.cs @@ -5,6 +5,14 @@ namespace Bit.Core.Billing.Services; public interface IOrganizationAutomaticTaxStrategy { + /// + /// + /// + /// + /// + /// Returns if changes are to be applied to the subscription, returns null + /// otherwise. + /// Task GetUpdateOptionsAsync(Subscription subscription); Task SetCreateOptionsAsync(SubscriptionCreateOptions options, Customer customer); Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription); diff --git a/src/Core/Billing/Services/Implementations/AutomaticTax/IndividualAutomaticTaxStrategy.cs b/src/Core/Billing/Services/Implementations/AutomaticTax/IndividualAutomaticTaxStrategy.cs index 81b7bc2784..230cb5be1c 100644 --- a/src/Core/Billing/Services/Implementations/AutomaticTax/IndividualAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/Implementations/AutomaticTax/IndividualAutomaticTaxStrategy.cs @@ -10,7 +10,7 @@ public class IndividualAutomaticTaxStrategy : IIndividualAutomaticTaxStrategy { options.AutomaticTax = new SubscriptionAutomaticTaxOptions { - Enabled = ShouldEnable(customer) + Enabled = ShouldBeEnabled(customer) }; } @@ -18,14 +18,14 @@ public class IndividualAutomaticTaxStrategy : IIndividualAutomaticTaxStrategy { options.AutomaticTax = new SubscriptionAutomaticTaxOptions { - Enabled = ShouldEnable(subscription.Customer) + Enabled = ShouldBeEnabled(subscription.Customer) }; options.DefaultTaxRates = []; } public SubscriptionUpdateOptions? GetUpdateOptions(Subscription subscription) { - if (subscription.AutomaticTax.Enabled == ShouldEnable(subscription.Customer)) + if (subscription.AutomaticTax.Enabled == ShouldBeEnabled(subscription.Customer)) { return null; } @@ -34,7 +34,7 @@ public class IndividualAutomaticTaxStrategy : IIndividualAutomaticTaxStrategy { AutomaticTax = new SubscriptionAutomaticTaxOptions { - Enabled = ShouldEnable(subscription.Customer), + Enabled = ShouldBeEnabled(subscription.Customer), }, DefaultTaxRates = [] }; @@ -42,7 +42,7 @@ public class IndividualAutomaticTaxStrategy : IIndividualAutomaticTaxStrategy return options; } - private static bool ShouldEnable(Customer customer) + private static bool ShouldBeEnabled(Customer customer) { return customer.HasTaxLocationVerified(); } diff --git a/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs b/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs index e72f963e4b..cd7597b7ba 100644 --- a/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs @@ -20,19 +20,13 @@ public class OrganizationAutomaticTaxStrategy( public async Task GetUpdateOptionsAsync(Subscription subscription) { - ArgumentNullException.ThrowIfNull(subscription); - - var isEnabled = await IsEnabledAsync(subscription); - if (!isEnabled.HasValue) - { - return null; - } + var shouldBeEnabled = await ShouldBeEnabledAsync(subscription); var options = new SubscriptionUpdateOptions { AutomaticTax = new SubscriptionAutomaticTaxOptions { - Enabled = isEnabled.Value + Enabled = shouldBeEnabled }, DefaultTaxRates = [] }; @@ -44,31 +38,27 @@ public class OrganizationAutomaticTaxStrategy( { options.AutomaticTax = new SubscriptionAutomaticTaxOptions { - Enabled = await IsEnabledAsync(options, customer) + Enabled = await ShouldBeEnabledAsync(options, customer) }; } public async Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription) { - if (subscription.AutomaticTax.Enabled == options.AutomaticTax?.Enabled) - { - return; - } + var shouldBeEnabled = await ShouldBeEnabledAsync(subscription); - var isEnabled = await IsEnabledAsync(subscription); - if (!isEnabled.HasValue) + if (subscription.AutomaticTax.Enabled == shouldBeEnabled) { return; } options.AutomaticTax = new SubscriptionAutomaticTaxOptions { - Enabled = isEnabled.Value + Enabled = shouldBeEnabled }; options.DefaultTaxRates = []; } - private async Task IsEnabledAsync(Subscription subscription) + private async Task ShouldBeEnabledAsync(Subscription subscription) { if (!subscription.Customer.HasTaxLocationVerified()) { @@ -86,15 +76,10 @@ public class OrganizationAutomaticTaxStrategy( shouldBeEnabled = subscription.Items.Select(item => item.Price.Id).Intersect(familyPriceIds).Any(); } - if (subscription.AutomaticTax.Enabled != shouldBeEnabled) - { - return shouldBeEnabled; - } - - return null; + return shouldBeEnabled; } - private async Task IsEnabledAsync(SubscriptionCreateOptions options, Customer customer) + private async Task ShouldBeEnabledAsync(SubscriptionCreateOptions options, Customer customer) { if (!customer.HasTaxLocationVerified()) {