New in Chargebee: Explore Reveal and understand your payment performance end-to-end.Try Now
Docschargebee docs
HomeBillingCPQPaymentsRevRecGrowthReveal
Support

Product Updates


  • Release Notes

Getting Started


  • Overview
  • Chargebee Billing Data Centers
  • Object Relationship Model
  • Understanding Sites
  • Chargebee Tech Glossary
  • Articles and FAQ

Implementing Chargebee


  • Implementation Guide
  • Go-live Checklist
  • Articles and FAQ

Agentic AI


  • Chargebee Copilot
  • Catalog Setup Assistant
  • MCP Servers

Developer Resources


  • Developer Resources Overview
  • API Explorer
  • Articles and FAQ

Chargebee Apps


  • Chargebee Apps CLI Developer Guide

Product Catalog


  • Product Catalog Overview
  • Coupons
  • Articles and FAQ

Subscriptions


  • Working with Subscriptions
  • Billing
  • Orders
  • Articles and FAQ

Customers


  • Managing Customers
  • Account Hierarchy
  • Email Notifications
  • Branding
  • Configure Multiple Languages
  • Articles and FAQ

Entitlements


  • Entitlements Overview
  • Features Overview
  • Feature Management
  • Managing Product Entitlements
  • Subscription Entitlements
  • Customer Entitlements
  • Grandfathering Entitlements
  • Articles and FAQ

Usage Based Billing


  • Understanding Usages
  • Setting up Usage Based Billing
  • Usage Alerts
  • Prepaid credits

Invoices and Credit Notes


  • Invoices
  • Credit Notes
  • Quotes [Legacy]
  • Transactions
  • Articles and FAQ

Taxes


  • Overview
  • Configuring Taxes
  • Country-specific Taxes
  • Articles and FAQ

Hosted Capabilities


  • Overview
  • Hosted Checkout
    • Integration Options
      • Embedded Checkout
    • Features
    • Configuring Checkout
    • Configuring Fields and Labels
    • Checkout Layout - Feature Comparison
    • FAQ
  • Hosted Self-Serve Portal
  • Hosted Pages Features
  • Additional Hosted Pages
  • Payment Components
  • Pricing Table
  • Mobile SDKs and Wrappers
  • Articles and FAQ

Site Configuration


  • Users & Roles
  • Custom Fields & Metadata
  • Approvals
  • Mandatory Fields
  • File Attachments & Comments
  • Advanced Filter Options
  • Multicurrency Pricing
  • Multi-decimal Support
  • Configuring Reason Codes
  • Events and Webhooks
  • API Keys
  • Time Zone
  • Time Machine
  • Transfer Configurations
  • Articles and FAQ

Multi Business Entity


  • Multi Business Entity Overview
  • Customer Transfer Overview
  • Articles and FAQ

Mobile Subscriptions


  • Overview
  • Omnichannel Subscriptions
  • Omnichannel Subscriptions (Legacy)

Reports and Analytics


  • RevenueStory
  • Home Dashboard
  • Frequently Asked Questions
  • FAQs for Classic Reports Sunset
  • Articles and FAQ

Integrations


  • Sales
  • Customer Support and Success
  • Finance
  • Tax
  • eInvoicing
  • Marketing
  • Stitch
  • Collaboration
  • Contract Management
  • Ecommerce Management
  • Articles and FAQ

Data Privacy & Security


  • Two Factor Authentication
  • SAML Single Sign-On
  • System for Cross-Domain Identity Management (SCIM)
  • EU-GDPR
  • Consent Management
  • Personal Data Management
  • Compliance Certificates
  • HIPAA Guidelines
  • PCI Recommendations and Integration Types
  • Articles and FAQ

Data Operations


  • Bulk Operations
  • Migration
  • Articles and FAQ
  1. Billing
  2. Hosted Capabilities
  3. Hosted Checkout
  4. Integration Options
  1. Billing
  2. Hosted Capabilities
  3. Hosted Checkout
  4. Integration Options

Integration options

Chargebee offers the following options to integrate the Checkout based on your application or website's framework and business model:

  • Hosted Pages API: Recommended if you want to authenticate the user on your end, override payment-related information, handle returning users, and collect additional information.
  • Drop-in Script.
  • Via Payment Link.

Regardless of the integration option you choose, to embed checkout in your website or application, use embedded checkout with Chargebee.js to mount checkout in a container on your page. Do not place hosted page URLs in your own iframe elements—Chargebee.js creates and manages the iframe for you.

