Portal Features 

In this document, we will explore one of the features of the hosted portal: Custom Codes.

With Custom Codes, you can tailor your customer portal to perfectly meet your unique business needs. Whether you want to enhance the user experience or integrate specialized functionalities, this feature empowers you to create a customer portal that stands out and delivers a seamless experience for your valued customers.

Let us dive in and unlock the possibilities of Custom Codes within your Chargebee-hosted customer portal.

Custom Codes 

Custom code is a feature enabled by Chargebee that allows you to implement custom business logic while the customer performs certain actions in the portal.

  • Contact support  to enable the custom code feature.
  • Currently, this feature is supported in the customer portal in Edit Subscription using the functions.

Custom Codes Use Case 

Let's look at an example.

James runs a fitness app.

He has three plans to which his users can subscribe, Elite, Pro, and Luxe.

James needs to implement business logic in his system to display only upper-level plans when his user wants to change his subscription.

Say, if a user is subscribed to a Pro plan and is trying to change his subscription, the listed plans should be only Luxe and not Elite.

Custom code enables you to implement this business logic easily using functions.

Let us see the supported functions for Custom Code.

Supported Functions for Custom Code 

The functions fetchChangeSubscriptionOptions  or fetchAllowedPlanConfig  enable you to use this feature.

Fetch Change Subscription Options 

Using this function, fetchChangeSubscriptionOptions, you can change subscriptions immediately or end-of-term based on custom code logic.

Implement your business logic on subscription change scenarios that need to happen with immediate effect or at the end of the subscription term, and finally return a value for each scenario.

  • If the changes need to take effect immediately, the end-of-term should be set to false.

  • If the changes need to take effect at the term end, end-of-term should be set to true.


Let's take an example. For downgrades, you can choose to make the change during the end of the term. Whereas for upgrades, you can choose to make the change immediately.

Fetch Allowed Plan Config 

Using this function, fetchAllowedPlanConfig, the following functionalities can be performed:

  • Specify allowed addons.
  • Specify allowed addons for a particular plan.
  • Specify addons to be automatically attached to a plan when selected.
  • Specify quantity meta for a plan or addon.

This function gets the list of plans and addons combinations for a specific subscription. Only the plans and addons present in the list appear to the customer while changing the subscription. You can write your business-specific logic in this function to restrict the plan list and addon list for your customers.


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.

Learn more  about the implementation details of the functions.

Execute your Custom Code 

Once the custom code is enabled by the support, you can access the same by navigating to https://{your-site-name}/custom_codes

The published version of your custom code will be available in the link above.

Click the Download code to download the custom code to make changes if needed.

To execute your custom codes, follow the steps below:

  1. Upload your file - Upload the file containing your business logic using this option.

  2. Pick an execution option - Pick an option to execute. Based on the coding, fetchChangeSubscriptionOptions  or fetchAllowedPlanConfig  or both populates in the dropdown.

  1. Enter the required input parameters. Sample input: ['sampleSubscriptionId']

  2. Click Run and validate your results.

  3. Click Publish.

The Custom Codes feature within Chargebee's Hosted Customer Portal opens endless customization possibilities. By harnessing the power of custom code, you can shape your customer portal into a unique and tailored platform that aligns perfectly with your business goals.

Was this article helpful?