# API Reference
# Chargebee object
# init
This function is used to initialize Chargebee with your site, domain name. The 'chargebee instance' object returned as result of initialization is used to create 3DS handler object.
# 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.
});
2
3
4
# getInstance
This function will return 'chargebee instance' object.
# Syntax
Chargebee.getInstance();
# Return value
Chargebee instance object
# Chargebee instance object
Chargebee instance is used to create 3DS handler object
# load3DSHandler
This function will load 3DS-helper module and will intialize 3DS handle object. You can use this approach or the above approach to load 3DS-helper module.
# Syntax
cbInstance.load3DSHandler();
# Return value
Promise that resolves 3DS handler object.
# Example
cbInstance.load3DSHandler().then((threeDSHandler) => {
// your code here
});
2
3
# create3DSHandler
You can create a threeDS handler object using this method as well. But 3ds-handler
module should be loaded prior to using this method.
# Return value
3DS handler object.
# Example
cbInstance.load("3ds-handler").then(() => {
let threeDSHandler = cbInstance.create3DSHandler();
// Your code here
});
2
3
4
# 3DS Handler Instance
3DS handler instance is used to handle 3DS authorization flow.
# setPaymentIntent
Use this function to set paymentIntent
that was created at your server side. The paymentIntent
will contain information about the payment gateway and the amount that needs to be charged. In case you are using the respective gateway's JS library along with this module, pass the gateway JS instance in this method. This gateway JS instance will internally be used for handling 3DS flow.
# Syntax
threeDSHandler.setPaymentIntent(paymentIntent, options);
# Parameters
# Example
cbInstance.load3DSHandler((threeDSHandler) => {
// This payment intent can be loaded while rendering the page or via ajax call
threeDSHandler.setPaymentIntent(paymentIntent);
// In case you are using adyen web components, you can pass the adyen instance with this method,
threeDSHandler.setPaymentIntent(paymentIntent, {
adyen: adyenCheckoutInstance,
});
});
2
3
4
5
6
7
8
9
# updatePaymentIntent
Whenever the amount that needs to charged changes with user interaction (discount coupon applied, tax), you can do an ajax call to your server to update the payment intent using this API (opens new window). This updated paymentIntent
should then be passed to this function.
# Syntax
threeDSHandler.updatePaymentIntent(paymentIntent, options);
# Parameters
# Example
let threeDSHandler = cbInstance.create3DSHandler();
// This payment intent can be loaded while rendering the page or via ajax call
threeDSHandler.updatePaymentIntent(paymentIntent);
2
3
# getPaymentIntent
Returns the payment intent object that is currently set in the 3DS handler instance.
# Syntax
threeDSHandler.getPaymentIntent();
# Return value
paymentIntent
object
# handleCardPayment
Call this function to initiate 3DS flow for the entered card details. Based on the Issuing Bank and gateway settings, 3DS flow can be initiated or not. After a successful 3DS authorization, paymentIntent will be marked as authorized. This paymentIntent id can then be used to create subscriptions or create payment methods.
# Return value
Authorized paymentIntent
object
# Syntax
threeDSHandler.handleCardPayment(paymentInfo, callbacks);
# Parameters
# Example
let threeDSHandler = cbInstance.create3DSHandler();
threeDSHandler.handleCardPayment(
{
card: {
firstName: "First Name",
lastName: "Last Name",
number: "xxxx xxxx xxxx xxxx",
cvv: "",
expiryMonth: "10",
expiryYear: "2019",
},
additionalData: {
// you can pass additional information to improve the chances to do a frictionless authorization
billingAddress: {
firstName: "",
lastName: "",
phone: "",
addressLine1: "",
addressLine2: "",
addressLine3: "",
city: "",
state: "",
stateCode: "",
countryCode: "",
zip: "",
},
email: "john@example.com",
phone: "",
},
},
{
change: function (intent) {
// Triggers on each step transition
},
success: function (intent) {
// Triggers when card is 3DS authorized
},
error: function (intent, error) {
// Triggers when 3DS authorization fails
},
}
);
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
# cancel
Call this function to cancel an ongoing 3DS flow. The transaction is cancelled with the gateway, and the payment attempt is refused with authentication failed status.
An error is thrown if no payment intent is set, or if there is no ongoing 3DS transaction.
This cancel
action is primarily used along with challenge
callback implementation, where the 3DS redirection URL is provided.
This function has to be called, after the handleCardPayment
method is called, while there is an ongoing 3DS transaction. This method does not cancel an authorized payment intent.
# Return value
Promise
# Syntax
threeDSHandler.cancel();
# Example
let threeDSHandler = cbInstance.create3DSHandler();
threeDSHandler
.handleCardPayment(
{
card: {
firstName: "First Name",
lastName: "Last Name",
number: "xxxx xxxx xxxx xxxx",
cvv: "",
expiryMonth: "10",
expiryYear: "2019",
},
},
{
challenge: (redirect_url: string) => {
// Open this redirect URL in a popup window
},
}
)
.then((intent) => {
console.log("success");
})
.catch((error) => {
console.error(error);
});
function onCloseWindow() {
threeDSHandler.cancel();
}
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