When to use API vs. drop-in script

image

Hosted Pages API

Using the Hosted Pages API to create in-app checkout is the recommended approach when you already maintain a user-management or authentication system.

Note

The API generates a Checkout URL that expires 3 hours after creation.

Benefits of using API integration:

  • Manage authentication and collect additional information in your application or website.
  • Override plan and add-on pricing during checkout.
  • Optimize trial tenure. For example, you can offer a 14-day trial to one customer and a one-month trial to another.

Example

Here's an example of when you might choose Checkout via API over the Drop-in Script:

Jenna runs a digital weight loss and fitness app. She wants to collect user information such as the client's height, weight, food habits, and so on, along with their address and email, and store it in her database instead of Chargebee. She would still like to use Chargebee's Checkout as she does not want to handle the details of PCI Compliance.

Jenna can use the API integration to collect additional information on the frontend and rely on Chargebee's Hosted Pages API for payment details.

To learn more about the integration and implementation of Checkout via API, read our developer documentation.

You can use Checkout via APIs for the following workflows:

  • Checkout for new subscriptions
  • Checkout for existing subscription upgrades
  • Checkout for one-time purchases

For end-to-end walkthroughs with server and client code in Ruby, Node.js, Java, Python, PHP, jQuery, Vue, Angular, and React, see Create a new subscription with Chargebee Checkout and Upgrade an existing subscription with Chargebee Checkout.

Call flow

Host an HTTPS endpoint that calls the Chargebee Hosted Pages API and returns a hosted page object.

Server-side call flow for Checkout via the Hosted Pages API

Your application then uses Chargebee.js to open the Checkout.

Client-side call flow for Checkout via the Hosted Pages API

Set up Chargebee.js

Include the Chargebee.js script in your HTML page. You need to do this only once per page.

<script src="https://js.chargebee.com/v2/chargebee.js"></script>

In your JavaScript code, initialize Chargebee to get a Chargebee instance. Use this instance for every subsequent Checkout call.

var cbInstance = Chargebee.init({
  site: "site-name", // Your Chargebee site
  domain: "https://mybilling.acme.com" // Optional. Use this only if a custom domain is enabled for your site.
});

Anywhere else on the page, call Chargebee.getInstance() to retrieve the same instance instead of initializing again.

Warning

Call tearDown() before you call init() again within the same session. Initializing twice without tearing down leaves the previous instance attached to the page.

For the complete initialization reference, including publishable keys, see Set up Chargebee.js in the Chargebee.js Reference.

Open Checkout with the Hosted Pages API

Call openCheckout() on the Chargebee instance. Pass a hostedPage function that returns a promise resolving to the hosted page object your server generates.

var cbInstance = Chargebee.getInstance();
cbInstance.openCheckout({
  hostedPage: function() {
    return $.ajax({
      url: '/generate_hp_url',
      data: data,
      method: 'POST'
    });
  },
  success: function(hostedPageId) {
    // Pass this ID to your server to retrieve the subscription details.
  }
});

Warning

On mobile browsers, Chargebee opens the Checkout in a new window. Open the Checkout in response to a user action, such as a button click. Otherwise, the browser blocks the new window.

Checkout callbacks

openCheckout() accepts the following callbacks in addition to hostedPage:

CallbackWhen it runs
loadedThe Checkout has opened.
errorThe Checkout failed to open. Receives the error.
closeThe customer closed the Checkout.
successThe Checkout completed. Receives the hosted page ID, which you can pass to your server and use with the Retrieve a hosted page API to get the subscription details.
stepThe customer moved to a different step of the Checkout. Receives the step name.

For the full parameter reference, see openCheckout().

Note

To accept PayPal, GoCardless, or Plaid, set embed to false when you create the hosted page. These payment methods redirect the customer away from your site and cannot run inside the embedded Checkout.

Create a hosted page on your server

  1. Create an HTTPS endpoint on your server.
  2. Generate the hosted page object using the API that matches your use case—Checkout new or Checkout existing.
  3. Return the hosted page object to the client.

Warning

Make sure the HTTP response has the content type application/json.

post '/generate_hp_url' do
  # Use the checkout new or checkout existing API based on your use case.
  result = ChargeBee::HostedPage.checkout_new_for_items(params)
  return result.hosted_page.to_s
end

The endpoint returns a hosted page object:

