public static decimal calculateTax (string from_country, string from_zip, string from_state, string from_city, string from_street, string to_country, string to_zip, string to_state, string to_city, string to_street, decimal amount, decimal shipping) { var client = new TaxjarApi(GetKey()); var tax = client.TaxForOrder(new { from_country = from_country, from_zip = from_zip, from_state = from_state, from_city = from_city, from_street = from_street, to_country = to_country, to_zip = to_zip, to_state = to_state, to_city = to_city, to_street = to_street, amount = amount, shipping = shipping }); decimal amt = Convert.ToDecimal(amount); var myRate = tax.Rate; var calculatedTax = myRate * amt; return(calculatedTax); }
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; })); }
public void TaxHelper_Gets_TaxRates() { var client = new TaxjarApi(GetKey()); decimal TaxRate = TaxHelper.GetRateByZipCode("07001", "US", "Avenel"); Console.WriteLine(TaxRate); Assert.AreEqual(0.06625, TaxRate); }
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); }
public TaxJarCommand(TaxJarConfig config) { if (string.IsNullOrWhiteSpace(config.ApiKey)) { return; } var apiUrl = config.Environment == TaxJarEnvironment.Production ? TaxjarConstants.DefaultApiUrl : TaxjarConstants.SandboxApiUrl; _client = new TaxjarApi(config.ApiKey, new { apiUrl }); }
public TaxjarCalculator() { try { string apiKey = WebConfigurationManager.AppSettings["TaxJarApiKey"]; _taxjarApi = new TaxjarApi(apiKey); } catch (Exception e) { throw new Exception("Could not instantiate TaxjarApi.", e.InnerException); } }
// 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" //}); }
public override Task <TaxBreakdownModel> RunAsync(TaxableCartModel arg, CommercePipelineExecutionContext context) { var taxJarPolicy = context.GetPolicy <TaxJarPolicy>(); var client = new TaxjarApi(taxJarPolicy.ApiKey); var nexus = arg.NexusAddresses.Select(x => new { id = Guid.NewGuid(), country = x.Country, zip = x.Zip, state = x.State, city = x.City, street = x.Address }).ToArray(); var lineItems = arg.LineItems.Select(x => new { id = x.Id, quantity = x.Quantity, unit_price = x.Price, discount = x.Discount }).ToArray(); var response = client.TaxForOrder(new { to_country = arg.ToCountry, to_zip = arg.ToZip, to_state = arg.ToState, to_city = arg.ToCity, to_street = arg.ToStreet, amount = arg.Amount, shipping = arg.Shipping, line_items = lineItems.ToArray(), nexus_addresses = nexus }); context.Logger.Log(LogLevel.Information, "Total: " + response.TaxableAmount + " shipping: " + response.Shipping + " Tax Payable: " + response.AmountToCollect + " Has Nexus: " + response.HasNexus); var result = new TaxBreakdownModel(); if (response != null) { result.HasNexus = response.HasNexus; result.IsShippingTaxable = response.FreightTaxable; result.AmountToCollect = response.AmountToCollect; } return(Task.FromResult(result)); }
public static void Init() { if (server == null) { server = FluentMockServer.Start(new FluentMockServerSettings { Urls = new[] { "http://localhost:9191" } }); } var options = GetTestOptions(); apiKey = options.ApiToken; client = new TaxjarApi(apiKey, new { apiUrl = "http://localhost:9191" }); }
public static void Init() { DotNetEnv.Env.Load("../../../.env"); if (server == null) { server = FluentMockServer.Start(new FluentMockServerSettings { Urls = new[] { "http://localhost:9191" } }); } apiKey = System.Environment.GetEnvironmentVariable("TAXJAR_API_KEY") ?? "foo123"; client = new TaxjarApi(apiKey, new { apiUrl = "http://localhost:9191" }); }
public void returns_exception_with_invalid_api_token() { this.client = new TaxjarApi("foo123", new { apiUrl = "http://localhost:9191/v2/" }); var stubHttp = HttpMockRepository.At("http://localhost:9191"); stubHttp.Stub(x => x.Get("/v2/categories")) .Return("{\"error\":\"Unauthorized\",\"detail\":\"Not authorized for route 'GET /v2/categories'\",\"status\":401}") .WithStatus(HttpStatusCode.Unauthorized); var taxjarException = Assert.Throws <TaxjarException>(() => client.Categories()); Assert.AreEqual(HttpStatusCode.Unauthorized, taxjarException.HttpStatusCode); Assert.AreEqual("Unauthorized", taxjarException.TaxjarError.Error); Assert.AreEqual("Not authorized for route 'GET /v2/categories'", taxjarException.TaxjarError.Detail); Assert.AreEqual("401", taxjarException.TaxjarError.StatusCode); }
public async Task <TaxResponse> GetTax(TaxJarRequest taxJarRequest) { try { taxResponse = new TaxResponse(); using (FaceDBEntities db = new FaceDBEntities()) { var client = new TaxjarApi(ApplicationConfiguration.TAX_JAR_ACCESS_KEY); if (!string.IsNullOrEmpty(taxJarRequest.UserEmail)) { var systemUser = await db.system_user.Where(x => x.email == taxJarRequest.UserEmail && x.Blocked == "N").FirstOrDefaultAsync(); if (systemUser.id > 0) { //var rates = client.RatesForLocation(systemUser.ZipCode.ToString(), new { }); var tax = client.TaxForOrder(new { from_zip = systemUser.ZipCode.ToString() }); taxResponse.combined_rate = tax.Rate; } else { taxResponse.Success = false; taxResponse.Message = CustomErrorMessages.INVALID_EMAIL; } } else { taxResponse.Success = false; taxResponse.Message = CustomErrorMessages.INVALID_INPUTS; } taxResponse.Success = true; taxResponse.Message = null; } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); taxResponse.Success = false; taxResponse.Message = CustomErrorMessages.INTERNAL_ERROR; } return(taxResponse); }
public void Init() { this.client = new TaxjarApi("foo123", new { apiUrl = "http://localhost:9191/v2/" }); }
public JarTaxService() { _client = new TaxjarApi(ConfigurationManager.AppSettings["TaxjarApiKey"]); }
public TaxCalculatorClientA(IMapper mapper, IConfiguration config) { _taxJarClient = new TaxjarApi(config["ApiKey"]); _mapper = mapper; }
public void Setup() { _client = new TaxjarApi("5da2f821eee4035db4771edab942a4cc"); }
public void instantiates_client_with_api_token() { this.client = new TaxjarApi("foo123"); }
public void instantiates_client_with_additional_arguments() { this.client = new TaxjarApi("foo123", new { apiUrl = "http://localhost:9191/v2/" }); }
public TaxJarCalculator() { var apiKey = ConfigurationService.AppSetting["TaxJarApiKey"]; client = new TaxjarApi(apiKey); }