# API Reference
# Chargebee object
# init
This function is used to create chargebee instance object to open checkout and portal.
# Syntax
Chargebee.init(options)
# Parameters
# Return value
chargebee instance object
# Example
var cbInstance = Chargebee.init({
site: "site-name", // your test site
domain: "https://mybilling.acme.com" // this is an optional parameter.
// Use this, if custom domain is enabled for your site
})
2
3
4
5
# getInstance
This function will return 'chargebee instance' object created using init() function.
# Syntax
Chargebee.getInstance();
# Return value
chargebee instance object
# getPortalSections
This function will return an object with all the available sections in Chargebee customer portal. This section name can be used to forward an user to a particular section or just to open the section as an individual card.
# Syntax
Chargebee.getPortalSections();
# Output
{
"SUBSCRIPTION_DETAILS": "sub_details",
"SUBSCRIPTION_CANCELLATION": "sub_cancel",
"EDIT_SUBSCRIPTION": "edit_subscription",
"VIEW_SCHEDULED_CHANGES": "scheduled_changes",
"ACCOUNT_DETAILS": "account_details",
"EDIT_ACCOUNT_DETAILS": "portal_edit_account",
"ADDRESS": "portal_address",
"EDIT_BILLING_ADDRESS": "portal_edit_billing_address",
"EDIT_SHIPPING_ADDRESS": "portal_edit_shipping_address",
"EDIT_SUBSCRIPTION_CUSTOM_FIELDS": "portal_edit_subscription_cf",
"PAYMENT_SOURCES": "portal_payment_methods",
"ADD_PAYMENT_SOURCE": "portal_add_payment_method",
"EDIT_PAYMENT_SOURCE": "portal_edit_payment_method",
"VIEW_PAYMENT_SOURCE": "portal_view_payment_method",
"CHOOSE_PAYMENT_METHOD_FOR_SUBSCRIPTION": "portal_choose_payment_method",
"BILLING_HISTORY": "portal_billing_history"
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Chargebee instance object
Chargebee instance object is used to open checkout and to create chargebee portal instance object.
# openCheckout
This function is used to open checkout page.
# Syntax
cbInstance.openCheckout(options)
# Parameters
# Example
cbInstance.openCheckout({
hostedPage: function() {
// required
// This function should return a promise, that will resolve a hosted page object
// If the library that you use for making ajax calls, can return a promise,
// you can directly return that.
return new Promise(function(resolve, reject){
// This sampe response should be fetched as a result of an ajax call
var sampleResponse = {
"id": "8ajOxcuyG692GDy9yjnZ2hNM1ATugOFQl",
"type": "checkout_new",
"url": "https://yourapp.chargebee.com/pages/v3/8ajOxcuyG692GDy9yjnZ2hNM1ATugOFQl/",
"state": "created",
"embed": true,
"created_at": 1515494821,
"expires_at": 1515498421
}
resolve(sampleResponse);
});
},
loaded: function() {
// Optional
// will be called once checkout page is loaded
},
error: function(error) {
// Optional
// will be called if the promise passed causes an error
},
step: function(step) {
// Optional
// will be called for each step involved in the checkout process
},
success: function(hostedPageId) {
// Optional
// will be called when a successful checkout happens.
},
close: function() {
// Optional
// will be called when the user closes the checkout modal box
}
})
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
36
37
38
39
40
41
# createChargebeePortal
This function will create a chargebee portal instance which opens Chargebee’s self-serve portal.
# Syntax
cbInstance.createChargebeePortal()
# Return value
chargebee portal instance object
# Example
var chargebeePortalInstance = cbInstance.createChargebeePortal()
# setPortalSession
This function is used to open customer portal with single-sign-on(SSO) enabled.
# Syntax
cbInstance.setPortalSession(setterFunction)
# Parameters
# Example
cbInstance.setPortalSession(function() {
// This function should return a promise, that will resolve a portal session object.
// If the library that you use for making ajax calls, can return a promise, you can directly return that.
return new Promise(function(resolve, reject){
// This sampe response should be fetched as a result of an ajax call.
var sampleResponse = {
"id": "portal_XpbGElGQgEHspHB",
"token": "cuqdrWacuITd2cabvf97KJD73SpNcd7BICB",
"access_url": "https://yourapp.chargebeeportal.com/portal/access/cuqdrWacuITd2cabvf97KJD73SpNcd7BICB",
"status": "created",
"created_at": 1515494835,
"expires_at": 1515498435,
"object": "portal_session",
"customer_id": "XpbGEt7QgEHsnL7O"
}
resolve(sampleResponse);
});
})
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# logout
This function is used to logout Chargebee’s session. If you do not call this function, the session will be valid for a maximum of one hour.
# Syntax
cbInstance.logout()
# closeAll
This function is used to close all Chargebee modals.
# Syntax
cbInstance.closeAll()
# Chargebee portal instance object
Chargebee portal instance object is used to do portal related actions.
# open
This function is used to open Chargebee’s self-serve portal.
# Syntax
chargebeePortalInstance.open(options, forwardOptions)
# Parameters
# Example
chargebeePortalInstance.open({
loaded: function() {
// Optional
// called when chargebee portal is loaded
},
close: function() {
// Optional
// called when chargebee portal is closed
},
visit: function(sectionName) {
// Optional
// called whenever the customer navigates across different sections in portal
},
paymentSourceAdd: function() {
// Optional
// called whenever a new payment source is added in portal
},
paymentSourceUpdate: function() {
// Optional
// called whenever a payment source is updated in portal
},
paymentSourceRemove: function() {
// Optional
// called whenever a payment source is removed in portal.
},
subscriptionChanged: function(data) {
// Optional
// called whenever a subscription is changed
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
subscriptionCustomFieldsChanged: function(data) {
// Optional
// called whenever a subscription custom fields are changed
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
subscriptionCancelled: function(data) {
// Optional
// called when a subscription is cancelled
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
subscriptionPaused: function(data) {
// Optional
// called when a subscription is Paused.
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
subscriptionResumed: function(data) {
// Optional
// called when a paused subscription is resumed.
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
scheduledPauseRemoved: function(data) {
// Optional
// called when the schedule to pause a subscription is removed for that subscription.
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
scheduledCancellationRemoved: function(data) {
// Optional
// called when the schedule to cancel a subscription is removed for that subscription.
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
},
subscriptionReactivated: function(data) {
// Optional
// called when a cancelled subscription is reactivated.
// data.subscription.id will give you the subscription id
// Make sure you whitelist your domain in the checkout settings page
}
})
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Example for forwarding the user to a specific section after opening customer portal
To redirect the user to a specific section while opening customer portal, the section name along with the supported params need to be passed.
var cbInstance = Chargebee.getInstance();
var cbPortal = cbInstance.createChargebeePortal();
var callbacks = {};
cbPortal.open(callbacks,
{
sectionType: Chargebee.getPortalSections().EDIT_SUBSCRIPTION,
params: {
subscriptionId: "active_direct"
}
}
);
2
3
4
5
6
7
8
9
10
11
# openSection
Use this method if you want to open a particular section as a separate card, instead of opening the entire customer portal.
# Only the below section types can be opened as a separate card
- SUBSCRIPTION_DETAILS
- ACCOUNT_DETAILS
- ADDRESS
- PAYMENT_SOURCES
- BILLING_HISTORY
# Syntax
cbPortal.openSection(options, callbacks)
# Parameters
# Example
var cbInstance = Chargebee.getInstance();
var cbPortal = cbInstance.createChargebeePortal();
cbPortal.openSection({
sectionType: Chargebee.getPortalSections().ACCOUNT_DETAILS
}
2
3
4
5
All the callbacks that are supported in the portal will be supported when a section of the portal is opened as a separete section using this method.