{
  "id": "example_hosted_page_id",
  "type": "checkout_new",
  "url": "https://yourapp.chargebee.com/pages/v3/example_hosted_page_id/",
  "state": "created",
  "embed": true,
  "created_at": 1515494821,
  "expires_at": 1515498421
}

Drop-in script

The Drop-in Script is a plug-in type, easy-to-use solution that requires minimal developer help. You can easily create a checkout page by adding a script generated for the plan item on your HTML page.

Checkout integrated using the Drop-in Script is Level 1 PCI compliant. Therefore, you need to fill out this questionnaire before integrating.

Note:

You should review the following documents from the above page before integrating Checkout using the Drop-in Script:

  1. SAQ Instructions and Guidelines
  2. Understanding SAQs for PCI DSS

The SAQs must be filled out based on the applicability as per the guideline document and shared with the payment gateway. No document needs to be submitted to Chargebee.

The Drop-in Script also handles more advanced cases:

  • Setting Checkout and portal callbacks.
  • Modifying the plan quantity dynamically.
  • Adding and removing addons on demand.
  • Prefilling customer information and shipping information in the Checkout.

To use the Drop-in Script to integrate Checkout, follow these steps:

  1. Click Settings > Configure Chargebee > Checkout and Self-Serve Portal > Integrate with Chargebee.
  2. Select the Product Family, Plan, Currency, and Frequency from the drop-down list.
  3. Add Addons and Charges if applicable using Add Addon and Add Charge options.
  4. Select the Layout to control whether the Checkout opens in-app or as a full page.
image
  1. Copy the Header Script and paste it within the <head> element of your website's HTML.
image
  1. Copy the generated Checkout Button Code and hyperlink it in the Subscribe button on your website's HTML. This way, when a customer clicks the Subscribe button, the Checkout opens and displays the selected parameters of plan name, frequency, addons, and so on.

Information

Checkout Button Code for a particular plan item can also be copied from the respective plan page. Follow these steps to copy the code from a plan page:

  1. Click Product Catalog > Plans > Select a Plan > Select a Price Point.
  2. Navigate to the Customer-Facing Information section, and click Grab Script.
  3. Select addons if necessary and click Copy Code.
  4. The copied script can now be embedded on your website's checkout page.

You can use Checkout via Drop-in for the following workflows:

  • Checkout for new subscriptions
  • Checkout for one-time purchases

For a step-by-step setup guide, including prefilling customer details and changing the cart at runtime, see the Drop-in Checkout with Chargebee.js tutorial.

The generated markup looks like this. The data-cb-item-<n> attributes carry the item price IDs you selected, and data-cb-layout carries the layout.

<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://js.chargebee.com/v2/chargebee.js" data-cb-site="acme-test" data-cb-business-entity-id="__dev__XpbBuzpT02K2kd24"></script>
  </head>
  <body>
    <h3>Checkout Drop-in</h3>
    <a href="javascript:void(0)" data-cb-layout="full_page" data-cb-type="checkout" data-cb-item-0="diamond-USD-monthly" data-cb-item-1="silver-pass-USD-monthly" data-cb-item-1-quantity="2">
      Subscribe
    </a>
  </body>
</html>

Note

If you have multiple business entities enabled, include the data-cb-business-entity-id attribute in the <script> element as shown above.

Warning

On page load, Chargebee.js binds click events to every Drop-in button it finds. If you use Angular, React, or Vue, call Chargebee.registerAgain() after the component mounts to register buttons that Chargebee.js did not see on page load.

Cart customization

Use cart customization when your cart needs dynamic quantity changes or collects extra details through custom fields. It gives you full JavaScript control to add or remove plans, addons, and coupons, and to update quantities.

Set isItemsModel to true during initialization, then build the cart yourself instead of relying on the generated button attributes.

