TaxEngineAdapter Interface

Retrieves information from the tax engine and evaluates the information to define tax details.

CommerceTax

  • TaxEngineAdapter Methods

    Learn more about the available methods with the TaxEngineAdapter class.

  • TaxEngineAdapter Example Implementation

    Refer to the example implementation of the TaxEngineAdapter interface to accept information from a tax engine and evaluate the information to define tax details.

  • Tax Mappings for Quotes and Orders

    You can extend and customize the tax interface for quotes and orders by using custom metadata types and tax mappings. These customizations help you with unique business requirements such as the inclusion of specific data for accurate calculations and audits.

Learn more about the available methods with the TaxEngineAdapter class.

The TaxEngineAdapter class includes these methods.

  • processRequest(requestType)

    The processRequest method takes an instance of TaxEngineContext class and returns a response with the calculated tax details through the TaxDetailsResponse class or an error response through the ErrorResponse class.

The processRequest method takes an instance of TaxEngineContext class and returns a response with the calculated tax details through the TaxDetailsResponse class or an error response through the ErrorResponse class.

global commercetax.TaxEngineResponse processRequest(commercetax.TaxEngineContext var1)

  • var1:

    Type: TaxEngineContext

    Wrapper class that stores information about

    the type of a tax calculation request.

Type: TaxEngineResponse

Generic interface representing a response from a tax engine.

Refer to the example implementation of the TaxEngineAdapter interface to accept information from a tax engine and evaluate the information to define tax details.

commercetax

The TaxEngineAdapter interface accepts information from the tax engine through the TaxEngineContext class. The interface evaluates the information to define tax in the response with details, such as tax amount and addresses. The response is used to update and create entities in the Salesforce org.

Use these steps to build a sample tax adapter implementation. Each tax adapter implementation varies based on your implementation requirements. Customize this example to suit your business requirements.

  • The custom adapter class implements the TaxEngineAdapter interface. The processRequest method takes an instance of TaxEngineContext class and returns a response with the calculated tax details through the TaxDetailsResponse class or an error response through the ErrorResponse class.

  • This example shows the CalculateTaxService class.

  • In the HttpService class, replace the test value in the endpoint variable with the name of the TaxTypedNamedCredential record. This class contains the credentials that are required to access your Avalara account through Salesforce.

  • Parse the JsonSuccessParser response object by using the AvalaraJSONBuilder class to build the response for your adapter.

    This example shows the JsonSuccessParser class.

Prepare your JSON request to call the Avalara endpoint by using the AvalaraJSONBuilder class.

  • Use the JsonErrorParser class to extract the error details, if any.

You can extend and customize the tax interface for quotes and orders by using custom metadata types and tax mappings. These customizations help you with unique business requirements such as the inclusion of specific data for accurate calculations and audits.

Tax callout extensions are supported for the Quote, QuoteLineItem, Order, and OrderItem objects to include additional fields to tax requests. See custom metadata types to specify all your tax mapping definitions.

This table defines the request mappings between the header attributes of a tax callout and fields of applicable quote and order objects.

Header AttributesQuote MappingOrder Mapping
currencyIsoCodeIf multi-currency is enabled, then this value is Quote.CurrencyISOCode. Otherwise, this value is NULL.If multi-currency is enabled, then this value is Order.CurrencyISOCode. Otherwise, this value is NULL.
isCommitFalseFalse
referenceEntityIdQuote.IDOrder.ID
taxEngineIdTaxTreatment.TaxEngine.IDTaxTreatment.TaxEngine.ID
transactionDateCurrent System DateSystem Date
sellerDetailsNULL 
code TaxEngine.SellerCode
customerDetails  
accountIdQuote.AccountIdOrder.AccountId
codeNULLNULL
exemptionNoNULLNULL
exemptionReasonNULLNULL
taxTypeEstimatedEstimated
taxTransactionTypeNULLNULL
effectiveDateNULLNULL
addresses  
billToNULLNULL
shipToNULLNULL
shipFromNULLNULL
soldToNULLNULL
taxEngineAddressTaxEngine.AddressTaxEngine.Address
referenceDocumentCodeNULLNULL
descriptionNULLNULL
documentCodeQuote.ID-TaxEngineIdOrder.ID-TaxEngineId
shouldVoidFALSEFALSE
lineItemsRefer to the next line attributes section.Refer to the next line attributes section.

This table defines the request mappings between the line attributes of a tax callout and fields of applicable quote line items and order products.

