> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CalculateTax

# Package: tax

# Namespace: TaxCalculationProvider

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/extensions/tax/tax-calculation-integration-service-plugin/calculate-tax.md

## Introduction

Calculates tax for the provided line items.

Wix calls this method whenever tax needs to be recalculated on a site, for example when a site visitor views their cart, begins checkout, or changes cart contents. Wix groups the line items by the tax calculator bound to each item's tax region and calls the corresponding provider.

Wix uses the returned tax breakdown to display tax on the cart and checkout pages and to calculate the order total.

Calculate tax for each line item based on the tax region in `lineItems.taxRegionId` and the tax group in `lineItems.taxGroupId`. The response `currency` must match the request `currency`, otherwise the response is invalid. Return:
+ `taxSummary`: The overall total tax calculated.
+ `lineItemTaxDetails.taxBreakdown`: The tax calculated for each line item in each jurisdiction.
+ `lineItemTaxDetails.taxSummary`: The total tax calculated for each line item.

*Error handling:** If your implementation returns an error or times out, Wix falls back to the Wix manual tax calculator. If that also fails, the order proceeds with zero tax and a calculation error. A resolved buyer exemption bypasses third-party providers and forces the Wix manual calculator.

---

## REST API

### Schema

```
 Method: calculateTax
 Description: Calculates tax for the provided line items.  Wix calls this method whenever tax needs to be recalculated on a site, for example when a site visitor views their cart, begins checkout, or changes cart contents. Wix groups the line items by the tax calculator bound to each item's tax region and calls the corresponding provider.  Wix uses the returned tax breakdown to display tax on the cart and checkout pages and to calculate the order total.  Calculate tax for each line item based on the tax region in `lineItems.taxRegionId` and the tax group in `lineItems.taxGroupId`. The response `currency` must match the request `currency`, otherwise the response is invalid. Return: + `taxSummary`: The overall total tax calculated. + `lineItemTaxDetails.taxBreakdown`: The tax calculated for each line item in each jurisdiction. + `lineItemTaxDetails.taxSummary`: The total tax calculated for each line item.  *Error handling:** If your implementation returns an error or times out, Wix falls back to the Wix manual tax calculator. If that also fails, the order proceeds with zero tax and a calculation error. A resolved buyer exemption bypasses third-party providers and forces the Wix manual calculator.
 URL: {DEPLOYMENT-URI}/v1/calculate-tax
 Method: POST
 Method parameters:
   param name: addresses | type: array<addresses> | description: Array of addresses. Each line item can individually reference the address to apply with `lineItems.addressIndex`.  | validation: minItems 1, maxItems 3
              - name: country | type: string | description: 2-letter country code in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) format.  | validation: format COUNTRY
              - name: subdivision | type: string | description: Subdivision (such as state, prefecture, or province) in [ISO-3166 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-2) format.  | validation: maxLength 50
              - name: city | type: string | description: City name.  | validation: maxLength 100
              - name: postalCode | type: string | description: Postal or zip code.  | validation: maxLength 50
              - name: addressLine | type: string | description: Main address line, usually street and number as free text.  | validation: maxLength 200
              - name: addressLine2 | type: string | description: Free text providing more detailed address information, such as apartment, suite, or floor.  | validation: maxLength 200
   param name: currency | type: currency | description: 3-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format.  | validation: format CURRENCY
   param name: lineItems | type: array<lineItems> | description: Line items to calculate tax for.  | validation: minItems 1, maxItems 300
              - name: id | type: string | description: Line item GUID.  | validation: minLength 1, maxLength 100
              - name: itemName | type: string | description: Line item name to display.  | validation: minLength 0, maxLength 250
              - name: quantity | type: integer | description: Line item quantity.  | validation: minimum 1, maximum 100000
              - name: price | type: string | description: Line item price.  | validation: format DECIMAL_VALUE, decimalValue {"lte":"1000000000000000"}
              - name: itemCode | type: string | description: Stock keeping unit for this line item. Learn more about [SKUs](https://www.wix.com/encyclopedia/definition/stock-keeping-unit-sku).  | validation: maxLength 40
              - name: taxGroupId | type: string | description: Tax group GUID for this line item. If not provided, the default tax group applies.  | validation: format GUID
              - name: taxIncludedInPrice | type: boolean | description: Whether tax is included in the price.  
              - name: addressIndex | type: AddressIndex | description: Index of the address from `addresses` to use to calculate tax for this specific line item. The index is zero-based.  
                 - ONE-OF: 
                    - name: singleAddress | type: integer | description: Single address to use for a sale location when only one address is required for tax calculations. The index is zero-based.  
                    - name: multipleAddresses | type: MultipleAddresses | description: Multiple addresses to use for a sale. For example, some tax calculations may require both the address where an item is shipped from, as well as the address the item is shipped to.  
                       - name: origin | type: integer | description: Index of the origin address.  
                       - name: destination | type: integer | description: Index of the destination address.  
              - name: taxRegionId | type: string | description: Tax region GUID for this line item.  | validation: format GUID
 Return type: CalculateTaxResponse
  - name: currency | type: string | description: 3-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. If this code doesn't match the `currency` passed in the request, then the response is invalid.  | validation: format CURRENCY
  - name: taxSummary | type: TaxSummary | description: Summary of the tax calculated.  
     - name: totalAmount | type: string | description: Total price for all line items.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
     - name: totalTax | type: string | description: Total amount of tax calculated for all line items. Note that due to rounding, `totalTax` may not equal the sum of `lineItemTaxDetails.taxSummary.taxAmount`.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
     - name: totalTaxableAmount | type: string | description: Total taxable amount for all line items.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
     - name: totalTaxIncludedInPrice | type: string | description: Total amount of `totalTax` that is included in price. Applies to line items with `taxIncludedInPrice` set to `true`.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
  - name: lineItemTaxDetails | type: array<LineItemTaxDetails> | description: Details of each tax applied to each line item.  | validation: minItems 1, maxItems 300
     - name: id | type: string | description: Line item GUID.  | validation: minLength 1, maxLength 100
     - name: itemName | type: string | description: Line item name to display.  | validation: minLength 0, maxLength 250
     - name: quantity | type: integer | description: Line item quantity.  | validation: minimum 1, maximum 100000
     - name: taxBreakdown | type: array<TaxBreakdown> | description: Array of each tax applied, grouped by `jurisdiction`, `jurisdictionType`, `taxName`, `rate`, and `taxType`.  | validation: maxItems 7
        - name: jurisdiction | type: string | description: Jurisdiction that taxes were calculated for.  | validation: maxLength 200
        - name: nonTaxableAmount | type: string | description: Non-taxable amount of the price.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4,"gte":"0"}
        - name: rate | type: string | description: Tax rate used for this jurisdiction, as a decimal. For example, 10% tax is `"0.1000"` and 200% tax is `"2.0000"`.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":6,"gte":"0"}
        - name: taxAmount | type: string | description: Amount of this tax calculated for this jurisdiction.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
        - name: taxableAmount | type: string | description: Taxable amount of the price.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4,"gte":"0"}
        - name: taxType | type: string | description: Type of tax that was calculated. For example, `"Sales Tax"`, `"Income Tax"`, `"Value Added Tax"`, etc.  | validation: maxLength 200
        - name: taxName | type: string | description: Name of the tax that was calculated. For example, `"NY State Sales Tax"`, `"Quebec GST"`, etc.  | validation: maxLength 200
        - name: jurisdictionType | type: JurisdictionType | description: Type of jurisdiction that taxes were calculated for. For example, `"State"`, `"County"`, `"City"`, `"Special"`, etc.  
             - enum: UNDEFINED, COUNTRY, STATE, COUNTY, CITY, SPECIAL
     - name: taxSummary | type: LineItemTaxSummary | description: Summary of this line item's total price and tax.  
        - name: fullPrice | type: string | description: Total price for this line item. To determine the price for each individual unit of this line item, divide by `quantity`.  | validation: format DECIMAL_VALUE, decimalValue {"lte":"1000000000000000"}
        - name: taxAmount | type: string | description: The total amount of tax calculated for this line item.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
        - name: taxableAmount | type: string | description: Total taxable amount for this line item.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}


```

