Skip to main content
Avalara Help Center

Install and Configure Avalara AvaTax for Salesforce B2C Commerce

After you activate AvaTax Update and set up your company profile, install and configure AvaTax for Salesforce B2C Commerce. During configuration, customize your setup to fit your unique business needs for things like:

  • Tax calculation settings for various tax types
  • Product taxability settings

Alter these settings when your business needs change.

Find steps to install and configure the SiteGenesis JavaScript Controller (SGJC) after the StoreFront Reference Architecture (SFRA) sections.

Download the AvaTax integration for Salesforce B2C Commerce

Find and download the AvaTax integration from the Salesforce B2C Commerce marketplace.

SFRA

Use this section to add the SFRA (previously MFRA) to your AvaTax for Salesforce B2C Commerce installation. Find additional details in our AvaTax for Salesforce B2C Commerce SFRA integration guide.

Install SFRA

To install SFRA, import the appropriate cartridges and metadata, and then configure the AvaTax Reconciliation utility.

Import cartridges

  1. In UXStudio, go to File > Import > General > Existing Projects into workspace.
  2. Browse to the directory where you saved the bm_avatax, int_avatax_sfra, and int_avatax_svcclient cartridges, select them, and then click Finish.
  3. When prompted to link the cartridges to the sandbox, click OK.
  4. Go to Business Manager > Administration > Manage Sites, modify the site path, and then make sure the cartridge name int_avatax_sfra appears before app_storefront_base.

Import metadata

  1. In the Salesforce B2C Commerce Business Manager, go to Administration > Site Development > Site Import & Export.
  2. Under Import & Export, click Upload, browse to the site-import.zip file (located in the metadata folder), and then click Upload.
  3. Select the site-import.zip file and click Import.

Configure the AvaTax Reconciliation utility

  1. Go to Administration > Sites > Manage Sites > Business Manager – Settings and add the bm_avatax cartridge you previously imported in the BM cartridge path.
  2. Go to Administration > Organization > Roles & Permissions and select the role to give access to.
  3. In the Business Manager Modules section, select the context for the site or organization, and click Apply.
  4. In the list of BM modules that display, select AvaTax and click Update. The new AvaTax module and its menu items appear under Merchant Tools.

Configure SFRA

Configure SFRA with AvaTax services and custom preferences.

Configure SFRA services for AvaTax

  1. In the Salesforce B2C Commerce Business Manager, go to Administration > Operations > Services.
  2. Complete the following on the indicated tabs:
    • Credentials
      Field Action
      Name Enter credentials.avatax.rest
      URL
      • User
      • Password

      Enter your AvaTax username and password.

      Alternately, enter your AvaTax account ID in User and AvaTax license key in Password.

    • Profile

      Field Action
      Name Enter profile.avatax.rest
      Connection Timeout (ms) We recommend you enter 20,000
      All other fields Enter 0
    • Service

      Field Action
      Name Enter avatax.rest.all
      Type Select HTTP
      Enabled Select this option to enable AvaTax for SFRA
      Service Mode Select Live
      Communication Log Enable Select this option
      Profile Select profile.avatax.rest
      Credentials Select credentials.avatax.rest

