Skip to main content
Avalara AvaTax works out sales tax, VAT and GST for each sale in real time. With the integration connected, Avalara calculates the tax on every line and delivery charge at checkout. Spree then files the placed order with Avalara, voids it if the order is cancelled, and files a credit when money goes back on a return, claim or exchange. It can also check US and Canadian addresses at checkout.
You need an Avalara account. Use a sandbox account to try the integration before going live.

Installation

Add the gem to your Spree application and restart the server:
The gem adds no database tables of its own. Its call log is kept in a table Spree core provides, so run your usual bin/rails spree:install:migrations db:migrate when you upgrade Spree. If you are moving from the 5.x extension (spree_avatax_official), see Upgrading from Spree 5.

Connect Avalara

In the Spree admin, go to Settings → Integrations and find the Avalara AvaTax tile. The Integrations page in the Spree admin showing the Avalara AvaTax tile Click Connect and fill in the form:
  • Account number and License key — your AvaTax credentials, from your Avalara account.
  • Company code — the company in your Avalara account that orders are filed against.
  • Endpoint — Sandbox for testing (the default) or Production for your live store. It must match the account the credentials belong to.
You find the account number, license key and company code in the Avalara admin console: admin.avalara.com for a production account, sandbox.admin.avalara.com for a sandbox one. The console is also where you manage your companies, nexus, exemption certificates and reports. The Avalara connection form in Spree, with the account number, license key, company code and environment When you save, Spree tests the connection. It checks that the credentials are accepted and that your Avalara account holds the company code you entered. If either check fails, the integration stays off and the form tells you which: Avalara’s own message for rejected credentials, or Company code … was not found in this Avalara account for a mistyped code. To run the same checks again later, open the integration and click Test connection. It changes no settings; with Logging on, its calls appear in the call log.

Settings

These settings are on the same form. The Avalara settings in Spree
  • Document recording — what happens to a placed order at Avalara:
    • Record and commit (the default) files it as committed, so it appears in your Avalara reports and returns.
    • Record without committing files it as saved. It stays out of your returns until you commit it in Avalara.
    • Don’t record files nothing. Spree still asks Avalara for the tax at checkout, but no order, cancellation or credit is sent. Choose this when another system, such as your ERP, records your sales with Avalara. Switching to it also stops cancellations and credits for orders recorded before the switch.
  • Address validation — when on, a checkout whose US or Canadian address Avalara cannot verify is refused before the order is placed.
  • Logging — when on, every call to Avalara is recorded in the integration’s call log. See Logging.

Choose where Avalara calculates tax

Each market chooses who calculates its tax. Set a market’s Tax engine to Avalara AvaTax and every sale in it is taxed by Avalara. Markets you leave alone keep using Spree’s own tax rates, so you can move one region at a time. Avalara taxes a sale from where it ships to where it goes, so your stock locations need full addresses: street, city, state or region and postal code. Set them at Settings → Stock locations. If one is incomplete, the market’s Tax engine field warns you and names it when you choose Avalara AvaTax; until it is fixed, checkout is refused for orders shipped from it. An order shipped from several locations is taxed and reported per location.

Tax codes

Each line is sent with an Avalara tax code, which tells Avalara what is being sold. Set the codes on your tax categories at Settings → Taxes → Tax categories. When a market calculates through Avalara, the Tax code field searches Avalara’s codes as you type. Type a word such as clothing, or the start of a code such as PC04, and pick a code from the list. You can still type a code that is not listed. Searching Avalara's tax codes on a tax category in Spree
  • A product is sent with its tax category’s code. A product without one uses the store’s default tax category, and then Avalara’s general tangible goods code, P0000000.
  • A delivery is sent as its own line with the code of its delivery method’s tax category, or Avalara’s freight code, FR, when it has none. Set a delivery method’s tax category at Settings → Delivery profiles: open the profile, then edit the delivery method.
You can also browse every code at taxcode.avatax.avalara.com.

Customers and exemptions

Avalara keys each sale to a customer code: the customer’s ID, or the email address for a guest. Exemption certificates recorded in Avalara for that customer code are applied by Avalara automatically. For business buyers, record exemptions in Spree on the company. Open the company at Customers → Companies and add its certificates on the Exemption certificates card. Each certificate names its states or countries, its certificate number and an exemption reason. A company's exemption certificates in Spree Avalara decides an exemption by its entity use code, so give each exemption reason the matching Avalara code at Settings → Taxes → Exemption reasons. Once a market uses Avalara, the reason form offers Avalara’s codes. A reason with a code Avalara does not define is sent as L (other). A buyer who does not belong to a company has no exemption certificates in Spree. Record their certificate in the Avalara admin console instead, under their customer code: the customer’s ID as Spree shows it, or their email address for a guest. Avalara applies it to their sales automatically. A company’s tax registration (its VAT number) is set on its Tax registration card and sent with each sale, so Avalara can zero-rate an intra-EU business sale or apply reverse charge. See Companies and Taxes for how to manage these.

What Spree sends to Avalara

Each document carries the customer code, the ship-from, ship-to and bill-to addresses, the location it ships from as the reporting location (from the location’s admin name), and the order’s purchase order number when it has one. A credit is dated the day the money went back but taxed as of the original sale, and carries exactly the tax the customer was refunded. With Don’t record chosen, none of these documents is sent. To check a document, open Transactions in the Avalara admin console (admin.avalara.com, or sandbox.admin.avalara.com for a sandbox account) and search for its document code. Transactions listed as sales invoices in the Avalara dashboard

Logging

Turn on Logging to trace what Spree sends to Avalara. Every call is then recorded in the integration’s call log: what was called, the HTTP status (or the network error when Avalara did not answer), how long it took, and the request and response. Your credentials are never recorded. To read it, go to Settings → Integrations and open Avalara AvaTax. Its Call log section shows the latest calls; click View all calls for the whole log. That page starts with how many calls were recorded and what share of them failed, then lists the calls, newest first. Search for an operation by name, such as create_transaction, or set Status to Failed to see the calls Avalara refused or never answered, and click a call to see its request and response. The request and response carry customer addresses, so they are shown only to staff whose role can also read orders; others see each call’s outcome and timing. Developers can read the same entries through the Admin API: GET /api/v3/admin/integrations/{id}/logs lists the calls, and GET /api/v3/admin/integrations/{id}/logs/{log_id} returns one with its request and response. The requests contain customer addresses, and a guest’s email address is their customer code, so entries are deleted after 30 days. Your developer can change the period with SPREE_INTEGRATION_LOG_RETENTION_DAYS; the deletion runs as a daily job (see background jobs). Turn logging on while you need it.

Upgrading from Spree 5

If your store used the 5.x extension, spree_avatax_official, run the upgrade task once after installing the gem:
It keeps your credentials and settings (a commit setting that was off becomes Record without committing), turns customers’ VAT numbers into tax registrations, removes the tax rate the old extension created, points markets that named no tax calculation at Avalara, and adds an exemption reason for each Avalara entity use code. It can be run again safely. The old extension’s schema stays in place until you remove it. Removing it deletes the old vat_id column, so first add by hand any VAT numbers the upgrade task listed as not valid, or export the column. A customer whose number is lost is charged tax as a consumer.

Managing your integration

You can change the credentials and settings at any time from Settings → Integrations.
Turning the integration off does not break checkout, but markets that calculate through Avalara then charge no tax at all until it is reconnected. The misconfiguration is reported to your error tracker. Point those markets at Spree’s own tax rates if Avalara will be off for long. Orders already filed with Avalara are not affected.