### Examples

### Calculate Tax
Trigger a tax calculation for a given set of line items and their addresses.

```curl
curl -X POST 'https://provider.example.com/v1/calculate-tax' \
--header 'accept: application/json, text/plain, */*' \
--header 'accept-language: en-US,en;q=0.9' \
--header 'authorization: <AUTH>' \
--header 'content-type: application/json' \
--data '{
  "lineItems": [
    {
      "id": "item123",
      "item_name": "some",
      "price": "123",
      "tax_group_id": "56ce0f07-adda-4419-9d16-1af86b2ed284",
      "tax_included": false,
      "address_index": {
        "single_address": 0
      },
      "quantity": 4
    }
  ],
  "addresses": [
    {
      "country": "US",
      "subdivision": "TX",
      "postal_code": "76248",
      "address_line": "296 Valley View Street Keller, TX 76248"
    }
  ],
  "currency": "USD"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.billing.taxCalculationProvider.calculateTax(request, metadata)
 Description: Calculates tax for the provided line items.  Wix calls this method whenever tax needs to be recalculated on a site, for example when a site visitor views their cart, begins checkout, or changes cart contents. Wix groups the line items by the tax calculator bound to each item's tax region and calls the corresponding provider.  Wix uses the returned tax breakdown to display tax on the cart and checkout pages and to calculate the order total.  Calculate tax for each line item based on the tax region in `lineItems.taxRegionId` and the tax group in `lineItems.taxGroupId`. The response `currency` must match the request `currency`, otherwise the response is invalid. Return: + `taxSummary`: The overall total tax calculated. + `lineItemTaxDetails.taxBreakdown`: The tax calculated for each line item in each jurisdiction. + `lineItemTaxDetails.taxSummary`: The total tax calculated for each line item.  *Error handling:** If your implementation returns an error or times out, Wix falls back to the Wix manual tax calculator. If that also fails, the order proceeds with zero tax and a calculation error. A resolved buyer exemption bypasses third-party providers and forces the Wix manual calculator.
 Method parameters:
   param name: request | type: CalculateTaxRequest | description: Items and information to calculate tax for.  
        - name: currency | type: string | description: 3-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format.  | validation: format CURRENCY
        - name: addresses | type: array<Address> | description: Array of addresses. Each line item can individually reference the address to apply with `lineItems.addressIndex`.  | validation: minItems 1, maxItems 3
           - name: city | type: string | description: none  
           - name: subdivision | type: string | description: none  
           - name: country | type: string | description: none  
           - name: postalCode | type: string | description: none  
           - name: addressLine2 | type: string | description: none  
        - name: lineItems | type: array<LineItem> | description: Line items to calculate tax for.  | validation: minItems 1, maxItems 300
           - name: _id | type: string | description: Line item GUID.  | validation: minLength 1, maxLength 100
           - name: itemName | type: string | description: Line item name to display.  | validation: minLength 0, maxLength 250
           - name: quantity | type: integer | description: Line item quantity.  | validation: minimum 1, maximum 100000
           - name: price | type: string | description: Line item price.  | validation: format DECIMAL_VALUE, decimalValue {"lte":"1000000000000000"}
           - name: itemCode | type: string | description: Stock keeping unit for this line item. Learn more about [SKUs](https://www.wix.com/encyclopedia/definition/stock-keeping-unit-sku).  | validation: maxLength 40
           - name: taxGroupId | type: string | description: Tax group GUID for this line item. If not provided, the default tax group applies.  | validation: format GUID
           - name: taxIncludedInPrice | type: boolean | description: Whether tax is included in the price.  
           - name: addressIndex | type: AddressIndex | description: Index of the address from `addresses` to use to calculate tax for this specific line item. The index is zero-based.  
              - ONE-OF: 
                 - name: singleAddress | type: integer | description: Single address to use for a sale location when only one address is required for tax calculations. The index is zero-based.  
                 - name: multipleAddresses | type: MultipleAddresses | description: Multiple addresses to use for a sale. For example, some tax calculations may require both the address where an item is shipped from, as well as the address the item is shipped to.  
                    - name: origin | type: integer | description: Index of the origin address.  
                    - name: destination | type: integer | description: Index of the destination address.  
           - name: taxRegionId | type: string | description: Tax region GUID for this line item.  | validation: format GUID
   param name: metadata | type: Context | description: this message is not directly used by any service, it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform. e.g. SPIs, event-handlers, etc.. NOTE: this context object MUST be provided as the last argument in each Velo method signature.  Example: ```typescript export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) { ... } ```  
        - name: requestId | type: string | description: A unique identifier of the request. You may print this GUID to your logs to help with future debugging and easier correlation with Wix's logs.  
        - name: currency | type: string | description: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code.  | validation: format CURRENCY
        - name: identity | type: IdentificationData | description: An object that describes the identity that triggered this request.  
           - ONE-OF: 
              - name: anonymousVisitorId | type: string | description: GUID of a site visitor that has not logged in to the site.  | validation: format GUID
              - name: memberId | type: string | description: GUID of a site visitor that has logged in to the site.  | validation: format GUID
              - name: wixUserId | type: string | description: GUID of a Wix user (site owner, contributor, etc.).  | validation: format GUID
              - name: appId | type: string | description: GUID of an app.  | validation: format GUID
        - name: languages | type: array<string> | description: A string representing a language and region in the format of `"xx-XX"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash "-", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `"en-US"`.  
        - name: instanceId | type: string | description: The service provider app's instance GUID.  | validation: format GUID
 Return type: PROMISE<CalculateTaxResponse>
  - name: currency | type: string | description: 3-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. If this code doesn't match the `currency` passed in the request, then the response is invalid.  | validation: format CURRENCY
  - name: taxSummary | type: TaxSummary | description: Summary of the tax calculated.  
     - name: totalAmount | type: string | description: Total price for all line items.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
     - name: totalTax | type: string | description: Total amount of tax calculated for all line items. Note that due to rounding, `totalTax` may not equal the sum of `lineItemTaxDetails.taxSummary.taxAmount`.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
     - name: totalTaxableAmount | type: string | description: Total taxable amount for all line items.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
     - name: totalTaxIncludedInPrice | type: string | description: Total amount of `totalTax` that is included in price. Applies to line items with `taxIncludedInPrice` set to `true`.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
  - name: lineItemTaxDetails | type: array<LineItemTaxDetails> | description: Details of each tax applied to each line item.  | validation: minItems 1, maxItems 300
     - name: _id | type: string | description: Line item GUID.  | validation: minLength 1, maxLength 100
     - name: itemName | type: string | description: Line item name to display.  | validation: minLength 0, maxLength 250
     - name: quantity | type: integer | description: Line item quantity.  | validation: minimum 1, maximum 100000
     - name: taxBreakdown | type: array<TaxBreakdown> | description: Array of each tax applied, grouped by `jurisdiction`, `jurisdictionType`, `taxName`, `rate`, and `taxType`.  | validation: maxItems 7
        - name: jurisdiction | type: string | description: Jurisdiction that taxes were calculated for.  | validation: maxLength 200
        - name: nonTaxableAmount | type: string | description: Non-taxable amount of the price.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4,"gte":"0"}
        - name: rate | type: string | description: Tax rate used for this jurisdiction, as a decimal. For example, 10% tax is `"0.1000"` and 200% tax is `"2.0000"`.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":6,"gte":"0"}
        - name: taxAmount | type: string | description: Amount of this tax calculated for this jurisdiction.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
        - name: taxableAmount | type: string | description: Taxable amount of the price.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4,"gte":"0"}
        - name: taxType | type: string | description: Type of tax that was calculated. For example, `"Sales Tax"`, `"Income Tax"`, `"Value Added Tax"`, etc.  | validation: maxLength 200
        - name: taxName | type: string | description: Name of the tax that was calculated. For example, `"NY State Sales Tax"`, `"Quebec GST"`, etc.  | validation: maxLength 200
        - name: jurisdictionType | type: JurisdictionType | description: Type of jurisdiction that taxes were calculated for. For example, `"State"`, `"County"`, `"City"`, `"Special"`, etc.  
             - enum: UNDEFINED, COUNTRY, STATE, COUNTY, CITY, SPECIAL
     - name: taxSummary | type: LineItemTaxSummary | description: Summary of this line item's total price and tax.  
        - name: fullPrice | type: string | description: Total price for this line item. To determine the price for each individual unit of this line item, divide by `quantity`.  | validation: format DECIMAL_VALUE, decimalValue {"lte":"1000000000000000"}
        - name: taxAmount | type: string | description: The total amount of tax calculated for this line item.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}
        - name: taxableAmount | type: string | description: Total taxable amount for this line item.  | validation: format DECIMAL_VALUE, decimalValue {"maxScale":4}


