This API enables you to calculate tax breakups for cart line item.

APISignature
computeTaxForCartwebService static Apttus_CPQApi.CPQ.ComputeTaxResponseDO computeTaxForCart(Apttus_CPQApi.CPQ.ComputeTaxRequestDO request)


Parameters
NameTypeDescription
requestApttus_CPQApi.CPQ.ComputeTaxRequestDOThe compute tax request object.


Request Data Object - Apttus_CPQApi.CPQ.ComputeTaxRequestDO
FieldTypeDescription
CartIDIDThe id of the cart.


Response Data Object - Apttus_CPQApi.CPQ.ComputeTaxResponseDO
FieldTypeDescription
TaxResultsMap<ID, Apttus_Config2.CustomClass.TaxResult>The Tax Result object populated by the line item id. This is only available when called from Apex.
TotalTaxItemApttus_Config2__LineItem__cThe line item with total taxes.


Data Object - Apttus_Config2.CustomClass.TaxResult
FieldTypeDescription
HandbackObjectAny Apex Object passed by the calling class and passed back to the calling class in the result.

Handback is used only in case when the tax needs to be calculated for an object other than Cart line item e.g. Billing Schedule line items.

  • For calculating tax for cart line items, there is no need to pass the Handback object. It can be blank

  • For calculating the tax for object other than line items, "Item" field will be blank and the actual object will be passed as handback object to identify object for which tax is calculated.

TaxAmountDecimalThis is the total amount for the line item. This is sum of the breakup tax amounts for the line item. Line item is identified by the sequence in which the tax result is added. This needs to be calculated and populated by the implementation.
TaxBreakupsList<Apttus_Config2__TaxBreakup_c>Tax breakup provide the different components of the tax for a given line item. This needs to be implemented and provided by the implementation. Tax breakup has structure specified below.


Data Object - Apttus_Config2__TaxBreakup_c
FieldTypeDescription
BreakupTypeStringIf you specify the breakup type as Detail, then the quote or order line items show the detailed tax break up for a cart line item.
TaxAmountDecimalThe tax amount calculated based on the formulae defined in the callback.
TaxAppliesToStringThe field on which the tax is applied to. For example, net price.
TaxRateDecimalTax percentage to be applied
TaxTypeStringType of tax to be applied. For example, sales, custom, excise.


Tax Breakup Type Example
Breakup TypeTax TypeTax RateTax Applies toTax Amount
DetailState Tax10Net Price100
DetailCity Tax1Net Price10
Total


110


Code Sample

The sample below enables you to compute tax for a cart with a valid cartID. Using the sample below, you can compute tax for the entire cart using the values fetched from the tax callback class. The fields Taxable, Tax Inclusive, and Tax Code are inherited from the quote or order line item. The tax code must be populated on the Price list item for each product and charge type combination. The Account and Account Location has a Tax Exempt indicator that overrides everything. For example, if the Account has a Tax Exempt flag enabled, then Tax is not calculated for the account. The system gives preference to location unless it is blank. If a product is not taxable or tax inclusive, the system will skip that line item.

For more information about Tax and Shipping scenarios refer, Updating Taxes and Shipping for an Order.
 

public void computeTaxForCart()
{
	if(String.isNotBlank(cartId))
	{
		
		// Create the request
		Apttus_CPQApi.CPQ.ComputeTaxRequestDO request = new Apttus_CPQApi.CPQ.ComputeTaxRequestDO();
		
		// Add request parameters
		request.CartId = cartId;
	   
		// Compute Tax for cart
		Apttus_CPQApi.CPQ.ComputeTaxResponseDO result = Apttus_CPQApi.CPQWebService.computeTaxForCart(request);

		
		// Get Total Tax Item
		ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info, 'Total Tax Item : ' + result.TotalTaxItem));
		
		Map<ID, Apttus_Config2.CustomClass.TaxResult> taxResults = new Map<ID, Apttus_Config2.CustomClass.TaxResult>();
		lstTaxBreakUpWrapper = new List<TaxBreakUpWrapper>();
		
		taxResults = result.TaxResults;
		
		for(ID tId : taxResults.keySet()) 
		{
			Apttus_Config2.CustomClass.TaxResult taxResult = taxResults.get(tId);
			
			// Tax Amount
			ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info, 'Tax Amount : ' + taxResult.TaxAmount));
			
			// Tax BreakUps
			for(Apttus_Config2__TaxBreakup__c taxBreakUp : taxResult.TaxBreakups) 
			{
			
				TaxBreakUpWrapper temp = new TaxBreakUpWrapper();
				temp.TaxBreakUpId = taxBreakUp.Id;
				temp.TaxType = taxBreakUp.Apttus_Config2__TaxType__c;
				temp.TaxAppliedTo = taxBreakUp.Apttus_Config2__TaxAppliesTo__c;
				temp.TaxRate = taxBreakUp.Apttus_Config2__TaxRate__c;
				temp.TaxAmount = taxBreakUp.Apttus_Config2__TaxAmount__c;
				temp.Sequence = taxBreakUp.Apttus_Config2__Sequence__c;
				
				lstTaxBreakUpWrapper.add(temp);
			}
		}
	} 
	else 
	{
		ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info, 'Invalid or blank cart Id.'));
	}   
}
CODE