From 58cf8b183cb7b20ac94c2b2d702d57dd842c09cd Mon Sep 17 00:00:00 2001 From: Jonas Hendrickx Date: Fri, 11 Oct 2024 15:33:37 +0200 Subject: [PATCH] add --- .../Billing/Controllers/StripeController.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Api/Billing/Controllers/StripeController.cs b/src/Api/Billing/Controllers/StripeController.cs index 5e4d0ea87cf7..36eb7c31f9ae 100644 --- a/src/Api/Billing/Controllers/StripeController.cs +++ b/src/Api/Billing/Controllers/StripeController.cs @@ -74,16 +74,23 @@ public async Task CalculateAsync([FromBody] CalculateTaxRequestModel re }, } }; - var taxCalculation = await stripeAdapter.CalculateTaxAsync(options); - var response = new CalculateTaxResponseModel + try { - 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); + 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); + } + catch (StripeException e) + { + return TypedResults.BadRequest(e.Message); + } } }