Portal Features
This document explores one of the hosted portal features: Custom Codes.
With Custom Codes, you can tailor your customer portal to fit your business needs. Whether you want to refine the user experience or add specialized logic, this feature lets you build a customer portal that reflects how you sell.
Custom codes
Custom Codes is a Chargebee feature that lets you run your own business logic while a customer performs certain actions in the portal.
Information
- Contact support to enable the Custom Codes feature.
- This feature is currently supported in the customer portal's Edit Subscription flow using functions.
Custom codes use case
Consider an example.
James runs a fitness app with three plans that his users can subscribe to: Elite, Pro, and Luxe.
James wants to show only higher-tier plans when a user changes their subscription. For example, when a user on the Pro plan changes their subscription, the portal should list only Luxe and not Elite.
Custom Codes lets James implement this logic using functions.
Supported functions for custom code
The fetchChangeSubscriptionOptions and fetchAllowedPlanConfig functions enable this feature.
Fetch change subscription options
Use fetchChangeSubscriptionOptions to control whether a subscription change takes effect immediately or at the end-of-term, based on your custom logic.
Implement your logic for the subscription-change scenarios that should apply immediately and those that should apply at the end of the term, and return a value for each:
- To apply the change immediately, set
end-of-termtofalse. - To apply the change at the end of the term, set
end-of-termtotrue.
Note
For example, you can apply upgrades immediately and defer downgrades to the end of the term.
Fetch allowed plan config
Use fetchAllowedPlanConfig to do the following:
- Specify the allowed plans and addons.
- Auto-attach addons to a plan when it's selected.
- Set quantity constraints for a plan or addon.
This function returns the plan and addon combinations available for a subscription. The customer sees only the plans and addons in this list when they change their subscription. Write your business logic in this function to restrict the plan and addon lists for your customers.
Note
For example, for customers on the Platinum plan, you can offer plans and addons from a premium group during an upgrade. For customers on the Gold plan, you can offer plans and addons from a basic group during a downgrade.
Learn more about the implementation details of these functions.
Execute your custom code
After support enables Custom Codes, access it at https://YOUR_SITE_NAME.chargebee.com/custom_codes.
The published version of your custom code is available at this link. To make changes, select Download code to download the current custom code.
To run your custom code, follow these steps:
-
Upload the file that contains your business logic.
-
Pick an execution option. Depending on your code, fetchChangeSubscriptionOptions, fetchAllowedPlanConfig, or both appear in the dropdown.
-
Enter the required input parameters. Sample input:
['sampleSubscriptionId'] -
Click Run and validate your results.
-
Click Publish.
With Custom Codes, you can shape your customer portal into a tailored experience that aligns with your business goals.
Was this article helpful?