Esempio n. 1
0
        public async Task <TaxCalculationResponse> Calculate(GetCalculationModel request)
        {
            if (request == null)
            {
                throw new NullReferenceException();
            }

            if (string.IsNullOrEmpty(request.ClientId))
            {
                throw new ArgumentNullException(nameof(request.ClientId));
            }

            if (string.IsNullOrEmpty(request.ToCountry))
            {
                throw new ArgumentNullException(nameof(request.ToCountry));
            }

            if (string.IsNullOrEmpty(request.ToState))
            {
                throw new ArgumentNullException(nameof(request.ToState));
            }

            if (string.IsNullOrEmpty(request.ToZip) && request.ToCountry == "US" || string.IsNullOrEmpty(request.ToZip) && request.ToCountry == "CA")
            {
                throw new ArgumentNullException(nameof(request.ToZip));
            }

            var mapped = mapper.Map <TaxCalculationRequest>(request);

            var response = await taxRepository.Post <TaxCalculationRequest, TaxCalculationResponse>(mapped);

            return(response);
        }
Esempio n. 2
0
        public async Task <TaxJarCalculateResponse> Calculate(TaxCalculationRequest request)
        {
            OrderModel mapped = mapper.Map <OrderModel>(request);

            //NOTE: Returning mocked data so clientId isn't used right now
            ClientModel  client  = clientService.GetClient(mapped.ClientId);
            ProductModel product = productService.GetProduct(request.ProductId);

            var lineItems = new List <Models.LineItem>
            {
                mapper.Map <Models.LineItem>(product)
            };

            mapped.LineItems   = lineItems;
            mapped.FromCity    = client.City;
            mapped.FromCountry = client.Country;
            mapped.FromState   = client.State;
            mapped.FromStreet  = client.Street;
            mapped.FromZip     = client.Zip;

            TaxJarCalculateResponse response = null;

            response = await taxRepository.Post <OrderModel, TaxJarCalculateResponse>(mapped);

            //TODO: Add mapping to TaxCalculationResposne, but for sake of time, return object from TaxJar. I would like to flatten this response out eventually.
            return(response);
        }