Exemplo n.º 1
0
        public async Task <decimal> GetTaxForOrder(OrderVM order)
        {
            if (string.IsNullOrEmpty(order.ToCountry) || order.Shipping < 0)
            {
                throw new InvalidOperationException("ZipCode is a required data");
            }

            if (!string.IsNullOrEmpty(order.ToCountry))
            {
                if (!RegEx.IsValidCountry(order.ToCountry.ToUpper()))
                {
                    throw new InvalidOperationException("Destination country is not a valid Code");
                }

                if (order.ToCountry.ToLower() == "us" && string.IsNullOrEmpty(order.ToZip))
                {
                    throw new InvalidOperationException("ZipCode data is required when destination country is US");
                }

                if (order.ToCountry.ToLower() == "us" && !RegEx.isValidZipCode(order.ToZip))
                {
                    throw new InvalidOperationException("ZipCode data is not a valid US ZipCode");
                }

                if ((order.ToCountry.ToLower() == "us" || order.ToCountry.ToLower() == "ca") && string.IsNullOrEmpty(order.ToState))
                {
                    throw new InvalidOperationException("Destination state is required whe Destination country is US or CA");
                }
            }

            var orderApi = _mapper.Map <Order>(order);
            var response = await _taxJarClient.TaxForOrderAsync(orderApi);

            return(response.AmountToCollect);
        }
Exemplo n.º 2
0
        public async Task TaxForOrder()
        {
            var orderRequest = new Order
            {
                FromCountry = "US",
                FromZip     = "92093",
                FromState   = "CA",
                ToCountry   = "US",
                ToZip       = "90002",
                ToState     = "CA",
                Amount      = 270,
                Shipping    = 7.5m,
            };
            var response = await _client.TaxForOrderAsync(orderRequest);

            Assert.AreEqual(27.68, response.AmountToCollect);
        }
Exemplo n.º 3
0
        private async Task <IEnumerable <(TaxJarOrder request, TaxResponseAttributes response)> > CalculateTax(OrderWorksheet orderWorksheet)
        {
            var orders    = orderWorksheet.ToTaxJarOrders();
            var responses = await Throttler.RunAsync(orders, 100, 8, async order =>
            {
                var tax = await MakeRequest(() => _client.TaxForOrderAsync(order));
                return(order, tax);
            });

            return(responses);
        }
Exemplo n.º 4
0
        public async Task <decimal> CalculateTaxesForOrder(Models.Order order)
        {
            var taxOrder = new Taxjar.Order()
            {
                FromCountry = "US",
                FromState   = order.FromState,
                ToCountry   = order.Country,
                ToState     = order.ToState,
                ToZip       = order.ToZip,
                Shipping    = 0,
                Amount      = order.GetSubTotal()
            };

            var result = await client.TaxForOrderAsync(taxOrder);

            if (result != null)
            {
                return(result.AmountToCollect);
            }
            return(0m);
        }