コード例 #1
0
        public async Task <TaxRateResult> GetTaxRateAsync(TaxRateRequest taxRateRequest)
        {
            var result = new TaxRateResult();

            //the tax rate calculation by country & state & zip
            if (taxRateRequest.Address == null)
            {
                result.Errors.Add("Address is not set");
                return(result);
            }

            var foundRecord = await _abcTaxService.GetAbcTaxRateAsync(
                taxRateRequest.CurrentStoreId,
                taxRateRequest.TaxCategoryId,
                taxRateRequest.Address
                );

            if (foundRecord == null)
            {
                return(result);
            }

            // get TaxJar rate if appropriate
            result.TaxRate = foundRecord.IsTaxJarEnabled ?
                             await _taxjarRateService.GetTaxJarRateAsync(taxRateRequest.Address) :
                             foundRecord.Percentage;

            return(result);
        }
コード例 #2
0
        private async Task <bool> IsCustomerInTaxableStateAsync(Customer customer)
        {
            var taxCategory     = (await _taxCategoryService.GetAllTaxCategoriesAsync()).FirstOrDefault(x => x.Name == "Warranties");
            var shippingAddress = customer.ShippingAddressId.HasValue ?
                                  await _addressService.GetAddressByIdAsync(customer.ShippingAddressId.Value) :
                                  null;

            if (shippingAddress == null)
            {
                return(false);
            }

            return(await _abcTaxService.GetAbcTaxRateAsync(
                       // for now this should be fine, since all rates apply to all stores
                       0,
                       taxCategory?.Id ?? 0,
                       shippingAddress
                       ) != null);
        }