Automattic / woocommerce-services

WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
GNU General Public License v2.0
108 stars 20 forks source link

Fix/issue 2709 - Fix miscalculation tax from TaxJar and decided to use nexus address #2716

Closed iyut closed 9 months ago

iyut commented 9 months ago

Description

Based on the discussion with TaxJar, it's rather to omit the from_* from the API request and use nexus_addresses instead. And after doing a couple of test, this method seems fixing the tax issue and I dont see any other issue when implementing it.

Related issue(s)

Fixes #2709

Steps to reproduce & screenshots/GIFs

  1. Head to TaxJar Sales Tax Calculator to check the sales tax for Aurora, CO: https://www.taxjar.com/sales-tax-calculator
  2. Find TaxJar shows a tax rate of 8.000%
  3. Enable automated taxes using WooCommerce Shipping & Tax and set shop location to Colorado Springs, CO (80907)
  4. Add a product to you cart and head to the checkout page - enter an Aurora, CO address at checkout with zip code 80013
  5. Find tax rate seen at checkout is 8% Screenshot 2024-02-07 at 09 39 46

Checklist

iyut commented 9 months ago

@kloon I have tried to dig more info about this. And found this article. It seems there is more to it. The way we charge the tax might be different on each state. Some of them might use origin-based tax and the other are destination-based tax.

But based on this article, it's said that : "a majority of states are 'destination-based,' meaning they require merchants to collect sales tax based on the buyer’s ship-to location."

I have also tried to change the nexus addresses info to use from_* ( store address ). The result is when shipping :

But if I use to_* ( shipping address ). The result is :

Should we ask them more detail about nexus_addresses implementation?

Here is the request that was generated just in case they need it :

Using from_* : {"to_country":"US","to_state":"CA","to_zip":"90210","to_city":"Beverly Hills","to_street":false,"shipping":"10","plugin":"woo","nexus_addresses":[{"street":"1275 Fraser St","city":"Aurora","state":"CO","country":"US","zip":"80011"}],"line_items":[{"id":"14-aab3238922bcc25a6f606eb525ffdc56","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"},{"id":"31-c16a5320fa475530d9583c34fd356ef5","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"}]}

using to_* : {"to_country":"US","to_state":"CA","to_zip":"90210","to_city":"Beverly Hills","to_street":false,"shipping":"10","plugin":"woo","nexus_addresses":[{"street":false,"city":"Beverly Hills","state":"CA","country":"US","zip":"90210"}],"line_items":[{"id":"14-aab3238922bcc25a6f606eb525ffdc56","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"},{"id":"31-c16a5320fa475530d9583c34fd356ef5","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"}]}

kloon commented 9 months ago

Thanks for the feedback @iyut, I have relayed the question to our tax partner for clarification.

kloon commented 9 months ago

@iyut I have received feedback from TaxJar:

  1. Sales Tax Calculation with FROM Address: If you don't have the FROM address when calculating sales tax, you can obtain tax rates for a given location by using the /v2/rates endpoint and providing the customer's address. However, this method may provide only a rough estimate, especially if the seller doesn't have nexus in that state. For the most accurate calculation, it's recommended to use the FROM address of the merchant selling the product. This can be done by utilizing the from_ or nexus_addresses parameters with the /v2/taxes endpoint. This approach ensures the most accurate sales tax calculation and determines if sales tax is due.
  2. Differentiating Between Origin-Based and Destination-Based Tax States: Our API automatically identifies whether a state is origin-based or destination-based. You can also verify this information on the Dashboard, where it is displayed in the upper left corner when reviewing any state [0]. Regarding your test from CO to CA that didn't return a calculation, I'll investigate further to understand why this occurred. Did you encounter any specific error message during the test?
iyut commented 9 months ago

Hi @kloon ,

I have done more testing into TaxJar API, and it seems even if we're using nexus addresses as a from. It will still show a wrong tax rate from Colorado Springs, CO, 80907 to Aurora, CO, 80012. It's still return 4.25% tax rate.

Requesting: taxjar/v2/taxes - {"to_country":"US","to_state":"CO","to_zip":"80012","to_city":"Aurora","to_street":"800 S Abilene St, Aurora, CO 80012, United States","shipping":"10","plugin":"woo","nexus_addresses":[{"street":"2300 N Wahsatch Ave","city":"Colorado Springs","state":"CO","country":"US","zip":"80907"}],"line_items":[{"id":"31-c16a5320fa475530d9583c34fd356ef5","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"}]}

Received: {"tax":{"amount_to_collect":0.77,"breakdown":{"city_tax_collectable":0.0,"city_tax_rate":0.0,"city_taxable_amount":0.0,"combined_tax_rate":0.0425,"county_tax_collectable":0.05,"county_tax_rate":0.0025,"county_taxable_amount":18.0,"line_items":[{"city_amount":0.0,"city_tax_rate":0.0,"city_taxable_amount":0.0,"combined_tax_rate":0.0425,"county_amount":0.05,"county_tax_rate":0.0025,"county_taxable_amount":18.0,"id":"31-c16a5320fa475530d9583c34fd356ef5","special_district_amount":0.2,"special_district_taxable_amount":18.0,"special_tax_rate":0.011,"state_amount":0.52,"state_sales_tax_rate":0.029,"state_taxable_amount":18.0,"tax_collectable":0.77,"taxable_amount":18.0}],"special_district_tax_collectable":0.2,"special_district_taxable_amount":18.0,"special_tax_rate":0.011,"state_tax_collectable":0.52,"state_tax_rate":0.029,"state_taxable_amount":18.0,"tax_collectable":0.77,"taxable_amount":18.0},"freight_taxable":false,"has_nexus":true,"jurisdictions":{"city":"AURORA","country":"US","county":"ARAPAHOE","state":"CO"},"order_total_amount":28.0,"rate":0.0425,"shipping":10.0,"tax_source":"destination","taxable_amount":18.0}}

I'm really wondering how they calculate it that way.

Regarding their question : Did you encounter any specific error message during the test? There is no error specified when testing it. It was return 0.

But I double test the tax rates again today from CO to CA: When not using nexus addresses, it returns the tax rate 9.5%. But when using nexus addresses it doesn't return tax rates.

kloon commented 9 months ago

Thanks for checking again @iyut

I have relayed this back to TaxJar support again, in the interim, perhaps we do a solution like we did for Canada, but for Colorado while we iron out this with TaxJar on using the Nexus Address.

iyut commented 9 months ago

Thanks for the suggestion @kloon , In fact, that's what our team have discussed yesterday. Applying nexus address to all store address seems risky and might have a potential for regression.