Billing Account Plugin
The Billing Account Plugin allows customization of the billing account selection process, including controlling account options, filtering accounts, and setting default accounts.
Use the IBillingAccountPlugin on the BillingAccountPlugin component to customize the Billing Account selection process. The following customizations are available.
For billing account selection
-
Control new and existing billing account options
-
To enable new billing account creation and hide existing accounts:
global zqu.BillingAccountPlugin.BillingAccountObjects getAvailableBillingAccounts(zqu.BillingAccountPlugin.BillingAccountObjects accountObjs) { // Control new and existing billing account options // User is only able to create new billing account and existing billing account will not display accountObjs.billingAccountTypes = new List<string>{ 'new' }; accountObjs.billingAccounts = accountObjs.billingAccounts; return accountObjs; } -
To display existing billing accounts and hide the New billing account button:
global zqu.BillingAccountPlugin.BillingAccountObjects getAvailableBillingAccounts(zqu.BillingAccountPlugin.BillingAccountObjects accountObjs) { // Control new and existing billing account options // Only display existing billing account and hide "New billing account" button. accountObjs.billingAccountTypes = new List<string>{ 'existing' }; accountObjs.billingAccounts = accountObjs.billingAccounts; return accountObjs; }
-
-
Filter billing accounts - The code below filters billing accounts based explicitly on the payment terms. If you intend to utilize alternative filter criteria, please make the necessary adjustments accordingly.
global zqu.BillingAccountPlugin.BillingAccountObjects getAvailableBillingAccounts(zqu.BillingAccountPlugin.BillingAccountObjects accountObjs) { // Filter billing accounts List<sobject> tempAccounts = new List<Sobject>(); for (Sobject sobj : accountObjs.billingAccounts) { if (sobj.get('Zuora__PaymentTerm__c') == 'Due Upon Receipt') { tempAccounts.add(sobj); } } accountObjs.billingAccounts = tempAccounts; return accountObjs; } -
Set the default billing account - The code provided below selects default billing accounts based explicitly on the bill cycle type. If you intend to utilize alternative filter criteria, please make the necessary adjustments accordingly.
global zqu.BillingAccountPlugin.BillingAccountObjects getAvailableBillingAccounts(zqu.BillingAccountPlugin.BillingAccountObjects accountObjs) { //Set default billing account based on BillCycleDay for (Sobject sobj : accountObjs.billingAccounts) { if (sobj.get('Zuora__BillCycleDay__c') == '1st of the month') { accountObjs.defaultBillingAccountId = (String)sobj.get('Zuora__Zuora_Id__c'); break; } } return accountObjs; }
For quote type selection
-
Control quote type options (new, amend, renew, cancel, New multi-sub, Amend multi-sub, or Renew multi-sub ) - By using the following code, the cancel button will not be displayed. However, you have the flexibility to set a different Quote Type based on your specific requirements. Modify the code accordingly.
Single Subscription Quoting
global zqu.BillingAccountPlugin.QuoteTypeObjects getAvailableQuoteTypes(zqu.BillingAccountPlugin.QuoteTypeObjects quoteTypeObjs) { //This will remove option of cancel quote and user is not able to do cancel quote quoteTypeObjs.quoteTypes = new List<string>{ 'new', 'amend', 'renew'}; return quoteTypeObjs; }Multi Subscription Quoting
global zqu.BillingAccountPlugin.QuoteTypeObjects getAvailableQuoteTypes(zqu.BillingAccountPlugin.QuoteTypeObjects quoteTypeObjs) { //This will remove option of cancel quote and user is not able to do cancel quote quoteTypeObjs.quoteTypes = new List<string>{ 'new', 'amend', 'renew', 'New multi-sub', 'Amend multi-sub', or 'Renew multi-sub'}; return quoteTypeObjs; }
For subscription type selection
-
Filter subscriptions - The code below filters subscriptions based on the term type, specifically targeting subscriptions with the term "termed." As a result, subscriptions with the term type "Evergreen" will not be displayed. If you wish to include or modify the filtering criteria, please make the necessary adjustments in the code according to your requirements.
global zqu.BillingAccountPlugin.SubscriptionObjects getAvailableSubscriptions(zqu.BillingAccountPlugin.SubscriptionObjects subscriptionObjs) { //Filter Subscriptions based on Term Type List<sobject> tempSubs = new List<Sobject>(); for (Sobject sobj : subscriptionObjs.subscriptions) { if (sobj.get('Zuora__TermSettingType__c') == 'TERMED') { tempSubs.add(sobj); } } subscriptionObjs.subscriptions = tempSubs; return subscriptionObjs; }
Plugin interface
The plugin interface is defined as:
global zqu.BillingAccountPlugin.IBillingAccountPlugin
The plugin contains the following interface methods.
| Return Type | Method | Input Parameters |
|---|---|---|
| zqu.BillingAccountPlugin.BillingAccountObjects | getAvailableBillingAccounts | zqu.BillingAccountPlugin.BillingAccountObjects |
| zqu.BillingAccountPlugin.QuoteTypeObjects | getAvailableQuoteTypes | zqu.BillingAccountPlugin.QuoteTypeObjects |
| zqu.BillingAccountPlugin.SubscriptionObjects | getAvailableSubscriptions | zqu.BillingAccountPlugin.SubscriptionObjects |
Sample Code for Billing Account Plugin
The following is a code sample for the Billing Account Plugin.
global with sharing class SampleBillingAccountPlugin implements
zqu.BillingAccountPlugin.IBillingAccountPlugin {
global zqu.BillingAccountPlugin.BillingAccountObjects
getAvailableBillingAccounts(zqu.BillingAccountPlugin.BillingAccountObjects
accountObjs) {
accountObjs.billingAccountTypes = new List<string>{ 'existing' };
List<sobject> tempAccounts = new List<Sobject>();
for (Sobject sobj : accountObjs.billingAccounts) {
if (sobj.get('Zuora__PaymentTerm__c') == 'Due Upon Receipt') {
tempAccounts.add(sobj);
}
}
accountObjs.billingAccounts = tempAccounts;
return accountObjs;
}
global zqu.BillingAccountPlugin.QuoteTypeObjects
getAvailableQuoteTypes(zqu.BillingAccountPlugin.QuoteTypeObjects
quoteTypeObjs) {
quoteTypeObjs.quoteTypes = new List<string>{ 'new', 'amend' };
return quoteTypeObjs;
}
global zqu.BillingAccountPlugin.SubscriptionObjects
getAvailableSubscriptions(zqu.BillingAccountPlugin.SubscriptionObjects
subscriptionObjs) {
List<sobject> tempSubs = new List<Sobject>();
for (Sobject sobj : subscriptionObjs.subscriptions) {
if (sobj.get('Zuora__TermSettingType__c') == 'TERMED') {
tempSubs.add(sobj);
}
}
subscriptionObjs.subscriptions = tempSubs;
return subscriptionObjs;
}
}
Test Class for Billing Account Plugin
The following is a APEX test class code sample for Billing Account Plugin. You can use the test class to achieve code coverage on the plugin in Salesforce.
@IsTest(SeeAllData=false)
public with sharing class SampleBillingAccountPluginTest{
@IsTest
public static void testGetAvailableBillingAccounts() {
SampleBillingAccountPlugin pluginObj=new
SampleBillingAccountPlugin();
Zuora__CustomerAccount__c customerAccount=new
Zuora__CustomerAccount__c();
customerAccount.Zuora__PaymentTerm__c='Due Upon Receipt';
zqu.BillingAccountPlugin.BillingAccountObjects billingAccounts=new
zqu.BillingAccountPlugin.BillingAccountObjects();
billingAccounts.sfdcAccountId='';
billingAccounts.opportunityId='';
billingAccounts.defaultBillingAccountId='';
billingAccounts.billingAccountTypes=new List<string>{'new','existing'};
billingAccounts.billingAccounts=new List<Sobject>{customerAccount};
zqu.BillingAccountPlugin.BillingAccountObjects
filteredBillingAccount=pluginObj.getAvailableBillingAccounts(billingAccounts);
System.assertEquals(1,filteredBillingAccount.billingAccounts.size());
System.assertEquals(1,filteredBillingAccount.billingAccountTypes.size());
}
@IsTest
public static void testGetAvailableQuoteTypes() {
SampleBillingAccountPlugin pluginObj=new SampleBillingAccountPlugin();
zqu.BillingAccountPlugin.QuoteTypeObjects quoteTypes=new
zqu.BillingAccountPlugin.QuoteTypeObjects();
quoteTypes.sfdcAccountId='';
quoteTypes.opportunityId='';
quoteTypes.billingAccountId='';
quoteTypes.quoteTypes=new List<string>{'new','existing'};
zqu.BillingAccountPlugin.QuoteTypeObjects
quoteTypesResponse=pluginObj.getAvailableQuoteTypes(quoteTypes);
System.assertEquals(2,quoteTypesResponse.quoteTypes.size());
}
@IsTest
public static void testGetAvailableSubscriptions() {
SampleBillingAccountPlugin pluginObj=new
SampleBillingAccountPlugin();
Zuora__Subscription__c subscriptionObj=new
Zuora__Subscription__c();
subscriptionObj.Zuora__TermSettingType__c='TERMED';
zqu.BillingAccountPlugin.SubscriptionObjects subscriptions=new
zqu.BillingAccountPlugin.SubscriptionObjects();
subscriptions.sfdcAccountId='';
subscriptions.opportunityId='';
subscriptions.billingAccountId='';
subscriptions.subscriptions=new List<Sobject>{subscriptionObj};
pluginObj.getAvailableSubscriptions(subscriptions);
System.assertEquals(1,subscriptions.subscriptions.size());
}
}