mirror of
https://github.com/bitwarden/server.git
synced 2024-11-26 12:55:17 +01:00
REFACTOR
This commit is contained in:
parent
4c349ddce5
commit
4bd0c40881
@ -1,4 +1,5 @@
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -46,4 +47,15 @@ public class StripeController(
|
||||
|
||||
return TypedResults.Ok(setupIntent.ClientSecret);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("~/tax/is-country-supported")]
|
||||
public IResult IsCountrySupported(
|
||||
[FromQuery] string country,
|
||||
[FromServices] ITaxService taxService)
|
||||
{
|
||||
var isSupported = taxService.IsSupported(country);
|
||||
|
||||
return TypedResults.Ok(isSupported);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,22 @@
|
||||
using Bit.Core.Billing.Models;
|
||||
|
||||
namespace Bit.Core.Billing.Services;
|
||||
namespace Bit.Core.Billing.Services;
|
||||
|
||||
public interface ITaxService
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the Stripe tax code for a given country and tax ID.
|
||||
/// </summary>
|
||||
/// <param name="country"></param>
|
||||
/// <param name="taxId"></param>
|
||||
/// <returns>
|
||||
/// Returns the Stripe tax code if the tax ID is valid for the country.
|
||||
/// Returns null if the tax ID is invalid or the country is not supported.
|
||||
/// </returns>
|
||||
string? GetStripeTaxCode(string country, string taxId);
|
||||
|
||||
IEnumerable<TaxIdType> GetTaxIdTypes();
|
||||
/// <summary>
|
||||
/// Returns true or false whether charging or storing tax is supported for the given country.
|
||||
/// </summary>
|
||||
/// <param name="country"></param>
|
||||
/// <returns></returns>
|
||||
bool IsSupported(string country);
|
||||
}
|
||||
|
@ -881,15 +881,6 @@ public class TaxService : ITaxService
|
||||
}
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the Stripe tax code for a given country and tax ID.
|
||||
/// </summary>
|
||||
/// <param name="country"></param>
|
||||
/// <param name="taxId"></param>
|
||||
/// <returns>
|
||||
/// Returns the Stripe tax code if the tax ID is valid for the country.
|
||||
/// Returns null if the tax ID is invalid or the country is not supported.
|
||||
/// </returns>
|
||||
public string? GetStripeTaxCode(string country, string taxId)
|
||||
{
|
||||
foreach (var taxIdType in _taxIdTypes.Where(x => x.Country == country))
|
||||
@ -903,5 +894,8 @@ public class TaxService : ITaxService
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnumerable<TaxIdType> GetTaxIdTypes() => _taxIdTypes;
|
||||
public bool IsSupported(string country)
|
||||
{
|
||||
return _taxIdTypes.Any(x => x.Country == country);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user