Newer Version Available

This content describes an older version of this product. View Latest

LineItemResponse Class

Response class that stores details of a list of one or more line items on which the tax engine has calculated tax.

Namespace

CommerceTax

Example

This example uses a LineItemResponse list to store information about each line item that was processed as part of the request. For simplicity, the sample code uses a static value of 1 for the tax rate. However, most integrations typically have a more complex process for determining a tax rate. Most integrations also build a TaxDetailsResponse list to store the actual tax value information that they assign to each line item in the LineItemResponse list.

1Double totalTax = 0.0;
2             Double totalAmount = 0.0;
3             List<commercetax.LineItemResponse> lineItemResponses = new List<commercetax.LineItemResponse>();
4             for(Commercetax.TaxLineItemRequest lineItem : request.lineItems){
5                 commercetax.AddressesResponse addressesRes = new commercetax.AddressesResponse();
6                 if(request.DocumentCode == 'SetsNullForResponseWithoutException'){
7                     addressesRes.setShipFrom(null);
8                     addressesRes.setShipTO(null);
9                     addressesRes.setSoldTo(null);
10                 }else{
11                     commercetax.AddressResponse addRes = new commercetax.AddressResponse();
12                     addRes.setLocationCode('locationCode');
13                     addressesRes.setShipFrom(addRes);
14                     addressesRes.setShipTO(addRes);
15                     addressesRes.setSoldTo(addRes);
16                 }
17                 commercetax.LineItemResponse lineItemResponse = new commercetax.LineItemResponse();
18                 Double totalLineTax = 0;
19                 List<commercetax.TaxDetailsResponse> taxDetailsResponses = new List<commercetax.TaxDetailsResponse>();
20                 for(integer i =0;i<1;i++){
21                     Integer rate  = 1;
22                     Double taxableAmount = lineItem.amount;
23                     commercetax.TaxDetailsResponse taxDetailsResponse = new commercetax.TaxDetailsResponse();
24                     taxDetailsResponse.setRate(Double.valueOf(rate));
25                     taxDetailsResponse.setTaxableAmount(taxableAmount);
26                     Double tax = taxableAmount*rate;
27                     totalLineTax+=tax;
28                     taxDetailsResponse.setTax(taxableAmount*rate);
29                     taxDetailsResponse.setExemptAmount(0);
30                     taxDetailsResponse.setExemptReason('exemptReason');
31                     taxDetailsResponse.setTaxRegionId('taxRegionId');
32                     taxDetailsResponse.setTaxId(String.valueOf(getRandomInteger(0,2323233)));
33                     taxDetailsResponse.setSerCode('serCode');
34                     taxDetailsResponse.setTaxAuthorityTypeId('taxAuthorityTypeId');
35                     if(request.DocumentCode == 'SetsNullForResponseWithoutException'){
36                         taxDetailsResponse.setImposition(null);
37                     }else{
38                         commercetax.ImpositionResponse imposition = new commercetax.ImpositionResponse();
39                         imposition.setSubType('subtype');
40                         imposition.setType('type');
41                         taxDetailsResponse.setImposition(imposition);
42                     }
43 
44                     if(request.DocumentCode == 'SetsNullForResponseWithoutException'){
45                         taxDetailsResponse.setJurisdiction(null);
46                     }else{
47                         commercetax.JurisdictionResponse jurisdiction = new commercetax.JurisdictionResponse();
48                         jurisdiction.setCountry('country');
49                         jurisdiction.setRegion('region');
50                         jurisdiction.setName('name');
51                         jurisdiction.setStateAssignedNumber('stateAssignedNo');
52                         jurisdiction.setId('id');
53                         jurisdiction.setLevel('level');
54                         taxDetailsResponse.setJurisdiction(jurisdiction);
55                     }
56 
57                     taxDetailsResponses.add(taxDetailsResponse);
58                 }
59                 lineItemResponse.setTaxes(taxDetailsResponses);
60                 totalTax +=totalLineTax;
61                 totalAmount+=lineItem.amount;

LineItemResponse Methods

Learn more about the available methods with the LineItemResponse class.

The LineItemResponse class includes these methods.

setAddresses(addresses)

Sets the Addresses field on the LineItemResponse using an instance of AddressesResponse class.

Signature

global void setAddresses(commercetax.AddressesResponse addresses)

Parameters

addresses
Type: AddressesResponse
Class that contains methods to set the Ship To, Ship From, and Sold To address information.

Return Value

Type: void

setAmountDetails(amountDetails)

Sets the Amount Details field on the LineItemResponse using an instance of AmountDetails.

Signature

global void setAmountDetails(commercetax.AmountDetailsResponse amountDetails)

Parameters

amountDetails
Type: AmountDetailsResponse
Class that contains methods to set the tax amount, total amount with tax, total amount, and exempt amount.

Return Value

Type: void

setEffectiveDate(effectiveDate)

Sets the EffectiveDate field on the LineItemResponse class. Effective Date fields are optional fields that store the date that a transaction takes effect. We provide these fields only for recordkeeping purposes – for example, if you must report an effective date to an external general ledger system. Salesforce doesn't use them to calculate any tax or payment values.

Signature

global void setEffectiveDate(Datetime effectiveDate)

Parameters

effectiveDate
Type: Datetime
Optional field that stores the date that a transaction takes effect.

Return Value

Type: void

setIsTaxable(isTaxable)

Sets the IsTaxable field on the LineItemResponse class.

Signature

global void setIsTaxable(Boolean isTaxable)

Parameters

isTaxable
Type: Boolean
Whether line items were taxed as part of the tax calculation request.

Return Value

Type: void

setLineNumber(lineNumber)

Sets the LineNumber field on the LineItemResponse class.

Signature

global void setLineNumber(String lineNumber)

Parameters

lineNumber
Type: String
User-defined number used to identify a line item.

Return Value

Type: void

setProductCode(productCode)

Sets the ProductCode field on the LineItemResponse class.

Signature

global void setProductCode(String productCode)

Parameters

productCode
Type: String
Code for the product that a line item represents.

Return Value

Type: void

setQuantity(quantity)

Sets the Quantity field on the LineItemResponse class.

Signature

global void setQuantity(Double quantity)

Parameters

quantity
Type: Double
Quantity of a line item.

Return Value

Type: void

setTaxCode(taxCode)

Sets the TaxCode field on the LineItemResponse.

Signature

global void setTaxCode(String taxCode)

Parameters

taxCode
Type: String
Federal code that an individual or business uses to pay their taxes to a federal or state government. The tax engine uses this code during the tax calculation process.

Return Value

Type: void

setTaxes(taxes)

Sets the Taxes field on a LineItemResponse.

Signature

global void setTaxes(List<commercetax.TaxDetailsResponse> taxes)

Parameters

taxes
Type: List<TaxDetailsResponse>
Tax values applied to a line item in the LineItemResponse list. This information is stored in a list of TaxDetailsResponses, which contains values such as tax, taxable amount, and tax rate.

Return Value

Type: void