Configure AvaTax site preferences for SFRA

  1. In the Salesforce B2C Commerce Business Manager, select the desired site.
    1. Go to Merchant Tools > AvaTax > AvaTax Settings and, on the Account Settings tab, select all appropriate settings for your company's storefront, including:
      Field Action
      Tax Calculation Select to start calculating taxes with AvaTax on your transactions. Enabled by default.
      Address Validation

      Select to validate shipping addresses during checkout using AvaTax. Enabled by default.

      AvaTax only validates addresses in the US and Canada.

      Save Transactions to AvaTax

      Select to save all orders to AvaTax.

      If not enabled, orders aren't saved to AvaTax, and features such as voiding and modifying transactions aren't available.

      Commit Transactions to AvaTax Select to have successful storefront orders marked as Committed when posted to AvaTax.
      Company Code Enter the AvaTax company code you created in AvaTax.
      Customer code Select the value that's sent as the customer code for authenticated customers. For guest customers, Salesforce B2C Commerce sends the email ID they enter during checkout.
      Shipping Tax Code Enter the default tax code to use to calculate taxes for shipping. If not specified, freight code FR is used.
      Taxation Policy

      This selection impacts cross-border tax calculation. Currently, only net calculations are supported.

      Select which is true for your store:

      • Net - Prices of items in a customer shopping cart do not include taxes or import duties. 
      • Gross - Prices of items in a customer shopping cart do include taxes or import duties.  (Not currently supported.)
      Location Code If anything is entered in this field, it's used for tax calculation on all your transactions and is given priority over all other ship from address fields.
      ShipFrom address fields Make sure the values in these fields match the address of the distributor. AvaTax uses this address to calculate taxes on all orders.
  2. Go to Merchant Tools > Site Preferences > Order > Order Access Settings, set Limit Storefront Order Access to No.
  3. Go to Merchant Tools > Site Preferences > Promotion > Discount Taxation and select the appropriate Promotion Preference.

Test the connection with AvaTax

Use the test utility to make sure you're correctly configured and connected. Actions taken in the test utility don't impact orders.

  1. In the Salesforce B2C Commerce Business Manager, select the desired site.
  2. Go to Merchant Tools > AvaTax > AvaTax Settings and, on the Services tab, test the current configuration for:
    • Voiding transactions - Next to Void Transaction, enter an order number to void, and then click Void.
    • Committing transactions - Next to Commit Transaction, enter an order number to commit, and then click Commit.
    • Validating addresses - Next to Address Validation, enter the number of an order with a shipping address to validate, and then click Validate.
  3. Use information in Service response to determine your next steps.

Install the SGJC 

The AvaTax for Salesforce B2C Commerce SGJC controller cartridge provides rapid integration for Salesforce B2C Commerce implementations. The self-contained cartridge easily integrates into any project. It can be configured in the Business Manager and contains all elements necessary to perform a successful best practices implementation.

Install the AvaTax integration for Salesforce B2C Commerce

To install AvaTax for Salesforce B2C Commerce, complete all the steps in this section.

