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 object GetTaxForOrder(OrderModel model) { if (_taxjarApi == null) { return(null); } object apiParameters = OrderModelToApiParameters(model); return(_taxjarApi.TaxForOrder(apiParameters)); }
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 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 TaxResponseAttributes GetTaxRateForOrder(Order order) { var rates = _client.TaxForOrder(order); return(rates); }
public void when_calculating_sales_tax_for_an_order() { var stubHttp = HttpMockRepository.At("http://localhost:9191"); stubHttp.Stub(x => x.Post("/v2/taxes")) .Return(TaxjarFixture.GetJSON("taxes.json")) .OK(); var rates = client.TaxForOrder(new { from_country = "US", from_zip = "07001", from_state = "NJ", to_country = "US", to_zip = "07446", to_state = "NJ", amount = 16.50, shipping = 1.50, line_items = new[] { new { quantity = 1, unit_price = 15.0, product_tax_code = "31000" } } }); Assert.AreEqual(16.5, rates.OrderTotalAmount); Assert.AreEqual(1.5, rates.Shipping); Assert.AreEqual(16.5, rates.TaxableAmount); Assert.AreEqual(1.16, rates.AmountToCollect); Assert.AreEqual(0.07, rates.Rate); Assert.AreEqual(true, rates.HasNexus); Assert.AreEqual(true, rates.FreightTaxable); Assert.AreEqual("destination", rates.TaxSource); // Breakdowns Assert.AreEqual(1.5, rates.Breakdown.Shipping.TaxableAmount); Assert.AreEqual(0.11, rates.Breakdown.Shipping.TaxCollectable); Assert.AreEqual(0.07, rates.Breakdown.Shipping.CombinedTaxRate); Assert.AreEqual(1.5, rates.Breakdown.Shipping.StateTaxableAmount); Assert.AreEqual(0.11, rates.Breakdown.Shipping.StateAmount); Assert.AreEqual(0.07, rates.Breakdown.Shipping.StateSalesTaxRate); Assert.AreEqual(0, rates.Breakdown.Shipping.CountyTaxableAmount); Assert.AreEqual(0, rates.Breakdown.Shipping.CountyAmount); Assert.AreEqual(0, rates.Breakdown.Shipping.CountyTaxRate); Assert.AreEqual(0, rates.Breakdown.Shipping.CityTaxableAmount); Assert.AreEqual(0, rates.Breakdown.Shipping.CityAmount); Assert.AreEqual(0, rates.Breakdown.Shipping.CityTaxRate); Assert.AreEqual(0, rates.Breakdown.Shipping.SpecialDistrictTaxableAmount); Assert.AreEqual(0, rates.Breakdown.Shipping.SpecialDistrictAmount); Assert.AreEqual(0, rates.Breakdown.Shipping.SpecialDistrictTaxRate); Assert.AreEqual(16.5, rates.Breakdown.TaxableAmount); Assert.AreEqual(1.16, rates.Breakdown.TaxCollectable); Assert.AreEqual(0.07, rates.Breakdown.CombinedTaxRate); Assert.AreEqual(16.5, rates.Breakdown.StateTaxableAmount); Assert.AreEqual(0.07, rates.Breakdown.StateTaxRate); Assert.AreEqual(1.16, rates.Breakdown.StateTaxCollectable); Assert.AreEqual(0, rates.Breakdown.CountyTaxableAmount); Assert.AreEqual(0, rates.Breakdown.CountyTaxRate); Assert.AreEqual(0, rates.Breakdown.CountyTaxCollectable); Assert.AreEqual(0, rates.Breakdown.CityTaxableAmount); Assert.AreEqual(0, rates.Breakdown.CityTaxRate); Assert.AreEqual(0, rates.Breakdown.CityTaxCollectable); Assert.AreEqual(0, rates.Breakdown.SpecialDistrictTaxableAmount); Assert.AreEqual(0, rates.Breakdown.SpecialDistrictTaxRate); Assert.AreEqual(0, rates.Breakdown.SpecialDistrictTaxCollectable); // Line Items Assert.AreEqual("1", rates.Breakdown.LineItems[0].Id); Assert.AreEqual(15, rates.Breakdown.LineItems[0].TaxableAmount); Assert.AreEqual(1.05, rates.Breakdown.LineItems[0].TaxCollectable); Assert.AreEqual(0.07, rates.Breakdown.LineItems[0].CombinedTaxRate); Assert.AreEqual(15, rates.Breakdown.LineItems[0].StateTaxableAmount); Assert.AreEqual(0.07, rates.Breakdown.LineItems[0].StateSalesTaxRate); Assert.AreEqual(1.05, rates.Breakdown.LineItems[0].StateAmount); Assert.AreEqual(0, rates.Breakdown.LineItems[0].CountyTaxableAmount); Assert.AreEqual(0, rates.Breakdown.LineItems[0].CountyTaxRate); Assert.AreEqual(0, rates.Breakdown.LineItems[0].CountyAmount); Assert.AreEqual(0, rates.Breakdown.LineItems[0].CityTaxableAmount); Assert.AreEqual(0, rates.Breakdown.LineItems[0].CityTaxRate); Assert.AreEqual(0, rates.Breakdown.LineItems[0].CityAmount); Assert.AreEqual(0, rates.Breakdown.LineItems[0].SpecialDistrictTaxableAmount); Assert.AreEqual(0, rates.Breakdown.LineItems[0].SpecialTaxRate); Assert.AreEqual(0, rates.Breakdown.LineItems[0].SpecialDistrictAmount); }