Calculates tax for the provided line items.
Tax is calculated for each line item based on the tax region
in lineItems.taxRegionId
and the tax group in lineItems.taxGroupId
.
The breakdown of calculated tax returned, includes:
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.calculateTax()
When you add the Tax Calculation service plugin,
a folder is automatically added to your site. Use the .js
file in the folder to write the code to determine how to calculate tax for an order.
function calculateTax(
options: Options,
context: Context,
): Promise<TaxCalculationResponse>;
Order information to calculate tax for.
Metadata about the request.
export const calculateTax = async (options, context) => {
return {
currency: "USD",
taxSummary: {
totalAmount: "170.00",
totalTax: "21.00",
totalTaxableAmount: "170.00",
totalTaxIncludedInPrice: "0.00",
},
lineItemTaxDetails: [
{
_id: "00000000-0000-0000-0000-000000000001",
itemName: "some",
quantity: 1,
taxBreakdown: [
{
jurisdiction: "TEXAS",
jurisdictionType: taxCalculationProvider.JurisdictionType.STATE,
nonTaxableAmount: "0.00",
rate: "0.20",
taxAmount: "15.00",
taxableAmount: "120.00",
taxType: "Sales",
taxName: "TX STATE TAX",
},
],
taxSummary: {
fullPrice: "120.00",
taxAmount: "12.00",
taxableAmount: "120.00",
},
},
{
_id: "shipping",
itemName: "Free Shipping",
quantity: 1,
taxBreakdown: [
{
jurisdiction: "",
nonTaxableAmount: "0",
rate: "0.12",
taxAmount: "6.00",
taxName: "",
taxType: "",
taxableAmount: "50",
},
],
taxSummary: {
fullPrice: "50",
taxAmount: "6.00",
taxableAmount: "50.00",
},
},
],
};
};
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.