<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://js.chargebee.com/v2/chargebee.js"></script>
  </head>
  <body>
    <h3>Checkout Drop-in</h3>
    <button href="javascript:void(0)" onclick="openCheckout()">
      Subscribe
    </button>
  </body>
  <script>
    var cbInstance, cart;

    window.addEventListener('DOMContentLoaded', function() {
      cbInstance = Chargebee.init({
        site: "acme-test",
        isItemsModel: true,
      })

      cbInstance.setCheckoutCallbacks(function(cart) {
        return {
          success: function(hpid) {
            console.log('success', hpid)
          }
        }
      })

      cart = cbInstance.getCart()
    })

    function openCheckout() {
      const planPriceId = 'diamond-USD-monthly' // Plan price point ID identifies the product.
      const planPriceQuantity = 1
      const product = cbInstance.initializeProduct(planPriceId, planPriceQuantity)
      cart.replaceProduct(product);

      // Add an addon.
      product.addAddon({
        id: "silver-pass-USD-monthly", // Addon price point ID
        quantity: 2
      })

      // Add a coupon.
      product.addCoupon("fourty")

      // Change the plan quantity dynamically.
      product.setPlanQuantity(planPriceQuantity);

      // Remove an addon.
      product.removeAddon("silver-pass-USD-monthly");

      // Pass values for custom fields.
      product.setCustomData({referral: "yes", corporate_agent: "no"});

      // Open the Checkout.
      cart.proceedToCheckout();
    }
  </script>
</html>

Get the plan price point IDs, addon price point IDs, and the rest of the cart parameters from the Product object and Cart object references.

Open Checkout from your own button

You do not have to use the generated button. Build the cart yourself and open the Checkout from any element on your page.

document.addEventListener("DOMContentLoaded", function() {
  let cbInstance = Chargebee.getInstance();
  let cart = cbInstance.getCart();
  let product = cbInstance.initializeProduct("cbdemo_grow");
  cart.replaceProduct(product);
  document.getElementById("subscribe").addEventListener("click", function() {
    cart.proceedToCheckout();
  });
});

Via payment link

When you're looking for a simple and effective way to collect payments from your customers, a payment link can be an excellent solution.

Chargebee lets you create a custom URL to pass product details, customer information, and subscription data during checkout. The resulting Checkout URL can then be embedded into your application or website. You can also share this URL directly with customers through email and text messages.

To use the Payment Link to integrate Checkout, follow these steps:

  1. Click Settings > Configure Chargebee > Checkout & Self-Serve Portal > INTEGRATE WITH CHARGEBEE > Via Payment Link

    image
  2. Choose the Business Entity if applicable. Learn more about multiple business entities.

  3. Choose Checkout Type.

    1. If Subscription,
      1. Select the Product family, Plan, Currency, and Frequency from the drop-down list.
      2. Add Addons and Charges if applicable using Add addon and Add charge options.
      3. You can also add any parameters to pass additional information to the customer or subscription. Sample URL:
      https://honeydukes-test.chargebee.com/hosted_pages/checkout?subscription_items[item_price_id][0]=cbdemo_advanced-USD-monthly&subscription_items[quantity][0]=1&customer[first_name]=Minerva&customer[last_name]=McGonagall&subscription[cf_butterbeer_type]=Frozen Butterbeer
    2. If One-Time Payment:
      1. Choose Currency.
      2. Add Charges if applicable using Add charge options. Sample URL:
      https://honeydukes-test.chargebee.com/hosted_pages/checkout?subscription_items[item_price_id][0]=cbdemo_setup-charge-USD&subscription_items[quantity][0]=1&customer[first_name]=Minerva&customer[last_name]=McGonagall

List of supported query parameters

Here is an API spec of query parameters supported, which can be used in the plan URL:

ModuleQuery Parameter
Subscription Item

subscription_items[item_price_id][index] subscription_items[quantity][index]

Coupons

coupon_ids[index]

Customer

All parameters in Create checkout for a new subscription endpoint can be used.

Exceptions: taxability, consolidated_invoicing

Subscription

subscription[start_date]

subscription[{custom_field_name}], where {custom_field_name} is the API name of the custom field.

Billing address

All billing_address parameters in Create checkout for a new subscription can be used.

Exceptions: validation_status

Note

Passing all mandatory billing_address parameters locks the billing address during checkout - the customer cannot edit it.

Shipping Address

All shipping_address parameters in Create checkout for a new subscription can be used.

Exceptions: validation_status

Business Entity ID

business_entity_id parameter in Create subscription can be used.

You can integrate hosted checkout via Payment Link for the following workflows:

  • Checkout for new subscriptions
  • Checkout for one-time purchases

Articles & FAQs

Pre-filling/Passing custom fields to hosted pages (via Plan URL)
Existing customer with plan based URL in Latest Product Catalog - in-app layout checkout
Why do Plans 'Preview' on the Live site show the configurations of the Test site‌?
Why is the checkout page not loading?
Can I purchase one time add-on for a subscription from the customer portal?
Managing the Payment Source Redirect URL
Redirect URL not working

Show more

Was this article helpful?