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.
LineItemResponse Class
Namespace
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
The LineItemResponse class includes these methods.
setAddresses(addresses)
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)
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
setCustomTaxAttributes(customTaxAttributes)
Signature
global void setCustomTaxAttributes(commercetax.CustomTaxAttributesResponse customTaxAttributes)
Parameters
-
customTaxAttributes:
Type: CustomTaxAttributesResponse
Additional
data or custom attributes to include in the tax response.
Return Value
Type: void
setEffectiveDate(effectiveDate)
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)
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)
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)
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)
Signature
global void setQuantity(Double quantity)
Parameters
-
quantity:
Type: Double
Quantity of a line item.
Return Value
Type: void
setTaxCode(taxCode)
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)
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