# Product Object
# Overview
The Product object represents the item prices (opens new window) to be used in checkout. The plan item price (opens new window) is set when you create the Product object using initializeProduct() or getProduct(). You can then use the Product object to change plan quantities, add addon and charge item price, coupons, and manage subscription details before proceeding to checkout.
# Prerequisites
Before using the Product object, ensure you have:
- Initialized Chargebee.js in your application
- Set up the product catalog (opens new window) in Chargebee Billing.
# Create the Product object
You can retrieve the Product object from a drop-in script element using the getProduct() method, or create a product programmatically using the initializeProduct() method.
# setPlanQuantity(planQuantity)
Sets the quantity for the plan item price (opens new window) in the product.
# Syntax
product.setPlanQuantity(planQuantity)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.initializeProduct("premium_plan");
product.setPlanQuantity(10);
2
# setPlanQuantityInDecimal(decimalQty)
Sets a decimal value for the plan item price (opens new window) quantity in the product.
# Syntax
product.setPlanQuantityInDecimal(decimalQty)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.initializeProduct("high_speed");
product.setPlanQuantityInDecimal("15.737");
2
# incrementPlanQuantity()
Increments the plan item price (opens new window) quantity by 1.
# Syntax
product.incrementPlanQuantity()
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.initializeProduct("premium_plan");
product.setPlanQuantity(10);
function onIncreaseQuantity() {
product.incrementPlanQuantity();
}
2
3
4
5
6
# decrementPlanQuantity()
Decrements the plan item price (opens new window) quantity by 1.
# Syntax
product.decrementPlanQuantity()
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.initializeProduct("premium_plan");
product.setPlanQuantity(10);
function onDecreasePlanQuantity() {
product.decrementPlanQuantity();
}
2
3
4
5
6
# addAddon(addon)
Adds an addon item price (opens new window) to the product. You can pass either an addon ID string or an addon object with addon ID and quantity.
# Syntax
product.addAddon(addon)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
// Add addon with quantity.
product.addAddon({
id: "silver-pass-USD-monthly", // Addon price point ID.
quantity: 2
});
// Add addon with default quantity.
product.addAddon("silver-freebies-1");
2
3
4
5
6
7
8
# removeAddon(addon)
Removes an addon item price (opens new window) from the product. You can pass either an addon object with id or an addon ID string.
# Syntax
product.removeAddon(addon)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
// Remove addon using object
product.removeAddon({id: "Medication-reminders-USD-Monthly"});
// Remove addon using ID string
product.removeAddon("Medication-reminders-USD-Monthly");
2
3
4
5
# setAddons(addons)
Sets one or more addon item prices (opens new window) for the product, replacing any existing addons.
# Syntax
product.setAddons(addons)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.getProduct(element);
product.setAddons([
{
id: "reports-USD-monthly",
quantity: 5,
},
{
id: "reminders-USD-monthly",
}
]);
2
3
4
5
6
7
8
9
10
# incrementAddonQty(addonId)
Increments the quantity of a specific addon item price (opens new window) by 1.
# Syntax
product.incrementAddonQty(addonId)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.getProduct(element);
const reportsAddon = {
id: "reports-USD-monthly",
quantity: 10,
};
product.addAddon(reportsAddon);
function onIncreaseAddonQuantity() {
product.incrementAddonQty("reports-USD-monthly");
}
2
3
4
5
6
7
8
9
10
# decrementAddonQty(addonId)
Decrements the quantity of a specific addon item price (opens new window) by 1.
# Syntax
product.decrementAddonQty(addonId)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.getProduct(element);
const reportsAddon = {
id: "reports-USD-monthly",
quantity: 10,
};
product.addAddon(reportsAddon);
function onDecreaseAddonQuantity() {
product.decrementAddonQty("reports-USD-monthly");
}
2
3
4
5
6
7
8
9
10
# setCharges(charges)
Set one or more charge item prices (opens new window) for the product, replacing any existing charges.
# Syntax
product.setCharges(charges)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.setCharges([
{
id: "installation-charge",
quantity: 1,
},
{
id: "service-charge",
quantity: 1
}
]);
2
3
4
5
6
7
8
9
10
# addCharge(chargeItem)
Adds a charge item price (opens new window) to the product.
# Syntax
product.addCharge(chargeItem)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.addCharge({
id: "installation-charge"
});
2
3
# removeCharge(chargeId)
Removes a charge item price (opens new window) from the product.
# Syntax
product.removeCharge(chargeId)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.removeCharge("installation-charge");
# incrementChargeQty(chargeId)
Increments the quantity of a specific charge item price (opens new window) by 1.
# Syntax
product.incrementChargeQty(chargeId)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.addCharge({
id: "membership-charges",
quantity: 1,
});
function addMember() {
product.incrementChargeQty("membership-charges");
}
2
3
4
5
6
7
8
# decrementChargeQty(chargeId)
Decrements the quantity of a specific charge item price (opens new window) by 1.
# Syntax
product.decrementChargeQty(chargeId)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.addCharge({
id: "membership-charges",
quantity: 10,
});
function removeMember() {
product.decrementChargeQty("membership-charges");
}
2
3
4
5
6
7
8
# addCoupon(couponCode)
Adds a coupon (opens new window) to the product.
# Syntax
product.addCoupon(couponCode)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.getProduct(element);
product.addCoupon("weekend_off_50");
2
# removeCoupon(coupon)
Removes a coupon from the product.
# Syntax
product.removeCoupon(coupon)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
const product = chargebee.getProduct(element);
product.removeCoupon("weekend_off_50");
2
# setCustomData(data)
Sets subscription-level custom fields for the product. This information is passed and pre-filled in checkout automatically.
# Syntax
product.setCustomData(data)
# Parameters
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.setCustomData({
cf_data1: "test",
cf_data2: "test2"
});
2
3
4
# getLayout()
Gets the current layout (opens new window) of the checkout page.
# Syntax
product.getLayout()
# Return value
Returns a string representing the current layout.
# Example
const layout = product.getLayout();
# setLayout(layoutName)
Sets the layout (opens new window) of the checkout page.
# Syntax
product.setLayout(layoutName)
# Parameters
in_app
full_page
# Return value
Returns the Product object for method chaining, allowing you to call additional product methods.
# Example
product.setLayout("in_app");