Magento 2 Sales Tax Extension Guide
- Magento 2 CE & EE
- Magento Marketplace
- Last Updated
- April 20, 2018
We put together this integration guide for Magento 2.x merchants and developers looking to better understand TaxJar’s extension for sales tax calculations.
You’ll learn how TaxJar provides free checkout calculations with our SmartCalcs API and zip-based rates for native Magento calculations as a fallback. Along the way, we’ll configure your store to collect sales tax where you have nexus, handle product exemptions, import orders into TaxJar, and much more. For a primer on everything sales tax, read our Magento sales tax guide before getting started.
Getting Started with TaxJar
First install the Magento 2 sales tax extension. The easiest way is to use the Magento Marketplace and install it from your Magento admin panel.
composer require taxjar/module-taxjar
If you’re installing the extension manually, unzip the archive and upload the files to
/app/code/Taxjar/SalesTax. After uploading, run the following Magento CLI commands:
bin/magento module:enable Taxjar_SalesTax bin/magento setup:upgrade bin/magento setup:di:compile
These commands will enable the TaxJar extension, perform necessary database updates, and re-compile your Magento store. If you decide to manually update the TaxJar extension later, run
setup:di:compile again after installing the update.
Transitioning from Magento 1 to Magento 2
Already using TaxJar for Magento 1? Both of our extensions handle sales tax calculations similarly, but if you’ve been using TaxJar for sales tax reporting and filing you’ll need to make a quick change. Log in to your TaxJar account and go to Account > Linked Accounts. Click Unlink to remove your existing Magento 1 connection. In Magento 2, transactions are imported directly through our extension using the SmartCalcs API. We’ll set up transaction sync shortly.
Before going further, let’s review some of your existing Magento settings to make sure TaxJar is clear for landing. Log in to your Magento admin panel.
Go to Stores > Configuration in your admin panel. Under Sales > Shipping Settings > Origin, make sure you have a valid address with a US-based region and 5-digit postal code. If not, go ahead and add your address then click the orange Save Config button.
If you have existing sales tax rates, don't worry. We only overwrite zip-based sales tax rates if they reside in one of your nexus states. Your other rates will be remain intact and can still be used.
To review your existing rates, go to Stores > Tax Zones & Rates.
For existing sales tax rules don't sweat it either. We attach our zip-based sales tax rates to new or existing rules based on the tax classes you select in our extension. This means that custom rates can still be tied to existing sales tax rules. We've designed our extension to stay out of the way as much as possible.
Sales Tax Calculations
You’ve reviewed the pre-import checklist and everything looks ready for primetime.
Go to Stores > Configuration from the main menu. Select Tax under the Sales configuration menu on the left. We’re now ready to configure the TaxJar Magento 2 extension for sales tax calculations.
Connecting to TaxJar
Before enabling SmartCalcs, you’ll first need to connect to TaxJar from your Magento store. Click the Connect to TaxJar button. This will open a popup asking you to create a new account or log in to TaxJar. Once you’re in, you’ll be shown a confirmation screen to import your API token:
Click the Connect button and your token will automatically be saved in Magento. The configuration screen will refresh and show new options:
After connecting to TaxJar, you’ll first want to set up the states where your company has nexus. Go to Stores > Nexus Addresses from the main menu. From there you can add, change, or delete nexus addresses associated with your TaxJar account. There’s also a Sync from TaxJar button to automatically import any of your existing addresses from TaxJar:
We currently support one address per state/region in the US and Canada. For other countries we support one address per country. Make sure you enter a valid address for each state. If you’re unsure where you need to collect sales tax, read our blog post on nexus. We also provide helpful sales tax guides for each state.
Once you’re finished adding all of the states where you have nexus, continue on.
Product Sales Tax Exemptions
Before enabling SmartCalcs, you may want to assign a TaxJar product tax code to a product tax class in Magento. For example, say you have nexus in New York and sell clothing apparel. Clothing items under $110 are exempt in certain jurisdictions of New York. To set this up in Magento, all we need to do is go to Stores > Product Tax Classes. Click the
Taxable Goods class and you’ll notice a shiny new dropdown for assigning a TaxJar product category:
Clothing and click Save Product Tax Class. You now have clothing tax exemptions applied to all products assigned to the
Taxable Goods class. This works for new or existing product tax classes. We leave the tax code assigning up to you and it’s completely optional.
For a list of product tax codes SmartCalcs currently supports, check out our category endpoint reference.
Customer Sales Tax Exemptions
If you have customer groups exempt from sales tax, you’ll need to set their corresponding tax classes to exempt for checkout calculations. Go to Stores > Customer Tax Classes. Click the customer tax class you’d like to exempt and you’ll notice a dropdown:
Yes and click Save Customer Tax Class. Now any customers associated with that customer tax class will be exempt from SmartCalcs. If you’re still seeing sales tax collected, make sure you’re not collecting for this class using our backup rates feature or your own custom tax rates by reviewing your tax rules under Stores > Tax Rules.
By default Magento uses zip-based rates for calculating sales tax. When you calculate taxes by zip code, you may not be collecting the most accurate amount of sales tax. Zip codes can cover multiple districts, counties, cities, and even states/regions. These jurisdictions can have different rates. In addition, you may have product exemptions depending on what you’re selling and where. There’s limitations when you rely solely on a zip code for figuring out sales tax.
With SmartCalcs enabled you’ll get the most accurate sales tax rates based on the entire shipping address (not just zip code) with built-in support for shipping taxability, sourcing logic, itemized discounts, and product exemptions. Response times are fast (sub-75ms) with 99.99% uptime. Rest assured it won’t interrupt your checkout process.
Set Enabled for Checkout to
Yes for live checkout calculations. Click the orange Save Config button. Upon saving, SmartCalcs will be used for calculations instead of Magento’s rate-based tables. However, we can still use those rate-based tables as a fallback just in case.
Backup Sales Tax Rates
We provide a fallback to Magento’s native zip-based rates in case our API becomes unresponsive. While that’s unlikely to happen, it’s always good to have a backup plan. Upon setting Backup Rates to
Yes for the first time, you’ll be shown a screen similar to this:
You’ll notice we imported zip-based sales tax rates for each US state where you have nexus. Since we’re downloading thousands of rates into your database at once, this can take several minutes. For destination-based states, TaxJar always returns the highest rate for each zip code to ensure you’re not under-collecting sales tax. For origin-based states we do the same for wildcard rates. We only provide backup rates for US states at this time.
If you decide to add a new nexus state under Stores > Nexus Addresses and would like to refresh your rates manually, just click the Sync Backup Rates button. It’s that simple. We’ll automatically refresh your backup rates on the first of each month to make sure they’re up to date.
To verify sales tax rates and rules are loaded, go to Stores > Tax Rules. You should see your imported rates attached to a couple of sales tax rules:
When turning off nexus for a state, please keep in mind that we never remove tax rates for non-nexus states/regions. This allows our merchants to use their own custom zip-based rates in Magento if needed. After removing a nexus state, you’ll need to manually remove the rates for that state and re-sync your backup rates to refresh the tax rules.
Backup Sales Tax Classes
If you’re taking advantage of our backup rates, make sure you select the appropriate product and customer tax classes under the TaxJar configuration. Usually this means you’ll want to select
Taxable Goods and
Retail Customer if you haven’t added your own custom classes.
After importing zip-based backup rates, TaxJar’s extension automatically does several things to help prepare you for collecting sales tax using Magento’s native calculations:
Based on your shipping origin state configured under Shipping Settings > Origin, we set Magento's native tax calculations to be based on origin or destination-based sourcing (e.g. your address of shipping origin or the customer's shipping address).
This means we update a setting under Sales > Tax in your store configuration: Tax Calculation Based On. For most stores, Tax Calculation Based On will be set to
Shipping Address. If your store's shipping origin is origin-based (not destination), we'll set it to
Keep in mind this setting only affects Magento's native zip-based rates calculations. If you decide to enable SmartCalcs (live checkout calculations), this will only be used as a backup.
Our extension sets the following tax display settings under Sales > Tax to
Price Display Settings
- Display Product Prices in Catalog
- Display Shipping Prices
Shopping Cart Display Settings
- Display Prices
- Display Subtotal
- Display Shipping Amount
For most stores, these settings will already be set to
If you’re a developer, you may be wondering if TaxJar changes anything with the database after installation. Beyond setting default configuration values and storing extension-related data in the
core_config_data table, we only add a single column to
tax_class for managing product tax class codes and a
tax_nexus table for managing nexus addresses.
If you need to contact support, enabling debug mode shows you diagnostic information about your Magento store and the TaxJar extension itself. It also prevents the extension from downloading zip-based rates into your store.
To help us help you, take a screenshot of the debug mode message and include it in your support email if you’re having difficulties. Disable it afterwards if you want to continue importing rates.
If you have multiple websites or stores with different nexus addresses, you can assign nexus addresses to specific store views. Select the nexus address from Stores > Nexus Addresses and update the Store View dropdown:
By default a nexus address will be assigned to “All Store Views” and applied globally. Keep in mind that the same one address restriction applies to nexus addresses at the store level. For example, you can’t add a separate nexus location in California for one of your stores if you already have a global nexus location for California.
You can also supply different shipping origins per website. Shipping origins are used to help determine sourcing for sales tax calculations. Make sure you review your shipping origins under Stores > Configuration > Sales > Shipping Settings > Origin.
Sales Tax Reporting
We’re almost done setting up TaxJar with your Magento 2 store. If you’re interested in sales tax reporting and automated filing, proceed!
The latest version of our extension now supports real-time transaction syncing between TaxJar and Magento 2. Once your order is invoiced and shipped from the Magento admin panel, it’s automatically synced to TaxJar through our SmartCalcs API. On subsequent changes, the order is updated. Separate refunds are created for each credit memo in the order. We only sync orders with a
closed order state.
Setting Up Sales Tax Reporting
To begin syncing transactions with TaxJar, go to Stores > Configuration from the main menu. Select Tax under the Sales configuration menu on the left. Under SmartCalcs by TaxJar, you’ll find a Transaction Sync setting:
Click the Transaction Sync dropdown and select
Yes. If it’s your first time enabling Transaction Sync, you’ll be shown a pop-up window to authorize your TaxJar account for syncing transactions. In order to sync transactions with TaxJar, we require a 30 day reporting trial or paid TaxJar subscription:
If you’re using our free tax calculations, your trial will begin automatically after logging in from this screen. From there, click the green Enable Transaction Sync button in the pop-up window to finish enabling Transaction Sync in your Magento admin panel:
That’s it! Future orders will now be synced to TaxJar once they transition into a
closed order state. To see when a transaction was synced, go to the individual order or credit memo in your admin panel. You’ll find a Synced to TaxJar row in the summary with the sync date:
You can also browse through your orders and credit memos with the Synced to TaxJar grid column. This is turned off by default, so you’ll need to customize your grid to show it:
Now that we’re syncing transactions, it’s likely that you have previous Magento orders that haven’t been synced to TaxJar yet. To backfill transactions, click the Sync Transactions button that’s shown after you enable Transaction Sync:
A modal window will slide in, allowing you to pick a date range of orders you’d like to sync:
After selecting the From and To states, click the orange Sync to TaxJar button. We’ll look for
closed orders updated within that date range and push them to TaxJar. Once the process is finished, you’ll be able to view a log of what happened.
Whenever a transaction is synced to TaxJar, it’s recorded in a log file for your reference. You can find the log file at
Multi-Store Transaction Sync
Agencies or merchants with multiple business entities across different websites or stores can now use multiple TaxJar accounts to sync their transactions from a single Magento instance. To get started, go to Stores > Configuration from the main menu. Select Tax under the Sales configuration menu on the left. Switch to one of your stores using the “Store View” dropdown.
From there, you’ll want to scroll down the page to enable Debug Mode in the TaxJar module. Once the API Token field is visible, replace the existing API token with another TaxJar API token. Click the Save Config button and turn off Debug Mode. Now any order or credit memo processed through that store will be synced to a different TaxJar account for reporting and filing.
You’ve finished setting up TaxJar and Magento 2! At this point you should be collecting sales tax in your Magento store and syncing orders to TaxJar for reporting. From here on out this guide becomes more in-depth to explain what we’re doing behind the scenes. If you’re curious, feel free to read on.
How SmartCalcs Works
Your store seems to be calculating sales tax correctly, but now you might be wondering several things:
- How many SmartCalcs API calls will be made per order?
- What happens if SmartCalcs goes down or becomes unresponsive?
- How does SmartCalcs handle my custom / international rates?
- Will SmartCalcs work with my other extensions?
- How often do the zip-based rates refresh?
Our extension only makes live API calls when the order resides in a state where you have nexus. This saves you a lot of API calls and money. Additionally, API calls are cached until the checkout data changes. So if you have a customer repeatedly loading the checkout page without changing their shipping info, your store will not make additional API calls. On average, our SmartCalcs integration will make 2-3 API calls per order in a nexus state. If you allow customers to estimate their shipping and tax on the cart page, that’s included.
API calls are only made under 3 circumstances:
- Checkout process for a nexus state
- Cart shipping and tax estimate for a nexus state
- Refreshing zip-based backup rates in the admin panel
If the order does not reside in a nexus state, SmartCalcs will fall back to Magento’s zip-based rate tables. This gives you the opportunity to use custom or international rates for regions where you may have nexus that TaxJar either doesn’t support yet or you’d rather handle it yourself.
In the unlikely event that SmartCalcs goes down or times out after 10 seconds, Magento’s native calculations will kick in using the backup rates as well.
Our SmartCalcs integration extends the
\Magento\Tax\Model\Sales\Total\Quote\Tax model and overrides Magento’s native calculations only if checkout calculations are enabled. If you’re using a third-party checkout extension or something else that may rely on Magento’s internal rate tables (such as multi-warehouse inventory), try out TaxJar’s extension on a test or staging server before deploying to production.
Your zip-based rates will refresh automatically on the first of each month via cron job. You can manually refresh these rates yourself by re-saving the TaxJar extension configuration. Each refresh counts as one API call.
After a customer completes an order using SmartCalcs, our extension will record the sales tax amount and rate by line item in your database. If your store allows multiple currencies, the sales tax will be converted to the customer’s currency:
How Reporting Works
After enabling Transaction Sync in your TaxJar extension configuration, we’ll automatically sync orders to your TaxJar account once they’re fully invoiced and shipped. This happens immediately after the order transitions into a
closed state using the
sales_order_save_after event. Credit memos are synced after the associated order is synced. We support both partial and full refunds in TaxJar.
Sync requests go through our SmartCalcs API using the transaction endpoints. Once an order is synced, we save the timestamp in your database to ensure the order is only synced again after it’s updated. In the unlikely event that we can’t sync an order, no timestamp will be shown in the individual order view. You’ll need to backfill the transaction later if you don’t see the timestamp or can’t find the order in TaxJar.
Transaction API requests and responses are recorded in a custom log file located at
/var/log/taxjar.log. This log file contains the sync history for both backfilled and new transactions. You can use
taxjar.log for debugging or reaching out to TaxJar support if you experience any issues.
We support checkout calculations powered by SmartCalcs in more than 30 countries including VAT in the EU and Canada. To perform international calculations, add the countries to your nexus addresses under Stores > Nexus Addresses. For backup zip-based rates, we currently support the United States since it’s tightly integrated with our reporting app.
With that said, our SmartCalcs integration will automatically fall back to custom zip-based rates in Magento and already supports non-USD currencies. If you need backup rates in other countries you can set up custom tax rules under Stores > Tax Rules.
TaxJar now provides a command in the Magento CLI for developers to sync transactions:
By default this command will backfill the previous day’s updated orders in a
closed state. Additionally, you can provide
to arguments to sync a date range:
bin/magento taxjar:transactions:sync 01/01/2018 01/31/2018
We recommend using the CLI for merchants backfilling a high volume of transactions to avoid in-browser AJAX timeouts. You can also use it to increase your PHP memory limit, sleep between date ranges, run the command in a bash script, or schedule the command using a cron job.
Curious to see what’s changed with our extension lately? Read on to learn more!
- Multi-store calculations and transaction sync. Nexus addresses can be assigned to specific stores in Magento for calculations. Multiple API tokens can be used to calculate sales tax and sync transactions to TaxJar. After upgrading, please review your TaxJar configuration at the store level and test your checkout.
- Multi-website shipping origins. TaxJar now uses different shipping origins by website for calculations and reporting / filing. After upgrading, please review your shipping origins at the website level and test your checkout.
- Transaction sync CLI command. Developers can backfill transactions into TaxJar using the Magento CLI. To get started, read the documentation on using
- Improve full tax summary at checkout with tax amounts and rates per jurisdiction.
- Calculate line item tax amounts in Magento using the API rate for more precise calculations.
- Tweak transaction sync registry code to improve compatibility with 3rd party extensions.
- Increase timeout to 30 seconds for general API requests.
- Fix refund transaction sync after creating a new credit memo.
- Fix gift card exemptions in Magento EE.
- Require a unique tax class for backup shipping rates.
- Support split databases when installing the module.
- Composer support for Magento 2.2.
- Fix transaction sync for completed virtual orders at checkout.
- Fix debug mode error when TaxJar account has no nexus states.
- Fix minor client exception syntax issue.
- Fix backup rates field comment typo.
- Update specs for Magento 2.2 & PHPUnit 6.
- Fully exempt tax for products with tax class set to “None”.
- Fix child item quantities for bundle line items when parent quantity is > 1.
- Fix calculations for fixed price bundle products.
- Add note to “TaxJar Exempt” field for customer exemptions.
- Ensure non-US, non-USD orders are filtered during transaction backfill process.
- Pass shipping discounts as a separate line item when syncing transactions.
- Prevent duplicate order comments and total refund amounts when syncing refunds.
- Fix line item IDs for credit memo line items when syncing refunds.
- Reduce configurable / bundle product children line items to base products when syncing refunds.
- Hide sync dates for orders and credit memos if empty.
- Fix transaction sync for duplicate configurable product line items with different simple products.
- Require Magento 2.1 or later for real-time transaction syncing.
- Update translation dictionary.
- Transaction sync for automated sales tax reporting and filing. Orders and credit memos can now be synced to TaxJar with a 30 day reporting trial or paid subscription.
- Fix order creation error with multiple bundle or configurable products.
- Support “Apply Customer Tax” configuration setting for before and after discount calculations.
- Fix customer exemption check for new customers during admin orders.
- Fix tax code error for products without a tax class or set to “None”.
- Customer tax class management for SmartCalcs customer exemptions now available under Stores > Customer Tax Classes.
- Support gift card exemptions in Magento EE.
- Import TaxJar product categories immediately after connecting to TaxJar.
- Fix cron issue when syncing backup rates.
- Tweak version handling in debug mode and connect popup.
- Initial release of our Magento 2 extension. Sales tax calculations at checkout with backup zip-based rates powered by TaxJar. Supports product exemptions, shipping taxability, sourcing logic, and international calculations in more than 30 countries.
- Free sales tax calculations for Magento merchants. Existing M2 beta users must upgrade to this version to receive free calculations at checkout using our new API endpoint.