Line AttributesQuote Line Item MappingOrder Product Mapping
taxCodeTaxTreatment.TaxCodeTaxTreatment.TaxCode
productCodeTaxTreatment.ProductCodeTaxTreatment.ProductCode
productIdQuoteLineItem.Product2.IdOrderItem.Product2.Id
amountQuoteLineItem.TotalPriceOrderItem.TotalPrice
effectiveDateCurrent System DateCurrent System Date
lineNumberQuoteLineItem.IdOrderItem.Id
descriptionNULLNULL
quantityQuoteLineItem.QuantityOrderItem.Quantity
addresses  
billToQuote.BillingAddress. If Quote.BillingAddress is null, then this value is Quote.Account.BillingAddress.Order.BillingAddress
shipToQuote.ShippingAddress. If Quote.ShippingAddress is null, then this value is Quote.Account.ShippingAddress.Order.ShippingAddress
shipFromNULLNULL
soldToNULLNULL
productskuQuoteLineItem.Product2.ProductCodeOrderItem.Product2.ProductCode
referenceDocumentCodeNULLNULL

This table defines the response mappings between the header attributes of a tax callout and fields of applicable objects. Most response data is used for tax calculation and isn’t persisted on quote or order records.

Header AttributesQuote MappingOrder Mapping
currencyIsoCodeQuote.CurrencyISOCodeOrder.CurrencyISOCode
isCommitNot returned.Not returned.
referenceEntityIdQuote.IDOrder.ID
taxEngineIdTaxTreatment.TaxEngine.IDTaxTreatment.TaxEngine.ID
transactionDateSystem DateSystem Date
sellerDetailsNot returned.Not returned.
codeNot returned.Not returned.
customerDetailsNot returned.Not returned.
accountIdNot returned.Not returned.
codeNot returned.Not returned.
exemptionNoNot returned.Not returned.
exemptionReasonNot returned.Not returned.
taxTypeEstimatedEstimated
taxTransactionTypeNot returned.Not returned.
effectiveDateSystem DateSystem Date
addresses  
billToNot returned.Not returned.
shipTolocationCode -> locationCodelocationCode -> locationCode
shipFromNot returned.Not returned.
soldToNot returned.Not returned.
taxEngineAddressNot returned.Not returned.
referenceDocumentCodeNot returned.Not returned.
descriptionNot returned.Not returned.
documentCodeQuote.ID-TaxEngineIdOrder.ID-TaxEngineId
statusUncommittedUncommitted
taxEngineLogsNot returned.Not returned.
resultCodeNot returned.Not returned.
transactionDateSystem DateSystem Date
amountDetails  
exemptAmountActual exemptAmount from response.Actual exemptAmount from response.
taxAmountActual taxAmount from response.Actual taxAmount from response.
totalAmountQuote.SubtotalOrder.Subtotal
totalAmountWithTaxTaxAmount + TotalAmountTaxAmount + TotalAmount
lineItemsRefer to the next line attributes section.Refer to the next line attributes section.

This table defines the response mappings between the line attributes of a tax callout and fields of applicable objects.

Line AttributesQuote Line Item MappingOrder Product Mapping
taxCodeTaxTreatment.TaxCodeTaxTreatment.TaxCode
productCodeTaxTreatment.ProductCodeTaxTreatment.ProductCode
productIdNot returned.Not returned.
amountDetails  
exemptAmountActual exemptAmount from responseActual exemptAmount from response
taxAmountActual taxAmount from responseActual taxAmount from response
totalAmountQuoteLineItem.SubtotalOrderItem.Subtotal
totalAmountWithTaxTaxAmount + TotalAmountTaxAmount + TotalAmount
effectiveDateSystem DateSystem Date
lineNumberQuoteLineItem.IdOrderItem.Id
descriptionNot returned.Not returned.
quantityNot returned.Not returned.
addresses  
billToNot persisted.Not persisted.
shipTolocationCode -> locationCodelocationCode -> locationCode
shipFromNot returned.Not returned.
soldToNot returned.Not returned.
productskuNot returned.Not returned.
referenceDocumentCodeNot returned.Not returned.
taxesRefer to the next tax attributes section.Refer to the next tax attributes section.

This table defines the response mappings between the tax attributes of a tax callout and fields of applicable objects.

Tax AttributesQuote MappingOrder Mapping
exemptAmountNot returned.Not returned.
exemptReasonNot returned.Not returned.
imposition  
typeNot returned.Not returned.
NameNot returned.Not returned.
jurisdiction  
countryNot returned.Not returned.
idNot returned.Not returned.
levelNot returned.Not returned.
nameNot returned.Not returned.
regionNot returned.Not returned.
stateAssignedNoNot returned.Not returned.
rateQuoteItemTaxItem.RateOrderItemTaxItem.Rate
taxQuoteItemTaxItem.amountOrderItemTaxItem.amount
taxIdNot returned.Not returned.
taxableAmountNot returned.Not returned.