Integrating with Chargebee

This page assumes that you already have a Chargebee account created, have metered billing enabled, and are able to create plans. To sign-up and create a Chargebee account, visit the Chargebee website.

If metered billing is not enabled, you’ll need to contact support@chargebee.com to enable the feature on your Chargebee site.

How it works

A billing meter is created via the Moesif UI for a specific metric and filter criteria that you want to charge for.

  • The filter criteria defines what the meter should include such as specific endpoints, certain customers, or other filter criteria.
  • The metric is what is metered. It could be number of API calls, unique users, an aggregation on a header or body field, or any other metric trackable by Moesif.

Once the billing meter is created, Moesif will automatically meter the usage for each company and charge your customers via Chargebee. Moesif billing meters support a variety of billing models including prepaid, postpaid, Pay As You Go (PAYG) and more. If you have different features or metrics you need to charge on, you can create multiple meters in Moesif, each linked to a different Plans and Prices in Chargebee. The integration also syncs subscription and revenue data from Chargebee to Moesif so you can understand how API usage translates to revenue.

Example

Prerequisites

In order to integrate Chargebee with Moesif, there are a few prerequisites which must be completed. These include:

  1. Creating an account with Chargebee
  2. Creating a plan in Chargebee

The plan must have This plan is metered set to true in order for usage to be updated correctly by Moesif. It is also recommended that the process charges for shared usage data by field be set to sum of usage values during period.

Example

Configuring the Chargebee integration

Moesif’s connection with Chargebee involves 2-way communication. Moesif has created a simple way to get all the info you need and to configure certain variables for Chargebee in a single screen.The Chargebee setup details screen can be accessed a few ways, including:

Through Settings > Extensions

Example

and then selecting install on the Chargebee extension

Example

Through the Billing Meters screen Edit Billing Providers dropdown

Example

And through the Create New Billing Meter screen

Example

Once you’ve opened the configuration screen through one of the routes above, you can get the info needed to add the Moesif Webhook to Chargebee, inputs to plug the Chargebee API into Moesif, and customize your Customer ID source in a single place.

Adding the Moesif Webhook to Chargebee

In Chargebee, a Webhook needs to be added so that Chargebee can send subscription updates to Moesif. To do this you’ll need to make sure you are logged into your Chargebee account. Once logged in, use the left-side menu to click on the Settings > Configure Chargebee menu item.

Example

Once you’re on the Configure Chargebee page click on Webhooks item in the scrollable list.

Example

Then, Click on the Add Webhook button.

Example

Lastly, add the Moesif Webhook URL into the Webhook URL field and the Moesif Application ID into the Username field. Then click on the Create button.

If not selected, you will need to enable Protect webhook URL with basic authentication.

Example

The Endpoint URL value you add to Chargebee should also contain your Moesif Application ID. The generated URL in the Moesif installation page will already contain the correct Application ID and have it appended to the URL.

Now that the webhook is created, Chargebee also allows you to test it. This can be done by clicking on the Test Webhook button.

Example

Click Test URL. The results should show Successfully received OK response from the webhook.

Example

Configuring the Chargebee extension in Moesif

In Moesif, you will need to plug in the Chargebee API details so that Moesif can post usage details to Chargebee to bill upon. These details can be entered into the Chargebee API Version, Chargebee API Key, and Site fields on the Chargebee Setup Details screen.

Currently, Moesif only supports v2 of the Chargebee API.

The Chargebee API Key can be found by navigating to the Configure Chargebee screen and clicking on API Keys from the scrollable menu.

Example

On the API Keys screen, copy the full_access_key_v1.

Example

Copy the value listed under full_access_key_v1 and paste it into the Chargebee API Key field on the Chargebee Setup Details screen.

Lastly, grab the Site name from your URL bar in your browser and paste it into the Site field.

Example

The filled out entries will look similar to this.

Example

Once completed, be sure to click Save.

Customizing the Customer ID source

The Customize Customer ID Source configuration on the Chargebee Setup Details screen allows users to specify the Chargebee subscription and customer field that Moesif will use as the Moesif company id and Moesif user id respectfully.

Example

Linking a plan in Chargebee to a billing meter

When creating a new billing meter, in the Link To section you can specify Chargebee as the Billing Provider and then select the Item Plan and Item Price you’d like the usage to be linked to.

Example

Updated: