# Cart Object
Cart object is meant to provide advanced control while using the drop-in script to dynamically change customer details and product information with the help of the product object. It contains customer related information such as shipping, billing information, and product information.
Use getCart
to retrieve the cart object.
# replaceProduct
Use this method to add plan product to your cart. Use cbInstance.initializeProduct
or cbInstance.getProduct
to get the product object.
# Syntax
cart.replaceProduct(product);
# Parameters
cbInstance.initializeProduct
or cbInstance.getProduct
.# Return value
Returns the Cart object for function chaining.
# Example
function onClickSubscribe(planId) {
const cbInstance = Chargebee.getInstance();
const cart = cbInstance.getCart();
const product = cbInstance.initializeProduct(planId);
cart.replaceProduct(product);
cart.proceedToCheckout();
}
2
3
4
5
6
7
# proceedToCheckout
This method helps to open the checkout.
# Syntax
cart.proceedToCheckout();
# Return value
NA
# Example
function onClickSubscribe(planId) {
const cbInstance = Chargebee.getInstance();
const cart = cbInstance.getCart();
const product = cbInstance.initializeProduct(planId);
cart.replaceProduct(product);
cart.proceedToCheckout();
}
2
3
4
5
6
7
# setBusinessEntity
Sets the business entity context for checkout.
# Syntax
cart.setBusinessEntity(businessEntityId)
# Parameters
# Return value
This function returns a promise.
# setAffiliateToken
Sets subscription affiliate token (opens new window) during checkout.
# Syntax
cart.setAffiliateToken(token)
# Parameters
# Return value
# setCustomer
Use this method to pre-fill customer information, billing address in Checkout, or to pass any hidden fields while creating a subscription. This function also supports customer custom fields.
# Syntax
cart.setCustomer(customer)
2
# Parameters
# Return value
# Example
const cbInstance = Chargebee.getInstance();
const cart = cbInstance.getCart();
const customer = {
first_name: "John",
last_name: "Smith",
locale: "it",
billing_address: {
first_name: "John",
last_name: " Smith",
line1: "132, My Street",
line2: "Kingston, New York",
state_code: "NY",
country: "US",
zip: "12401"
}
};
// Setting custom fields
customer["cf_about_myself"] = "This is short description"
cart.setCustomer(customer);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# setShippingAddress
Use this method to pre-fill shipping address information.
# Syntax
cart.setShippingAddress(shippingAddress)
2
# Parameters
# Return value
# Example
const cbInstance = Chargebee.getInstance();
const cart = cbInstance.getCart();
const shippingAddress = {
first_name: "John",
last_name: " Smith",
line1: "132, My Street",
line2: "Kingston, New York",
state_code: "NY",
country: "US",
zip: "12401"
}
cart.setShippingAddress(shippingAddress);
2
3
4
5
6
7
8
9
10
11
12