# Retrieve Allowed Plans and Addons in Product Catalog 1.0


This page is for Product Catalog 1.0 customers. If you are on Product Catalog 2.0, visit this page.

Chargebee will call this function from its backend to get the allowed list of plans and addons for a particular subscription when a subscription change is initiated by the customer in Portal.

This function performs the business logic (written into it by you) and returns only the allowed list of plans and addons. Chargebee then displays only that list of plans and addons to the user to choose from while changing their subscription.

Contact [email protected] to enable this feature.

# How to use this function

Using this function, you can

  • Create groups of plans and addons

  • Allow/disallow downgrade/upgrade within a group

  • Apply addons

Though the calls between this function and Chargebee are automated, the logic of this function needs to be written by you. This way, you have complete control over the business logic running in the function and Chargebee displays the allowed list for that user.

You need to formulate and implement your business logic into the function on what plan and addons are applicable for users who are trying to change their subscription in Portal. And return that list of plans and addons to Chargebee.

Let's take an example. For users on the Platinum plan you can provide the plans and addons from a premium group to choose from during upgrade. Whereas for users on the Gold plan, you can provide the plans and addons from a basic group to choose from, during downgrade.

# Instructions for writing the function

  • It should be written in javascript.
  • It should be executable in Node.js v6.0 environment.
  • Some default resources are passed to this function by Chargebee. You can use these resources to write your business logic. The resource formats are similar to the resource output generated from the Node.js client library.
  • You can also use Chargebee’s Node.js client library (if already configured with API key and secret key) for retrieving and using additional resources.
  • Return a JavaScript object that matches the JSON schema given below.

# Input parameters

Note that these parameters are passed to this function by Chargebee. You can make use of the information from them for writing your business logic. Additional information can also be retrieved using Chargebee’s Node.js client library.

  • Subscription [object] : User's existing subscription details.

  • Customer [object] : User’s details.

  • Plans [object] : Current plan details.

  • Addons [object] : List of current addons linked to the subscription.

  • Callback [object] : Output or error message needs to be passed here. Errors can be seen in the Chargebee app. Any reported errors would stop the change subscription operation.

    • For success, pass callback(null,output).
    • For error, pass callback(error,null).
  • Logger [object] : Used to log debugging information only while testing (function should be in draft mode) using the Chargebee test site.

# Output parameters

You can use these additional parameters to pass data to Chargebee. It is then displayed on portal for the user to access.

  • use_existing_addons : Set true to carryover addons from the current subscription to the changed subscription.

  • allowed_addons : List of applicable addons for the plan.

  • addons : List of addons to be auto-attached when a customer moves from one plan to another.

  • meta_data : This supplies data for the quantity drop-down associated with a plan or addon.

# Sample Code

  • js

# Sample Output

  • json

# Expected JSON schema for the output

  • json