# Retrieve Subscription Change Timeline 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 when a subscription change is initiated by a customer in Portal.

This function performs the business logic (written into it by you) and returns whether the change in subscription needs to happen end of term or immediately. Chargebee then sets the timeline for changes to take effect, based on the return value.

Contact [email protected] to enable this feature.

# How to use this function

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 invokes the subscription change during the desired time.

You can implement your business logic on cases of subscription change that need to happen immediately and at the end of term, and finally return a value for each scenario.

  • If the changes need to take effect immediately, 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.

# 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.

  • Item prices [object] : Details on current plan item and addon items in use.

  • 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.

# Sample code

  • js

# Sample Output

  • json

# Expected JSON schema for the output

  • json