Download PDF
Download page Computing Taxes for Cart Line Items.
Computing Taxes for Cart Line Items
This API enables you to calculate tax breakups for cart line item.
API | Signature |
---|---|
computeTaxForCart | webService static Apttus_CPQApi.CPQ.ComputeTaxResponseDO computeTaxForCart(Apttus_CPQApi.CPQ.ComputeTaxRequestDO request) |
Parameters | ||
---|---|---|
Name | Type | Description |
request | Apttus_CPQApi.CPQ.ComputeTaxRequestDO | The compute tax request object. |
Request Data Object - Apttus_CPQApi.CPQ.ComputeTaxRequestDO | ||
---|---|---|
Field | Type | Description |
CartID | ID | The id of the cart. |
Response Data Object - Apttus_CPQApi.CPQ.ComputeTaxResponseDO | ||
---|---|---|
Field | Type | Description |
TaxResults | Map<ID, Apttus_Config2.CustomClass.TaxResult> | The Tax Result object populated by the line item id. This is only available when called from Apex. |
TotalTaxItem | Apttus_Config2__LineItem__c | The line item with total taxes. |
Data Object - Apttus_Config2.CustomClass.TaxResult | ||
---|---|---|
Field | Type | Description |
Handback | Object | Any 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.
|
TaxAmount | Decimal | This 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. |
TaxBreakups | List<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 | ||
---|---|---|
Field | Type | Description |
BreakupType | String | If 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. |
TaxAmount | Decimal | The tax amount calculated based on the formulae defined in the callback. |
TaxAppliesTo | String | The field on which the tax is applied to. For example, net price. |
TaxRate | Decimal | Tax percentage to be applied |
TaxType | String | Type of tax to be applied. For example, sales, custom, excise. |
Breakup Type | Tax Type | Tax Rate | Tax Applies to | Tax Amount |
---|---|---|---|---|
Detail | State Tax | 10 | Net Price | 100 |
Detail | City Tax | 1 | Net Price | 10 |
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.'));
}
}