示例#1
0
        public async Task <TotalOrderAmount> TaxForOrder(TaxOrderRequest orderRequest)
        {
            using (var client = _httpClientFactory.CreateClient())
            {
                client.BaseAddress = new Uri("https://api.taxjar.com");
                string             jsonstring     = Newtonsoft.Json.JsonConvert.SerializeObject(orderRequest);
                HttpRequestMessage requestMessage = new HttpRequestMessage
                {
                    Content    = new StringContent(jsonstring, System.Text.Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json),
                    Method     = HttpMethod.Post,
                    RequestUri = new Uri("v2/taxes", UriKind.Relative)
                };
                requestMessage.Headers.Add("Authorization", string.Format("Bearer {0}", _configuration.GetValue <string>("TaxJarApi")));
                try
                {
                    var result = await client.SendAsync(requestMessage);

                    if (result.IsSuccessStatusCode)
                    {
                        var responseStream           = result.Content.ReadAsStringAsync().Result;
                        TotalOrderAmount orderAmount = JsonConvert.DeserializeObject <TotalOrderAmount>(responseStream);
                        return(orderAmount);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(null);
        }
示例#2
0
        private TaxOrderRequest GetTaxOrderRequest()
        {
            TaxOrderRequest taxOrderRequest = new TaxOrderRequest();

            taxOrderRequest.from_country = "US";
            taxOrderRequest.from_zip     = "07001";
            taxOrderRequest.from_state   = "NJ";
            return(taxOrderRequest);
        }
        public async Task <ActionResult <TotalOrderAmount> > TaxForOrder([FromBody] TaxOrderRequest orderRequest)
        {
            try
            {
                var rate = await _taxService.TaxForOrder(orderRequest);

                return(Ok(rate));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }