Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

CalculateTaxResponse Class

Sets the values of the tax transaction following a response from the external tax engine. Extends the AbstractTransactionResponse class and is the top-level response class.

Namespace

CommerceTax

Example

1if(requestType == commercetax.RequestType.CalculateTax){
2             commercetax.calculatetaxtype type = request.taxtype;
3             String docCode='';
4             if(request.DocumentCode == 'simulateEmptyDocumentCode')
5                 docCode = '';
6             else if(request.DocumentCode != null)
7                 docCode =request.DocumentCode;
8             else if(request.ReferenceEntityId != null) docCode = request.ReferenceEntityId;
9             else docCode =  String.valueOf(getRandomInteger(0,2147483647));
10             commercetax.CalculateTaxResponse response = new commercetax.CalculateTaxResponse();
11             if(request.isCommit == true) {
12                 response.setStatus(commercetax.TaxTransactionStatus.Committed);
13             } else {
14                 response.setStatus(commercetax.TaxTransactionStatus.Uncommitted);
15             }
16             response.setDocumentCode(docCode);
17             response.setReferenceDocumentCode(request.referenceDocumentCode);
18             response.setTaxType(type);
19             response.setStatusDescription('statusDescription');
20             if(request.sellerDetails.code == 'testSellerCode') {
21                 response.setDescription('SellerCode fetched from TaxEngine entity');
22             }
23             else {
24                 response.setDescription('description');
25             }
26            response.setEffectiveDate(system.now());
27            if(request.transactionDate == null) {
28               response.setTransactionDate(system.now());
29            } else {
30               response.setTransactionDate(request.transactionDate);
31            }
32            if(request.taxTransactionType == null) {
33                response.setTaxTransactionType(commercetax.TaxTransactionType.Debit);
34            } else {
35                response.setTaxTransactionType(request.taxTransactionType);
36            }
37             if(request.currencyIsoCode == null || request.currencyIsoCode == '') {
38                response.setCurrencyIsoCode('USD');
39             } else {
40                response.setCurrencyIsoCode(request.currencyIsoCode);
41             }
42             response.setReferenceEntityId(request.ReferenceEntityId);
43}

CalculateTaxResponse Methods

Learn more about the available methods with the CalculateTaxResponse class.

The CalculateTaxResponse class includes these methods.

setAddresses(addresses)

Sets the value of the Addresses field using the addresses contained in an instance of the AddressesResponse class.

Signature

global void setAddresses(commercetax.AddressesResponse addresses)

Parameters

  • addresses:

    Type: AddressesResponse

    Contains Ship To, Ship From, and Sold To addresses.

Return Value

Type: void

setAmountDetails(amountDetails)

Sets the value of the AmountDetails field using an instance of AmountDetailsResponse.

Signature

global void setAmountDetails(commercetax.AmountDetailsResponse amountDetails)

Parameters

  • amountDetails:

    Type: AmountDetailsResponse

    The tax amount details for a line item on which tax was calculated.

Return Value

Type: void

setCurrencyIsoCode(currencyIsoCode)

Sets the value of the CurrencyIsoCode field of the CalculateTaxResponse object.

Signature

global void setCurrencyIsoCode(String currencyIsoCode)

Parameters

  • currencyIsoCode:

    Type: String

    Three-letter ISO 4217 currency code associated with a tax object.

Return Value

Type: void

setDescription(dscptn)

Sets the value of the Description field of the CalculateTaxResponse object.

Signature

global void setDescription(String dscptn)

Parameters

  • dscptn:

    Type: String

    Optional description for providing more information about the calculate tax response.

Return Value

Type: void

setDocumentCode(documentCode)

Sets the value of the DocumentCode field of the CalculateTaxResponse object.

Signature

global void setDocumentCode(String documentCode)

Parameters

  • documentCode:

    Type: String

    Code

    for a tax document that’s created by the tax engine for the calculation process.

Return Value

Type: void

setEffectiveDate(effectiveDate)

Sets the value of the EffectiveDate field of the CalculateTaxResponse object.

Signature

global void setEffectiveDate(Datetime effectiveDate)

Parameters

  • effectiveDate:

    Type: Datetime

    The date a tax calculation action takes effect. This parameter is optional and is provided only for recordkeeping purpose. Additionally, this parameter is used to determine the tax rates or rules and overrides the transaction date. For example, if the tax calculation request is placed on January 3 and the transaction date is January 1, you can set the effective date as January 1.

Return Value

Type: void

setLineItems(lineItems)

Sets the value of the LineItems field of the CalculateTaxResponse object.

Signature

global void setLineItems(List<commercetax.LineItemResponse> lineItems)

Parameters

  • lineItems:

    Type: List<LineItemResponse>

    Response object that the tax adapter populates from the response of the external tax engine.

Return Value

Type: void

setReferenceDocumentCode(referenceDocumentCode)

Sets the value of the ReferenceDocumentCode field of the CalculateTaxResponse object.

Signature

global void setReferenceDocumentCode(String referenceDocumentCode)

Parameters

  • referenceDocumentCode:

    Type: String

    Code

    for a reference document used in the tax calculation process.

Return Value

Type: void

setReferenceEntityId(referenceEntityId)

Sets the value of the ReferenceEntityId field of the CalculateTaxResponse object.

Signature

global void setReferenceEntityId(String referenceEntityId)

Parameters

  • referenceEntityId:

    Type: String

    ID of an entity related to the line items submitted for tax calculation. For example, if order items were sent for tax calculation, you could use the ID of their parent order.

Return Value

Type: void

setStatus(status)

Sets the value of the Status field of the CalculateTaxResponse object.

Signature

global void setStatus(commercetax.TaxTransactionStatus status)

Parameters

Return Value

Type: void

setStatusDescription(statusDescription)

Sets the value of the StatusDescription field of the CalculateTaxResponse object.

Signature

global void setStatusDescription(String statusDescription)

Parameters

  • statusDescription:

    Type: String

    Optional value for providing more information about a tax transaction's status.

Return Value

Type: void

setTaxTransactionId(taxTrxnId)

Sets the value of the TaxTransactionId field of the CalculateTaxResponse object.

Signature

public void setTaxTransactionId(String taxTrxnId)

Parameters

  • taxTrxnId:

    Type: String

    The ID of the Salesforce tax transaction entity that stores information about the tax calculation transaction.

Return Value

Type: void

setTaxTransactionType(taxTransactionType)

Sets the value of the TaxTransactionType field of the CalculateTaxResponse object.

Signature

global void setTaxTransactionType(commercetax.TaxTransactionType taxTransactionType)

Parameters

  • taxTransactionType:

    Type: TaxTransactionType

    Whether the tax transaction was for a credit, debit, or voided transaction.

Return Value

Type: void

setTaxType(taxType)

Sets the value of the TaxType field of the CalculateTaxResponse object.

Signature

global void setTaxType(commercetax.CalculateTaxType taxType)

Parameters

  • taxType:

    Type: CalculateTaxType

    Indicates whether a tax calculation request is for estimated or actual tax.

Return Value

Type: void

setTransactionDate(transactionDate)

Sets the value of the TransactionDate field of the CalculateTaxResponse object.

Signature

global void setTransactionDate(Datetime transactionDate)

Parameters

  • transactionDate:

    Type: Datetime

    The date that the tax transaction occurred.

Return Value

Type: void