# Retrieve Allowed Plans and Addons in Product Catalog 2.0
This page is for Product Catalog 2.0 customers. If you are on Product Catalog 1.0, visit this page.
Chargebee will call this function from its backend to get the allowed list of plan items and addon items 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 plan items and addon items. Chargebee then displays only that list of plan items and addon items to the user to choose from while changing their subscription.
# How to use this function
Using this function, you can
Create groups of plans and addons
Allow/disallow downgrade/upgrade within a group
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 items and addon items are applicable for users who are trying to change their subscription in Portal. And return that list of plan items and addon items to Chargebee.
Let's take an example. For users on the Platinum plan you can provide the plan items and addon items from a premium group to choose from during upgrade. Whereas for users on the Gold plan, you can provide the plan items and addon items from a basic group to choose from, during downgrade.
# Instructions for writing the function
- 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.
# 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.
Item prices [object] : Details of current plan and addon price points.
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.
success, pass callback(null,output).
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.
trueto carryover addon items from the current subscription to the changed subscription.
allowed_addons: List of applicable addon items for the plan item.
addons: List of addons items to be auto-attached when a customer moves from one plan item to another.
meta_data: This supplies data for the quantity drop-down associated with a plan item or addon item.
# Sample Code
# Sample Output
# Expected JSON schema for the output