diff --git a/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs b/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs index 13e4a3fb9e..d91454af23 100644 --- a/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs +++ b/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs @@ -139,7 +139,7 @@ public class UpcomingInvoiceHandler( { var updateOptions = subscription.IsOrganization() ? await organizationAutomaticTaxStrategy.GetUpdateOptionsAsync(subscription) - : await individualAutomaticTaxStrategy.GetUpdateOptionsAsync(subscription); + : individualAutomaticTaxStrategy.GetUpdateOptions(subscription); if (updateOptions == null) { diff --git a/src/Core/Billing/Services/IAutomaticTaxStrategy.cs b/src/Core/Billing/Services/IAutomaticTaxStrategy.cs deleted file mode 100644 index 628e241d8f..0000000000 --- a/src/Core/Billing/Services/IAutomaticTaxStrategy.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Stripe; - -namespace Bit.Core.Billing.Services; - -public interface IAutomaticTaxStrategy -{ - Task GetUpdateOptionsAsync(Subscription subscription); - Task SetCreateOptionsAsync(SubscriptionCreateOptions options, Customer customer); - Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription); -} diff --git a/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs b/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs index 8e6f7d7bec..46f8e09224 100644 --- a/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/IIndividualAutomaticTaxStrategy.cs @@ -1,3 +1,11 @@ -namespace Bit.Core.Billing.Services; +#nullable enable +using Stripe; -public interface IIndividualAutomaticTaxStrategy : IAutomaticTaxStrategy; +namespace Bit.Core.Billing.Services; + +public interface IIndividualAutomaticTaxStrategy +{ + 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 eef418a2d7..3b15c73a45 100644 --- a/src/Core/Billing/Services/IOrganizationAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/IOrganizationAutomaticTaxStrategy.cs @@ -1,3 +1,11 @@ -namespace Bit.Core.Billing.Services; +#nullable enable +using Stripe; -public interface IOrganizationAutomaticTaxStrategy : IAutomaticTaxStrategy; +namespace Bit.Core.Billing.Services; + +public interface IOrganizationAutomaticTaxStrategy +{ + 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 6e3a69cadb..81b7bc2784 100644 --- a/src/Core/Billing/Services/Implementations/AutomaticTax/IndividualAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/Implementations/AutomaticTax/IndividualAutomaticTaxStrategy.cs @@ -1,37 +1,29 @@ -using Bit.Core.Billing.Extensions; +#nullable enable +using Bit.Core.Billing.Extensions; using Stripe; namespace Bit.Core.Billing.Services.Implementations.AutomaticTax; public class IndividualAutomaticTaxStrategy : IIndividualAutomaticTaxStrategy { - public Task SetCreateOptionsAsync(SubscriptionCreateOptions options, Customer customer) + public void SetCreateOptions(SubscriptionCreateOptions options, Customer customer) { - ArgumentNullException.ThrowIfNull(options); - ArgumentNullException.ThrowIfNull(customer); - options.AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = ShouldEnable(customer) }; - - return Task.CompletedTask; } - public Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription) + public void SetUpdateOptions(SubscriptionUpdateOptions options, Subscription subscription) { - ArgumentNullException.ThrowIfNull(options); - options.AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = ShouldEnable(subscription.Customer) }; options.DefaultTaxRates = []; - - return Task.CompletedTask; } - public Task GetUpdateOptionsAsync(Subscription subscription) + public SubscriptionUpdateOptions? GetUpdateOptions(Subscription subscription) { if (subscription.AutomaticTax.Enabled == ShouldEnable(subscription.Customer)) { @@ -47,7 +39,7 @@ public class IndividualAutomaticTaxStrategy : IIndividualAutomaticTaxStrategy DefaultTaxRates = [] }; - return Task.FromResult(options); + return options; } private static bool ShouldEnable(Customer customer) diff --git a/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs b/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs index a07dfd5653..e72f963e4b 100644 --- a/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs +++ b/src/Core/Billing/Services/Implementations/AutomaticTax/OrganizationAutomaticTaxStrategy.cs @@ -1,4 +1,5 @@ -using Bit.Core.Billing.Enums; +#nullable enable +using Bit.Core.Billing.Enums; using Bit.Core.Billing.Extensions; using Bit.Core.Billing.Pricing; using Stripe; @@ -17,7 +18,7 @@ public class OrganizationAutomaticTaxStrategy( return plans.Select(plan => plan.PasswordManager.StripePlanId); }); - public async Task GetUpdateOptionsAsync(Subscription subscription) + public async Task GetUpdateOptionsAsync(Subscription subscription) { ArgumentNullException.ThrowIfNull(subscription); @@ -41,9 +42,6 @@ public class OrganizationAutomaticTaxStrategy( public async Task SetCreateOptionsAsync(SubscriptionCreateOptions options, Customer customer) { - ArgumentNullException.ThrowIfNull(options); - ArgumentNullException.ThrowIfNull(customer); - options.AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = await IsEnabledAsync(options, customer) @@ -52,8 +50,6 @@ public class OrganizationAutomaticTaxStrategy( public async Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription) { - ArgumentNullException.ThrowIfNull(subscription); - if (subscription.AutomaticTax.Enabled == options.AutomaticTax?.Enabled) { return; diff --git a/src/Core/Billing/Services/Implementations/PremiumUserBillingService.cs b/src/Core/Billing/Services/Implementations/PremiumUserBillingService.cs index ff9bbaaca5..3aeeec4ce7 100644 --- a/src/Core/Billing/Services/Implementations/PremiumUserBillingService.cs +++ b/src/Core/Billing/Services/Implementations/PremiumUserBillingService.cs @@ -332,7 +332,7 @@ public class PremiumUserBillingService( OffSession = true }; - await individualAutomaticTaxStrategy.SetCreateOptionsAsync(subscriptionCreateOptions, customer); + individualAutomaticTaxStrategy.SetCreateOptions(subscriptionCreateOptions, customer); var subscription = await stripeAdapter.SubscriptionCreateAsync(subscriptionCreateOptions); diff --git a/src/Core/Billing/Services/Implementations/SubscriberService.cs b/src/Core/Billing/Services/Implementations/SubscriberService.cs index 451f0df438..2031fad17f 100644 --- a/src/Core/Billing/Services/Implementations/SubscriberService.cs +++ b/src/Core/Billing/Services/Implementations/SubscriberService.cs @@ -667,7 +667,7 @@ public class SubscriberService( { var subscription = await stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId); var automaticTaxOptions = subscriber.IsUser() - ? await individualAutomaticTaxStrategy.GetUpdateOptionsAsync(subscription) + ? individualAutomaticTaxStrategy.GetUpdateOptions(subscription) : await organizationAutomaticTaxStrategy.GetUpdateOptionsAsync(subscription); if (automaticTaxOptions?.AutomaticTax?.Enabled != null) { diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 3b36c693cb..f4bacca8a7 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -823,7 +823,7 @@ public class StripePaymentService : IPaymentService var subscription = await _stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId); var subscriptionUpdateOptions = subscriber is User - ? await _individualAutomaticTaxStrategy.GetUpdateOptionsAsync(subscription) + ? _individualAutomaticTaxStrategy.GetUpdateOptions(subscription) : await _organizationAutomaticTaxStrategy.GetUpdateOptionsAsync(subscription); if (subscriptionUpdateOptions != null)