Skip to main content

Billing Account Plugin

Zuora

Billing Account Plugin

UndefinedNameError: reference to undefined name 'undefined' (click for details)
Callstack:
    at (Zuora_CPQ/CPQ_X/Quote_Studio_Settings_and_Configurations/CPQ_X_supported_plugins/Billing_Account_Plugin), /content/body/div[1]/pre, line 2, column 1

Customize Billing Account Plugin

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, or cancel) - 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. Please modify the code accordingly.
    
    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;
       }

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

Procedure

To activate the Billing Account plugin:

  1. Create a global plugin interface that implements zqu.BillingAccountPlugin.IBillingAccountPlugin
  2. Register and activate the plugin.
    1. Navigate to Zuora Config > Quote Studio Settings > Plugins.
    2. Switch the Billing Account Plugin toggle to Active, then add the class name of your custom plugin.

clipboard_ed84427118927904e67e49df8fe4a4450.png

  1. Click Save.

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());
      
    }
    
}