Пример #1
0
        public async Task <decimal> GetTaxJarRateAsync(Address address)
        {
            var zip     = address.ZipPostalCode?.Trim() ?? string.Empty;
            var street  = address.Address1;
            var city    = address.City;
            var country = (await _countryService.GetCountryByIdAsync(address.CountryId.Value))?.TwoLetterIsoCode;

            var cacheKey = _staticCacheManager.PrepareKeyForDefaultCache(
                AbcTaxTaxjarRateKey,
                zip,
                street,
                city,
                country
                );

            return(await _staticCacheManager.GetAsync(cacheKey, () =>
            {
                var taxjarApi = new TaxjarApi(_abcTaxSettings.TaxJarAPIToken);
                var rates = taxjarApi.RatesForLocation(zip, new {
                    street = street,
                    city = city,
                    country = country
                });

                // if US or Canada, CountryName will be populated
                return !string.IsNullOrWhiteSpace(rates.Country) ?
                rates.CombinedRate * 100 :
                rates.StandardRate * 100;
            }));
        }
Пример #2
0
        public async Task <decimal> GetTaxRate(string zipcode)
        {
            await Task.Delay(0);

            var rates = _client.RatesForLocation(zipcode);

            return(rates.CombinedRate);
        }
Пример #3
0
        public static decimal GetRateByZipCode(string zipCode, string countryCode, string city)
        {
            var client = new TaxjarApi(GetKey());
            var rates  = client.RatesForLocation(zipCode, new
            {
                country = countryCode,
                city    = city,
            });

            return(rates.CombinedRate);
        }
Пример #4
0
        public object GetRatesForLocation(string zip, LocationModel model = null)
        {
            if (_taxjarApi == null)
            {
                return(null);
            }

            object apiParameters = LocationModelToApiParameters(model);

            return(_taxjarApi.RatesForLocation(zip, apiParameters));
        }
Пример #5
0
        public void when_showing_tax_rates_for_a_location()
        {
            var stubHttp = HttpMockRepository.At("http://localhost:9191");

            stubHttp.Stub(x => x.Get("/v2/rates/90002"))
            .Return(TaxjarFixture.GetJSON("rates.json"))
            .OK();

            var rates = client.RatesForLocation("90002");

            Assert.AreEqual("90002", rates.Zip);
            Assert.AreEqual("CA", rates.State);
            Assert.AreEqual(0.065, rates.StateRate);
            Assert.AreEqual("LOS ANGELES", rates.County);
            Assert.AreEqual(0.01, rates.CountyRate);
            Assert.AreEqual("WATTS", rates.City);
            Assert.AreEqual(0, rates.CityRate);
            Assert.AreEqual(0.015, rates.CombinedDistrictRate);
            Assert.AreEqual(0.09, rates.CombinedRate);
            Assert.AreEqual(false, rates.FreightTaxable);
        }
Пример #6
0
        // static HttpClient client;//= new HttpClient();

        public static void GetRate()
        {
            var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214");
            var rates  = client.RatesForLocation("90404-3370");

            // United States (ZIP w/ Optional Params)
            //var rates = client.RatesForLocation("90404", new
            //{
            //    city = "Santa Monica",
            //    state = "CA",
            //    country = "US"
            //});
        }
Пример #7
0
 public RateResponseAttributes GetTaxRateForLocation(Rate rate)
 {
     return(_client.RatesForLocation(rate.Zip));
 }