API Reference

This reference is for integrating "threeDS helper module" into your application.

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 threeDS handler object

Syntax

Chargebee.init(options)

Parameters

options
Object Required Hide properties
site
String Required
Your site name
domain
String Required if custom domain is enabled
Your custom domain
Eg: https://billing.yourdomain.com
publishableKey
String Required
Your publishable API key

Return value

Chargebee instance object

Example

var chargebeeInstance = Chargebee.init({
    site: "site-name", // your test site
    domain: "https://mybilling.acme.com" // this is an optional parameter.
})


getInstance

This function will return 'chargebee instance' object.

Syntax

Chargebee.getInstance();

Return value

Chargebee instance object

Error will be thrown if instance is not created.

Chargebee instance object

Chargebee instance is used to create threeDS handler object

load3DSHandler

This function will load 3ds-helper module and will intialize threeDS handle object. You can use this approach or the above approach to load 3ds-helper module

Syntax

chargebeeInstance.load3DSHandler()

Return value

Promise that resolves threeDS handler object

Example

chargebeeInstance.load3DSHandler().then((threeDSHandler) => {
    // your code here
});

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

ThreeDS handler object

Example

chargebeeInstance.load('3ds-handler').then(() => {
    let threeDSHandler = chargebeeInstance.create3DSHandler();
    // Your code here
})


ThreeDS Handler Instance

ThreeDS 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

paymentIntent
Payment Intent Required
options
Object Hide properties
stripe
Object
Stripe instance
braintree
Object
Braintree client instance
adyen
Object
Adyen Checkout instance

Example

  chargebeeInstance.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
      })
  })

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. This updated paymentIntent should then be passed to this function.

Syntax

threeDSHandler.updatePaymentIntent(paymentIntent, options)

Parameters

paymentIntent
Payment Intent Required

Example

    let threeDSHandler = chargebeeInstance.create3DSHandler();
    // This payment intent can be loaded while rendering the page or via ajax call
    threeDSHandler.updatePaymentIntent(paymentIntent)

getPaymentIntent

Returns the payment intent object that is currently set in the 3DS handler instance.

Syntax

threeDSHandler.getPaymentIntent()

Return value

paymentIntent object

handleCardPayment

A paymentIntent needs to be created and setup before using this method. Click here to know more

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

paymentInfo
Object Hide properties
element
Object
You can pass gateway specific hosted field instance
card
Object View properties
Card details
tokenizer
Function
A function that returns a gateway's card temp token
additionalData
Object View properties
Additional information that needs to be passed for improving the chances of frictionless checkout
callbacks
Object Hide properties
change
Function
This function will be called during each step of 3DS flow
success
Function
This function will be called if 3DS Authorization is successful
error
Function
This function will be called if 3DS Authorization has failed

Example

  let threeDSHandler = chargebeeInstance.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
    }
  })