diff --git a/src/Api/Billing/Controllers/StripeController.cs b/src/Api/Billing/Controllers/StripeController.cs index a4a974bb9..5e4d0ea87 100644 --- a/src/Api/Billing/Controllers/StripeController.cs +++ b/src/Api/Billing/Controllers/StripeController.cs @@ -1,4 +1,6 @@ -using Bit.Core.Services; +using Bit.Api.Billing.Models.Requests; +using Bit.Api.Billing.Models.Responses; +using Bit.Core.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; @@ -46,4 +48,42 @@ public class StripeController( return TypedResults.Ok(setupIntent.ClientSecret); } + + [HttpPost] + [Route("~/tax/calculate")] + public async Task CalculateAsync([FromBody] CalculateTaxRequestModel requestBody) + { + var options = new Stripe.Tax.CalculationCreateOptions + { + Currency = "usd", + CustomerDetails = new() + { + Address = new() + { + PostalCode = requestBody.PostalCode, + Country = requestBody.Country + }, + AddressSource = "billing" + }, + LineItems = new() + { + new() + { + Amount = Convert.ToInt64(requestBody.Amount * 100), + Reference = "Subscription", + }, + } + }; + var taxCalculation = await stripeAdapter.CalculateTaxAsync(options); + var response = new CalculateTaxResponseModel + { + SalesTaxRate = taxCalculation.TaxBreakdown.Any() + ? decimal.Parse(taxCalculation.TaxBreakdown.Single().TaxRateDetails.PercentageDecimal) / 100 + : 0, + SalesTaxAmount = Convert.ToDecimal(taxCalculation.TaxAmountExclusive) / 100, + TaxableAmount = Convert.ToDecimal(requestBody.Amount), + TotalAmount = Convert.ToDecimal(taxCalculation.AmountTotal) / 100, + }; + return TypedResults.Ok(response); + } } diff --git a/src/Api/Billing/Controllers/TaxController.cs b/src/Api/Billing/Controllers/TaxController.cs deleted file mode 100644 index bb947535e..000000000 --- a/src/Api/Billing/Controllers/TaxController.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Bit.Api.Billing.Models.Requests; -using Bit.Api.Billing.Models.Responses; -using Bit.Core.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace Bit.Api.Billing.Controllers; - -[Route("tax")] -[Authorize("Application")] -public class TaxController( - IStripeAdapter stripeAdapter) : Controller -{ - [HttpPost] - [Route("calculate")] - public async Task CalculateAsync([FromBody] CalculateTaxRequestModel requestBody) - { - var options = new Stripe.Tax.CalculationCreateOptions - { - Currency = "usd", - CustomerDetails = new() - { - Address = new() - { - PostalCode = requestBody.BillingAddressPostalCode, - Country = requestBody.BillingAddressCountry - }, - AddressSource = "billing" - }, - LineItems = new() - { - new() - { - Amount = Convert.ToInt64(requestBody.Amount * 100), - Reference = "Subscription", - }, - } - }; - var taxCalculation = await stripeAdapter.CalculateTaxAsync(options); - var response = new CalculateTaxResponseModel - { - SalesTaxRate = taxCalculation.TaxBreakdown.Any() - ? decimal.Parse(taxCalculation.TaxBreakdown.Single().TaxRateDetails.PercentageDecimal) / 100 - : 0, - SalesTaxAmount = Convert.ToDecimal(taxCalculation.TaxAmountExclusive) / 100, - TaxableAmount = Convert.ToDecimal(requestBody.Amount), - TotalAmount = Convert.ToDecimal(taxCalculation.AmountTotal) / 100, - }; - return TypedResults.Ok(response); - } -} diff --git a/src/Api/Billing/Models/Requests/CalculateTaxRequestModel.cs b/src/Api/Billing/Models/Requests/CalculateTaxRequestModel.cs index bac2aaa00..1e7b6c62c 100644 --- a/src/Api/Billing/Models/Requests/CalculateTaxRequestModel.cs +++ b/src/Api/Billing/Models/Requests/CalculateTaxRequestModel.cs @@ -4,7 +4,7 @@ public class CalculateTaxRequestModel { public decimal Amount { get; set; } - public string BillingAddressPostalCode { get; set; } + public string PostalCode { get; set; } - public string BillingAddressCountry { get; set; } + public string Country { get; set; } }