Exemplo n.º 1
0
 /// <summary>
 /// Validates Order Tax request and Consumer
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public void ValidateOrderTaxRequest(OrderTaxRequest request)
 {
     if (string.IsNullOrEmpty(request.To_country))
     {
         throw new BadInputException("Invalid.To_country");
     }
     if (request.Shipping == 0)
     {
         throw new BadInputException("Invalid.Shipping");
     }
 }
        /// <summary>
        /// Method to Calculate Order Tax
        /// </summary>
        /// <returns></returns>
        public async Task <OrderTaxResponse> TaxForOrder(OrderTaxRequest orderTax)
        {
            //Validate request and consumer
            _taxServiceValidator.ValidateOrderTaxRequest(orderTax);

            //Get Consumer Details
            var consumerDetail = _consumerHelper.GetConsumer();

            //Create api request
            var apiRequest = new OrderTaxApiRequest()
            {
                //required
                To_country   = orderTax.To_country,
                Shipping     = orderTax.Shipping,
                From_country = orderTax.From_country,
                ////optional
                From_zip    = orderTax.From_zip,
                From_city   = orderTax.From_city,
                From_state  = orderTax.From_state,
                From_street = orderTax.From_street,

                To_city         = orderTax.To_city,
                To_street       = orderTax.To_street,
                Amount          = orderTax.Amount,
                Nexus_addresses = MapAddress(orderTax.Nexus_addresses),
                Line_items      = MaplineItem(orderTax.Line_items),

                ////conditional
                To_zip   = orderTax.To_zip,
                To_state = orderTax.To_state,

                TaxApiAuthToken = consumerDetail.TaxApiAuthToken,
                TaxApiUrl       = consumerDetail.TaxApiUrl
            };

            //Call repository with valid request
            var response = await _taxRepository.TaxForOrder(apiRequest);

            return(response);
        }
        public async Task <IActionResult> OrderTax([FromBody] OrderTaxRequest orderTax)
        {
            var getTaxForOrder = await _taxService.TaxForOrder(orderTax);

            return(Ok(getTaxForOrder));
        }