public void GetTaxRateBadCalculatorNoAPIKeyTest() { string taxRateApiendpoint = "https://api.taxjar.com/v2/rates"; TaxJarRateRequest taxRateRequest = new TaxJarRateRequest { Street = "312 Hurricane Lane", City = "Williston", State = "VT", Country = "US", Zip = "05495-2086" }; TaxCalculationLibrary.Calculators.TaxJar taxJar = new TaxCalculationLibrary.Calculators.TaxJar("", "", taxRateApiendpoint); using (var service = TaxCalculationLibrary.Service.Factory.GetTaxService(taxJar)) { try { TaxJarRateResponse result = service.GetTaxRate(taxRateRequest); Assert.Fail("Should throw exception"); } catch (Exception ex) { Assert.IsNotNull(ex); } } }
private static void RunTaxJarSample() { string taxRateApiendpoint = "https://api.taxjar.com/v2/rates"; string apikey = "5da2f821eee4035db4771edab942a4cc"; TaxJarRateRequest taxRateRequest = new TaxJarRateRequest { Street = "312 Hurricane Lane", City = "Williston", State = "VT", Country = "US", Zip = "05495-2086" }; TaxJarCalculationRequest jarCalculationRequest = new TaxJarCalculationRequest { from_country = "US", from_zip = "92093", from_state = "CA", from_city = "La Jolla", from_street = "9500 Gilman Drive", to_country = "US", to_zip = "90002", to_state = "CA", to_city = "Los Angeles", to_street = "1335 E 103rd St", amount = 15, shipping = 1.5F, nexus_addresses = new System.Collections.Generic.List <TaxJarAddress> { new TaxJarAddress { id = "Main Location", country = "US", zip = "92093", state = "CA", city = "La Jolla", street = "9500 Gilman Drive", } }, line_items = new System.Collections.Generic.List <TaxJarLineItem> { new TaxJarLineItem { id = "1", quantity = 1, product_tax_code = "20010", unit_price = 15, discount = 0 } } }; TaxCalculationLibrary.Calculators.TaxJar taxJar = new TaxCalculationLibrary.Calculators.TaxJar(apikey, "https://api.taxjar.com/v2/taxes", taxRateApiendpoint); using (var service = TaxCalculationLibrary.Service.Factory.GetTaxService(taxJar)) { try { Console.WriteLine(service.GetTaxRate(taxRateRequest).Jsonify()); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { Console.WriteLine(service.GetTaxCalculationForOrder(jarCalculationRequest).Jsonify()); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }