The IPricingTotallingCallback interface provides you a mechanism to defined custom logic to be executed before, during, and after adjustment calculation. The IPricingTotallingCallback is invoked once for each pricing request to calculate the total.

The following methods are available in the IPricingTotallingCallback interface:

Method SignatureDescription
Task BeforePricingCartAdjustmentAsync(IAggregateCartRequest aggregateCartRequest)You can use this method to define custom logic that must be executed before the adjustment is calculated.
Task AfterPricingCartAdjustmentAsync(IAggregateCartRequest aggregateCartRequest)You can use this method to define custom logic that must be executed after the adjustment is calculated.
Task OnCartPricingCompleteAsync(IAggregateCartRequest aggregateCartRequest)You can use this method to define custom logic that must be executed after the pricing is calculated completely.


Example Code

The below code snippet is for reference purposes only.

namespace Apttus.Lightsaber.Customer.Totaling 
{
    public class PricingTotallingCallback : CodeExtensibility, IPricingTotallingCallback 
    {       
        public async Task BeforePricingCartAdjustmentAsync(IAggregateCartRequest aggregateCartRequest)
        {
            var cartLineItems = aggregateCartRequest.GetCartContext().GetLineItems().SelectMany(x => x.GetChargeLines()).Select(s => new LineItem(s)).ToList();

            foreach(LineItem cartLineItem in cartLineItems) {
                if(cartLineItem.IncentiveBasePrice.HasValue && cartLineItem.IncentiveBasePrice.Value != 0) {

                    decimal sellingTerm = cartLineItem.GetValuetOrDefault(LineItemPropertyNames.SellingTerm, 1);
                    decimal lineItemQ = cartLineItem.GetQuantity();

                    decimal? unitIncentiveAmount = cartLineItem.BasePrice - cartLineItem.IncentiveBasePrice;                    

                    cartLineItem.APTS_Unit_Incentive_Adjustment_Amount__c = unitIncentiveAmount;
                    cartLineItem.IncentiveBasePrice = cartLineItem.BasePrice - unitIncentiveAmount;
                    cartLineItem.IncentiveAdjustmentAmount = unitIncentiveAmount * lineItemQ * sellingTerm * -1;
                }
            }

            await Task.CompletedTask;
        }
        
        public async Task AfterPricingCartAdjustmentAsync(IAggregateCartRequest aggregateCartRequest)
        {
            //Example, Set custom fields on line item based on the adjusted price
            await Task.CompletedTask;
        }

        public async Task OnCartPricingCompleteAsync(IAggregateCartRequest aggregateCartRequest)
        {
            var cartLineItems = aggregateCartRequest.GetCartContext().GetLineItems().SelectMany(x => x.GetChargeLines()).Select(s => new LineItem(s)).ToList();
            foreach(var cartLineItem in cartLineItems) {
                if(cartLineItem.NetPrice < 1000) {
                    cartLineItem.APTS_Deal_Color = "Red";
                } else {
                    cartLineItem.APTS_Deal_Color = "Green";
                }
            }
            await Task.CompletedTask;
        }
    }
}
CODE