# Portal Object

# Overview

The Portal object provides access to Chargebee's customer self-service portal functionality. This object enables you to open the complete customer portal or specific sections, allowing customers to manage their subscriptions, billing information, and account details.

# Prerequisites

Before creating the Portal object, ensure you have:

# Create the Portal object

To create a Portal object instance, use the createChargebeePortal() method:

const chargebeePortal = chargebee.createChargebeePortal();
1

# open(options?, forwardOptions?)

Opens the customer self-service portal or one of its sections in a modal or new window.

# Syntax

chargebeePortal.open(options, forwardOptions);
1

# Parameters

DETAILS
options
Object Hide properties
loaded
Function
This function will be called once the portal is loaded.
close
Function
This function will be called once the portal is closed by the end user.
visit
Function
This function will be called everytime a user visits a section in the customer portal.
Arguments - Hide
sectionType
String
paymentSourceAdd
Function
This function will be called whenever a new payment source is added in portal.
Arguments - Hide
status
String
Specifies whether the payment source was added successfully.
Allowed Values:
success
error
paymentSourceUpdate
Function
This function will be called whenever a payment source is updated in portal.
Arguments - Hide
status
String
Specifies whether the payment source was updated successfully.
Allowed Values:
success
error
paymentSourceRemove
Function
This function will be called whenever a payment source is removed from portal.
subscriptionChanged
Function
This function will be called whenever a subscription is changed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionCustomFieldsChanged
Function
This function will be called whenever a subscription custom fields are changed
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionCancelled
Function
This function will be called when a subscription is canceled.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionResumed
Function
This function will be called when a subscription is resumed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionPaused
Function
This function will be called when a subscription is paused.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
scheduledPauseRemoved
Function
This function will be called when a subscription that is scheduled for pause is removed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
scheduledCancellationRemoved
Function
This function will be called when the schedule to cancel a subscription is removed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionReactivated
Function
This function will be called when a canceled subscription is reactivated.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
forwardOptions
Object Hide properties
sectionType
String Required
Allowed Values:
All values present in Chargebee.getPortalSections()
params
Object Hide properties
subscriptionId
String Required if the sectionType involves a subscription related action
paymentSourceId
String Required if the sectionType involves a payment source related action

# Return value

This function does not return a value.

# Example

const chargebee = Chargebee.getInstance();

// Set up portal session (required before creating portal).
chargebee.setPortalSession(() => {
  // Return a promise that resolves to portal session data.
  return new Promise(function(resolve, reject) {
    // Example portal session response from your server.
    const portalSessionResponse = {
      "id": "portal_XpbGElGQgEHspHB",
      "token": "<portal-session-token>",
      "access_url": "https://yourapp.chargebeeportal.com/portal/access/<portal-session-token>",
      "status": "created",
      "created_at": 1515494835,
      "expires_at": 1515498435,
      "object": "portal_session",
      "customer_id": "XpbGEt7QgEHsnL7O"
    };
    resolve(portalSessionResponse);
  });
});

// Create and open the portal.
const chargebeePortal = chargebee.createChargebeePortal();
chargebeePortal.open({
  // Optional: Customize portal behavior
  closeOnEscape: true,
  showCloseButton: true
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# openSection(options, callbacks?)

Opens a specific section of the customer portal instead of the complete portal.

# Available section types

You can open the following section types as separate cards:

  • SUBSCRIPTION_DETAILS - View and manage subscription information.
  • ACCOUNT_DETAILS - Update customer account information.
  • ADDRESS - Manage billing and shipping addresses.
  • PAYMENT_SOURCES - Add, update, or remove payment methods.
  • BILLING_HISTORY - View past invoices and payment history.

# Syntax

chargebeePortal.openSection(options, callbacks)
1

# Parameters

DETAILS
options
Object Hide properties
sectionType
String
params
Object Hide properties
subscriptionId
String Required if the sectionType involves a subscription
callbacks
Object Hide properties
loaded
Function
This function will be called once the portal is loaded.
close
Function
This function will be called once the portal is closed by the end user.
visit
Function
This function will be called everytime an user visits a section in the customer portal.
Arguments - Hide
sectionType
String
paymentSourceAdd
Function
This function will be called whenever a new payment source is added in portal.
paymentSourceUpdate
Function
This function will be called whenever a payment source is updated in portal.
paymentSourceRemove
Function
This function will be called whenever a payment source is removed from portal.
subscriptionChanged
Function
This function will be called whenever a subscription is changed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionCustomFieldsChanged
Function
This function will be called whenever a subscription custom fields are changed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionCancelled
Function
This function will be called when a subscription is canceled.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionResumed
Function
This function will be called when a subscription is resumed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionPaused
Function
This function will be called when a subscription is paused.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
scheduledPauseRemoved
Function
This function will be called when a subscription that is scheduled for pause is removed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
scheduledCancellationRemoved
Function
This function will be called when the schedule to cancel a subscription is removed.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String
subscriptionReactivated
Function
This function will be called when a canceled subscription is reactivated.
Arguments - Hide
data
Object Hide properties
subscription
Object Hide properties
id
String

# Return value

This function does not return a value.

# Example

const chargebee = Chargebee.getInstance();

// Set up portal session (required before creating portal).
chargebee.setPortalSession(() => {
  // Return a promise that resolves to portal session data.
  return new Promise(function(resolve, reject) {
    // Example portal session response from your server.
    const portalSessionResponse = {
      "id": "portal_XpbGElGQgEHspHB",
      "token": "<portal-session-token>",
      "access_url": "https://yourapp.chargebeeportal.com/portal/access/<portal-session-token>",
      "status": "created",
      "created_at": 1515494835,
      "expires_at": 1515498435,
      "object": "portal_session",
      "customer_id": "XpbGEt7QgEHsnL7O"
    };
    resolve(portalSessionResponse);
  });
});

// Create and open the portal.
const chargebeePortal = chargebee.createChargebeePortal();

// Open a specific section
chargebeePortal.openSection({
  sectionType: Chargebee.getPortalSections().ACCOUNT_DETAILS
}, {
  loaded: () => {
    console.log('Account details section loaded.');
  },
  closed: () => {
    console.log('Account details section closed.');
  }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35