1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-04 20:50:21 -05:00
This commit is contained in:
Jonas Hendrickx 2025-03-18 11:56:14 +01:00
parent cae8835e27
commit d2df65665d
9 changed files with 33 additions and 39 deletions

View File

@ -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)
{

View File

@ -1,10 +0,0 @@
using Stripe;
namespace Bit.Core.Billing.Services;
public interface IAutomaticTaxStrategy
{
Task<SubscriptionUpdateOptions> GetUpdateOptionsAsync(Subscription subscription);
Task SetCreateOptionsAsync(SubscriptionCreateOptions options, Customer customer);
Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription);
}

View File

@ -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);
}

View File

@ -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<SubscriptionUpdateOptions?> GetUpdateOptionsAsync(Subscription subscription);
Task SetCreateOptionsAsync(SubscriptionCreateOptions options, Customer customer);
Task SetUpdateOptionsAsync(SubscriptionUpdateOptions options, Subscription subscription);
}

View File

@ -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<SubscriptionUpdateOptions> 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)

View File

@ -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<SubscriptionUpdateOptions> GetUpdateOptionsAsync(Subscription subscription)
public async Task<SubscriptionUpdateOptions?> 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;

View File

@ -332,7 +332,7 @@ public class PremiumUserBillingService(
OffSession = true
};
await individualAutomaticTaxStrategy.SetCreateOptionsAsync(subscriptionCreateOptions, customer);
individualAutomaticTaxStrategy.SetCreateOptions(subscriptionCreateOptions, customer);
var subscription = await stripeAdapter.SubscriptionCreateAsync(subscriptionCreateOptions);

View File

@ -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)
{

View File

@ -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)