Context

The upcoming updates to our Client token and Payments API will supersede the TaxJar calculation from the Web SDK.

This document outlines how to migrate to the logic to this new API.

Changes

Calculate tax with POST /client-session

Tax calculation is now performed at the client token generation, when calling POST /client-session.

https://primer.io/docs/api/#operation/create_client_side_token_client_session_post

Tax will automatically be calculated using TaxJar if the following data are provided:

// POST /client-session

// Request
{
  "currencyCode": "USD",
  "order": {
    "lineItems": [
      {
        "itemId": "item",
        "quantity": 1,
        "amount": 2000,
        "discountAmount": 100,
        "taxCode": "item-tax-code"
      }
    ],
    "shipping": {
      "amount": 500
    }
  },
  "customer": {
    "billingAddress": {
      /* ... */
    }
  },

	"checkoutModuleOptions": {
		"addressForTaxCalculation": "BILLING_ADDRESS",
	}
}

The response of the API call will contain the results of the calculation that you can use to update your UI.

You don't have to pass top amount in the request as it will be automatically calculated with the line items. If amount is provided, you have to handle any discrepancy with the line items.

// Response
{
  "clientToken": "...",
  "clientTokenExpirationDate": "...",
  "currencyCode": "USD",
  "amount": 2500, // Automatically calculated
  "order": {
    "lineItems": [
      {
        "itemId": "item",
        "quantity": 1,
        "amount": 2000,
        "discountAmount": 100,
        "taxCode": "item-tax-code",
        "taxAmount": 100 // Calculated by TaxJar
      }
    ],
    "shipping": {
      "amount": 500
    }
  },
	/* ... */
}