Implementing a custom fee
During the contract tenure, many kinds of fees may be applied to a loan, such as late fees, pre-payment fees, and NSF fees. On most occasions these fees have a fixed value. However, there may be scenarios where you may have a specific mechanism to compute the value of the fee. For example, you may define a custom fee calculation as: % of payment amount + % of principal balance. Or, % of payment amount * no of terms remaining.
CL Loan offers an extension point using which the calculation of the fee can be customized in a customer org. This functionality leverages the template method pattern that lets you redefine certain aspects of an algorithm in downstream subclasses. This pattern implements plugin-style object-oriented frameworks so that the behavior of the plugin can be picked at run time through dynamic dispatch.
For example, default fee calculation is implemented as:
public class FeeCalculator implements FeeCalculator{
public Decimal computeFee(Fee__c fee, Loan_Account__c loan) {
// default implementation...
}
}
Based on the algorithm you need to define for calculating the custom fee amount, the default behavior is overwritten as:
/* note that this class MUST be global because it will be called from the base package */
global class CustomFeeCalculator implements loan.CustomFeeCalculator {
// loan is the namespace
// the method must be global as well
global Decimal computeFee(Fee__c fee, Loan_Account__c loan) {
//loan__ is the namespace
// perform custom calculation here
}
}
Only one custom fee calculation can be set up org wide. The lender needs to specify the fee calculation algorithm at the time of CL Loan implementation.
Custom fees are billed as charges.
Prerequisites
The following is a prerequisite to setting up a custom fee:
A fee with Fee Calculation Method as Custom is included in the fee set attached to the contract.
Steps
Perform the following steps to set up the custom fee calculation:
Log in to your Salesforce account.
Click Setup.
Go to Build, Develop, Apex Classes.
-
Create Apex Class which implements 'loan.CustomFeeCalculator'.
Note:Custom Fee Calculator interface enforces to write following method: Decimal computeFee(Fee__c fee, Loan_Account__c loan)
Custom logic should go in this compute Fee method. Method should return Decimal value (actual fee amount).
Go to Setup, Build, Develop, Custom Settings, Manage Org Parameters.
Set Apex Class name, created in step #10, in Custom Fee Calculator Class field in Org Parameters.
Sample Class
public class SampleCustomFeeCalculator implements loan.CustomFeeCalculator {
public Decimal computeFee(Fee__c fee, Loan_Account__c loan) {
//Custom Algorithm implementation.
Decimal factor =
loan.Frequency_of_Loan_Payment__c.equals(LoanConstants.LOAN_PAYMENT_FREQ_MONTHLY) ?
30 : loan.Frequency_of_Loan_Payment__c.equals(LoanConstants.LOAN_PAYMENT_FREQ_WEEKLY) ?
7 : 0;
//Calculate Fee Amount.
return ValueUtil.round(0.01 * loan.Loan_Amount__c * loan.Number_of_Installments__c * factor / 360);
}
}