Exemple #1
0
        /// <summary>
        /// Makes a request to the PostalCodeTax API to return a list of postal codes with
        /// their corresponding tax calculation types
        /// </summary>
        /// <returns></returns>
        public async Task <PostalCodeTaxResponse> GetAsync()
        {
            try
            {
                var endpointUri = new Uri($"{_apiGatewayUri}api/v1/listPostalCodeTaxes");

                using (var client = new GenericHttpClient <PostalCodeTaxResponse>(endpointUri))
                {
                    return(await client.GetAsync());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error while trying to retrieve the postal codes with their corresponding tax types from the PostalCodeTax API.");

                // rethrow to preserve stack details
                throw;
            }
        }
        /// <summary>
        /// Makes an HTTP request to the TaxCalculation API to calculate the tax ammount for a given postal code and annual income
        /// </summary>
        /// <param name="postalCode">Postal code</param>
        /// <param name="annualIncome">Total annual income</param>
        /// <returns>TaxCalculationResponse</returns>
        public async Task <TaxCalculationResponse> CalculateAsync(string postalCode, decimal annualIncome)
        {
            try
            {
                var endpointUri = new Uri($"{_apiGatewayUri}api/v1/calculateTax");
                var request     = new TaxCalculationRequest
                {
                    PostalCode   = postalCode,
                    AnnualIncome = annualIncome
                };

                using (var client = new GenericHttpClient <TaxCalculationResponse>(endpointUri))
                {
                    return(await client.PostAsync(request));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error while trying to tax caluclation request to the PostalCodeTax API.");

                // rethrow to preserve stack details
                throw;
            }
        }