```

### Examples

### Example of an `taxCalculationProvider` return value
```javascript
import { taxCalculationProvider } from '@wix/ecom/service-plugins'

taxCalculationProvider.provideHandlers({
  calculateTax: async (payload) => {

    const {request, metadata} = payload;
        // Use the `request` and `metadata` received from Wix and
        // apply custom logic.
      return {
        "currency": "USD",
        "lineItemTaxDetails": [
          {
            "_id": "205c539b-fd89-4b0c-8d7e-55630f66e5f9",
            "itemName": "Wireless Headphones",
            "quantity": 2,
            "taxBreakdown": [
              {
                "jurisdiction": "State of California",
                "jurisdictionType": "STATE",
                "nonTaxableAmount": "0.00",
                "rate": "0.0750",
                "taxAmount": "3.00",
                "taxName": "California State Sales Tax",
                "taxType": "Sales Tax",
                "taxableAmount": "40.00"
              },
              {
                "jurisdiction": "City of Los Angeles",
                "jurisdictionType": "CITY",
                "nonTaxableAmount": "0.00",
                "rate": "0.01",
                "taxAmount": "0.40",
                "taxName": "Los Angeles City Sales Tax",
                "taxType": "Sales Tax",
                "taxableAmount": "40.00"
              }
            ],
            "taxSummary": {
              "fullPrice": "100.00",
              "taxAmount": "3.40",
              "taxableAmount": "40.00"
            }
          }
        ],
        "taxSummary": {
          "totalAmount": "103.40",
          "totalTax": "3.40",
          "totalTaxIncludedInPrice": "0.00",
          "totalTaxableAmount": "40.00"
        }
      }

  }
});


```

### calculateTax (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { taxCalculationProvider } from '@wix/billing/service-plugins';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { taxCalculationProvider },
  // Include the auth strategy and host as relevant
});


async function calculateTax(request,metadata) {
  const response = await myWixClient.taxCalculationProvider.calculateTax(request,metadata);
};
```

---