Beispiel #1
0
        public bool Calculate()
        {
            try
            {
                if (Entity.Calculated)
                {
                    return(false);
                }

                var customer = _customerService.FindById(Entity.CustomerId);

                switch (_taxRule.GetTaxRule(customer.CountryId))
                {
                case TaxRuleType.Calculated:
                    _taxService.Calculate(Entity, true);
                    break;

                case TaxRuleType.NotCalculated:
                    _taxService.Calculate(Entity, false);
                    break;
                }
                Entity.Calculated = true;

                return(true);
            }catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] TaxCalculationRequest request)
        {
            try
            {
                if (request == null)
                {
                    return(BadRequest("Invalid Request"));
                }

                //TODO: Recommended to get clientId from Auth token/Identity unless an 'agent' is selecting clients in the app
                if (string.IsNullOrEmpty(request.ClientId))
                {
                    return(BadRequest("ClientId is Required"));
                }

                if (string.IsNullOrEmpty(request.ToCountry))
                {
                    return(BadRequest("Ship to Country is Required"));
                }

                if (string.IsNullOrEmpty(request.ToState))
                {
                    return(BadRequest("Ship to State is Required"));
                }

                if (request.Shipping == 0)
                {
                    return(BadRequest("Total amount to Ship is Required"));
                }

                if (request.ToCountry == "US" || request.ToCountry == "CA")
                {
                    if (string.IsNullOrEmpty(request.ToZip))
                    {
                        return(BadRequest("Zip is required if US or CA is the Country"));
                    }
                }

                TaxJarCalculateResponse calculation = await taxService.Calculate(request);

                return(Ok(JsonConvert.SerializeObject(calculation)));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public static CartProduct Create(Cart cart, Product product, int quantity, ITaxService taxService)
        {
            if(cart == null)
                throw new ArgumentNullException("cart");

            if (product == null)
                throw new ArgumentNullException("product");

            return new CartProduct()
            {
                Cart = cart,
                Product = product,
                Quantity = quantity,
                Active = true,
                Created = DateTime.Now,
                Tax = taxService.Calculate(cart.Customer, product)
            };
        }
        public static CartProduct Create(Cart cart, Product product, int quantity, ITaxService taxService)
        {
            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            return(new CartProduct()
            {
                Cart = cart,
                Product = product,
                Quantity = quantity,
                Active = true,
                Created = DateTime.Now,
                Tax = taxService.Calculate(cart.Customer, product)
            });
        }
Beispiel #5
0
 public Response <TaxVM> Post([FromBody] UserVM userVM)
 {
     return(_taxService.Calculate(userVM, ModelState.IsValid));
 }