1
0
mirror of https://github.com/bitwarden/server synced 2025-12-17 08:43:27 +00:00

[PM-18028] Attempting to enable automatic tax on customer with invalid location (#5374)

This commit is contained in:
Jonas Hendrickx
2025-02-06 16:34:22 +01:00
committed by GitHub
parent bc27ec2b9b
commit 678d5d5d63
8 changed files with 155 additions and 35 deletions

View File

@@ -0,0 +1,35 @@
using Stripe;
namespace Bit.Core.Billing.Extensions;
public static class SubscriptionUpdateOptionsExtensions
{
/// <summary>
/// Attempts to enable automatic tax for given subscription options.
/// </summary>
/// <param name="options"></param>
/// <param name="customer">The existing customer to which the subscription belongs.</param>
/// <param name="subscription">The existing subscription.</param>
/// <returns>Returns true when successful, false when conditions are not met.</returns>
public static bool EnableAutomaticTax(
this SubscriptionUpdateOptions options,
Customer customer,
Subscription subscription)
{
if (subscription.AutomaticTax.Enabled)
{
return false;
}
// We might only need to check the automatic tax status.
if (!customer.HasTaxLocationVerified() && string.IsNullOrWhiteSpace(customer.Address?.Country))
{
return false;
}
options.DefaultTaxRates = [];
options.AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = true };
return true;
}
}