Import the int_avatax cartridge and add SOAP services

  1. In  UXStudio, go to File > Import > General > Existing Projects Into Workspace.
  2. Browse to the directory where you saved the int_avatax cartridge, select it, and then click Finish.
  3. Browse to the root directory of your storefront cartridge and open package.json. (If the file doesn't exist, create it.)
  4. Add the following line to it:
    "init": ["int_avatax/cartridge/scripts/avatax/services/soapServiceInit.ds"]

    clipboard_ed77881cacda868786df465a9f12b9910.png

Import site preferences and custom objects

To import the system object customizations into the Salesforce B2C Commerce Business Manager:

  1. In the Salesforce B2C Commerce Business Manager, go to Administration > Sites Development > Import & Export.
  2. Under Import & Export, click Upload, browse to the avatax_metadata.xml file, and then click Upload.
  3. Click << Back at the bottom of the page.
  4. Under Meta Data, click Import, select the avatax_metadata.xml file, and then click Next.
  5. When validation completes, click Next.

Configure the SGJC

Add the AvaTax cartridge to your storefront cartridge path, configure AvaTax custom preferences and services, and then add custom code to your cartridges.

Append int_avatax to the effective cartridge path

  1. In the Salesforce B2C Commerce Business Manager, go to Administration > Sites > Manage Sites, and then select the desired site.
  2. On the Settings tab, append :int_avatax to Cartridges.
  3. Click Apply.

Configure AvaTax custom preferences

  1. In the Salesforce B2C Commerce Business Manager, from the tabs across the top of the page, select the desired site.
  2. Click Site Preferences, and then click Custom Preferences.
  3. Fill in all of the site preferences, including:
    Field Action
    Enable AvaTax Select Yes to start calculating taxes with AvaTax on your transactions. Enabled by default.
    Enable Address Validation Select Yes to validate addresses using AvaTax. Enabled by default.
    Enable Test Pipelines Select Yes to enable access to AvaTaxTest pipelines on the storefront. Enabled by default.
    Save transactions to AvaTax Select Yes to save uncommitted transactions to AvaTax.
    On successful payment commit transaction to AvaTax If Save transactions to AvaTax is set to Yes, select Yes to commit uncommitted transactions to AvaTax when marked as Paid. Disabled by default.
    AVS Excluded Countries Upload a CSV of country codes to exclude when validating addresses  
    AvaTax Company Code Enter your AvaTax company code to save transactions to companies configured in AvaTax
    Customer Code Select the attribute to use as the customer code. If a customer completes their transaction as a guest, the customer email is used regardless of what's selected here.
    Custom attribute for customer code If the source selected for Customer Code is Use another attribute from 'Profile' System object, enter 
    AvaTax Default Shipping Method Tax Code (Tax) Enter the default tax code to send when a shipping method has no tax class ID
    AvaTax Default Product Tax Code (Tax) Enter the default tax code to send when a product has no tax class ID
    • Avatax ShipFrom City
    • Avatax ShipFrom StateCode
    • Avatax ShipFrom ZipCode
    • Avatax ShipFrom Country Code
    Make sure the values in these fields match the address of the distributor

Add AvaTax tax and address validation services

  1. In the Salesforce B2C Commerce Business Manager, go to Administration > Operations > Services.
  2. On the Credentials tab, click New, fill in the following for tax services, and then click Apply:
    Field Action
    Name Enter a name of your choice
    URL
    • User
    • Password

    Enter your AvaTax username and password.

    Alternately, enter your AvaTax account ID in User and AvaTax license key in Password.

  3. On the Credentials tab, click New, fill in the following for address validation services, and then click Apply:
    Field Action
    Name Enter a name of your choice
    URL
    • User
    • Password

    Enter your AvaTax username and password.

    Alternately, enter your AvaTax account ID in User and AvaTax license key in Password.

  4. On the Profiles tab, click New.
  5. Enter a name for the tax service profile, fill out the other settings, and then click Apply.
  6. Repeat steps 4-5 for the address validation service profile.
  7. On the Services tab, click New, fill in the following, and then click Apply:
    Field Action
    Name Enter avatax.soap.GetTax
    Type Select SOAP
    • Profile
    • Credentials
    Choose the profile and credentials you created for the tax service
  8. On the Services tab, click New, fill in the following, and then click Apply:
    Field Action
    Name Enter avatax.soap.CancelTax
    Type Select SOAP
    • Profile
    • Credentials
    Choose the profile and credentials you created for the tax service
  9. On the Services tab, click New, fill in the following, and then click Apply:
    Field Action
    Name Enter avatax.soap.PostTax
    Type Select SOAP
    • Profile
    • Credentials
    Choose the profile and credentials you created for the tax service
  10. On the Services tab, click New, fill in the following, and then click Apply:
    Field Action
    Name Enter avatax.soap.ValidateAddress
    Type Select SOAP
    • Profile
    • Credentials
    Choose the profile and credentials you created for the address validation service

Add custom code to SGJC

Modify Salesforce B2C Commerce SGJCs to finish integrating with AvaTax.

  1. In CartMode.js, add the blue, bolded code to the following modules and functions:
    1. Include the Site module by adding:
      /**
       * Model for cart functionality. Creates a CartModel class with payment, shipping, and product
       * helper methods.
       * @module models/CartModel
       */
      var Transaction = require('dw/system/Transaction');
      var Site = require('dw/system/Site');
    2. Include the avataxApp module by adding:
      var lineItem;
      var app = require('~/cartridge/scripts/app');
      var ProductList = app.getModel('ProductList');
      var avataxApp = require('int_avatax/cartridge/scripts/app');
    3. To the calculate function add:
      calculate: function () {
      if(Site.getCurrent().preferences.custom.hasOwnProperty('ATEnable') && Site.getCurrent().getCustomPreferenceValue('ATEnable')) {
           avataxApp.getController('Avatax').CalculateTaxes(this.object);

      dw.system.HookMgr.callHook('dw.ocapi.shop.basket.calculate', 'calculate', this.object);
      },
    4. In the createOrder function, add orderNo as a parameter and include orderNo in the OrderMgr.createOrder call:
      createOrder: function (OrderNo) {
      var basket = this.object;
      var order;
      try {
            order = Transaction.wrap(function () {
                      return OrderMgr.createOrder(basket,OrderNo);
                       });
  2. In COPlaceOrder.js, add the blue, bolded code to the start function:
    1. After the check that the billing module is fulfilled, add:

      if (!session.forms.billing.fulfilled.value) {
          app.getController('COCustomer').Start();
          return {};
      }

      Var OrderNo = orderMgr.createOrderNo(); 

      session.custom.NoCall = false;
      session.custom.OrderNo = OrderNo;
      session.custom.finalCall = true;


      Transaction.wrap(function () {
          cart.calculate();
      });

    2. Pass OrderNo to the cart.createOrder() function:
       // Creates a new order. This will internally ReserveInventoryForOrder and will create a new Order with status
      // 'Created'.
           var order = cart.createOrder(OrderNo);
  3. In COShipping.js, add the blue, bolded code to the following functions:
    1. In the selectShippingMethod function, before the cart is calculated, set the NoCall variable to false:
      applicableShippingMethods = cart.getApplicableShippingMethods(address);    
      session.custom.NoCall = false;
      Transaction.wrap(function () {
      cart.updateShipmentShippingMethod(cart.getDefaultShipment().getID(),   request.httpParameterMap.shippingMethodID.stringValue, null, applicableShippingMethods);
              cart.calculate();
      });
    2. In the updateShippingMethodList function, assign the NoCall variable to true before looping through the shipping methods and to false after the loop is complete, before the cart is calculated:

      Transaction.begin();
          
          session.custom.NoCall = true;

          for (i = 0; i < applicableShippingMethods.length; i++) {
              method = applicableShippingMethods[i];

              cart.updateShipmentShippingMethod(cart.getDefaultShipment().getID(), method.getID(), method, applicableShippingMethods);
              cart.calculate();
              shippingCosts.put(method.getID(), cart.preCalculateShipping(method));
          } 
          session.custom.NoCall = false;

          Transaction.rollback();

          Transaction.wrap(function () {
              cart.updateShipmentShippingMethod(cart.getDefaultShipment().getID(), currentShippingMethod.getID(), currentShippingMethod, applicableShippingMethods);
              cart.calculate();
          });

  4. In calculate.js, require the Site module and add the following blue, bolded conditional statement around calculateTax() to avoid calling it if AvaTax is enabled:

    Var Site = require('dw/system/Site');

    and add the following conditional statement around calculateTax() to avoid calling it if Avatax is enabled:
     if(!Site.getCurrent().getCustomPreferenceValue('ATEnable')) {
                 calculateTax(basket);
        }

Test the connection with AvaTax

Navigate to the connection test address to make sure you're properly connecting to AvaTax.

  1. In the Salesforce B2C Commerce Business Manager, go to Storefront.
  2. In the browser address bar, at the end of the URL, replace Home-Show with Test-Connect, and then press Enter. For example:
    Change http://realmURL/ on/demandware.store/Sites-mysite-Site/default/Home-Show
    to http://realmURL/on/demandware.store/Sites-mysite-Site/default/Test-Connect
  • Was this article helpful?