The IPricingBasePriceCallback interface provides you a mechanism to define a custom logic to be executed before, during, and after Base Price calculation. The IPricingBasePriceCallback is executed in batches which consists of the batch line items. TurboPricing calls this interface for every batch.

The following methods are available in the IPricingBasePriceCallback interface:

Method SignatureDescription
Task BeforePricingBatchAsync(IBatchPriceRequest batchPriceRequest)You can use this method to define custom logic that must be executed before Base Price is calculated.
Task OnPricingBatchAsync(IBatchPriceRequest batchPriceRequest)You can use this method to define custom logic that must be executed during the Base Price calculation. You can use the price list items to write the custom logic.
Task AfterPricingBatchAsync(IBatchPriceRequest batchPriceRequest)You can use this method to define custom logic that must be executed after the Base Price is calculated.


Example Code

The below code snippet is for reference purposes only.

namespace Apttus.Lightsaber.Customer.Pricing 
{
    public class PricingBasePriceCallback : CodeExtensibility, IPricingBasePriceCallback 
    {
        public async Task AfterPricingBatchAsync(IBatchPriceRequest batchPriceRequest)
        {
            await Task.CompletedTask;
        }

        public async Task BeforePricingBatchAsync(IBatchPriceRequest batchPriceRequest)
        {
            var batchLineItems = batchPriceRequest.GetLineItems().SelectMany(x => x.GetChargeLines()).Select(s => new LineItem(s)).ToList();

            //Example, setting custom field on line item before PLI resolution
            foreach(var batchLineItem in batchLineItems) {
                decimal extendedQuantity = batchLineItem.GetQuantity();
                decimal quantity = batchLineItem.GetQuantity();

                if(batchLineItem.IsOptionLine()) {
                    LineItem rootBundleLineItemModel = new LineItem(batchLineItem.GetRootParentLineItem().GetPrimaryLineItem());
                    decimal bundleQuantity = rootBundleLineItemModel.GetQuantity();
                    extendedQuantity = bundleQuantity * batchLineItem.GetQuantity();
                }

                batchLineItem.APTS_Extended_Quantity__c = extendedQuantity;
            }
            
            //You can also query DB here, and perform initial setup such as creating required Dictionary, List and so on for later use in the callback code.

            await Task.CompletedTask;
        }

        public async Task OnPricingBatchAsync(IBatchPriceRequest batchPriceRequest)
        {
            var batchLineItems = batchPriceRequest.GetLineItems().SelectMany(x => x.GetChargeLines()).Select(s => new LineItem(s)).ToList();

            foreach(var batchLineItem in batchLineItems) {
                IPriceListItemModel priceListItemModel = batchLineItem.GetPriceListItem();
                IPriceListItem priceListItemEntity = priceListItemModel.GetEntity();

                if(batchLineItem.PriceListId != priceListItemEntity.PriceListId) {                   
                       batchLineItem.APTS_Is_Contract_Pricing__c = true;                   
                }
            }                
            await Task.CompletedTask;
        }
    }
}
CODE