Creating a Billing Meter With Chargebee

If you’re looking to monetize your APIs or your application, metered billing could be a perfect solution. With metered billing, users usage is tallied up throughout a designated period and that is how they are billed. Billing meters Moesif will automatically meter the usage for each company and charge your customers via Chargebee. They 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 plan in Chargebee. The integration also syncs subscription and revenue data from Chargebee to Moesif so you can understand how API usage translates to revenue.

A graphical overview of the process looks like this:

example

In this walk-through, we will create a very simple billing meter that integrates and publishes usage data to Chargebee.

To follow this guide you will need:

  • A Moesif account and successful integration with your API(s)
  • A Chargebee account with Metered Billing enabled

There are a few steps after you’ve integrated with Moesif to get you to the point where you can collect revenue. These steps include:

  • Adding the Moesif webhook to Chargebee
  • Plugging the Chargebee API details into Moesif
  • Setting up products and prices in Chargebee
  • Configuring and activating the Billing Meter in Moesif

Let’s get started!

Step 1: Configuring Chargebee in Moesif

To begin configuring Chargebee in Moesif, go to the Billing Meters page and click the Edit Billing Provider dropdown in the top right corner of the screen.

example

This will bring up the Chargebee configuration screen walking you through the integration. From this screen, you can get all of the info needed to plug Chargebee into Moesif. Each step for configuration is covered within the modal.

Step 2: Adding the Moesif Webhook to Chargebee

Our first step in enabling the integration with Moesif is to add the Moesif webhook in Chargebee. To do this, we will first log into Chargebee. Once logged in, in the left-side menu we will click on Configure Chargebee.

example

Once on the Configure Chargebee screen, you wil click on the Webhooks link.

example

On the Webhooks screen, you’ll then want to click the Add Webhook button to bring up the modal to add the Moesif webhook.

example

In the Create a Webhook modal, you will fill in the Webhook URL field and the Username field (details on these fields below). Once these details are filled in, you’ll click Create.

example

These details can be found in Moesif by looking at the details under Step 1 in the integration steps

example

After the webhook has been created, you will then want to test the webhook connectivity. To do this, click on the Test Webhook button.

example

Then, after picking an event to test (any of them will do), click the Test URL button. Once clicked, you should receive a message that says “Successfully received OK response from the webhook”.

If you get another response, you’ll want to go back and make sure that the webhook is configured correctly and test again.

example

Step 3: Adding the Chargebee API key to Moesif

After the webhook is configured, your next step will be to add the Chargebee API key into Moesif. For this, while on the same screen that you configured the webhook on, you’ll click on API Keys and copy the key that is shown under full_access_key_v1.

If you want to use another key that you’ve created, you can also use that as well instead of the test key.

example

You will also need to put your Chargebee site name into Moesif as well. That can be found in the URL bar in your browser.

example

With these details, you will be able to fill in Step 2 on the Moesif configuration page.

example

Step 4: Enabling Metered Billing in Chargebee

Next, we will turn on Metered Billing in Chargebee. For this step, we will navigate back to the Configure Chargebee screen and select Metered Billing.

If the Metered Billing option is not available, you will need to contact Chargebee and ask them to enable Metered Billing on your site. This can be done by emailing Chargebee support.

example

You will then want to set your desired configuration (the recommended configuration is in the image below) and click Apply.

example

After clicking Apply, you will see a confirmation message pop up regarding your changes. Here you will click Confirm.

example

Step 5: Creating the Products

After the above config is complete and integration steps are done for connecting Chargebee and Moesif, we will navigate to Product Catalog > Product Families. On this screen we will click Create Product Family.

example

On the Create a Product Family screen, we will add in our Product family name and click Create in the top right of the screen. In this example, I will use “Monetized APIs” as the product family name.

example

Once the Product Family is created, we can then create a Plan. For that, navigate to the Plans screen and click Create Plan in the top right of the screen.

example

On the Create a New Plan screen, you will fill out the details for:

  • Product Family
  • External name
  • Internal name

You will also need to ensure that This plan is metered is checked off.

After these details are input, click Create.

example

You will then see your new plan displayed on the Plans screen. Now, click on the plan (by clicking on the plan name) so that you can add in the pricing details.

example

Since we will be invoicing monthly, under the Pricing panel, select the Set Price button across from the Monthly billing interval.

example

We will then set the price for this unit of usage. In this example, I will set the price to $0.10 per unit. After setting those details, click Create.

example

Step 6: Creating the Billing Meter

Now that we have a Plan and a Price set up in Chargebee, we can create a billing meter to calculate usage and send to the usage details to Chargebee.

Navigate to New Billing Meter from the left-side menu. From here you will add you billing meter name. In this example I used “Chargebee Billing Meter” but this can be whatever is most relevant to you.

After this, you will select Chargebee as your Billing Provider and pick the Item Plan and Item Price that you’d like usage metrics to be attached to.

Then, You will set up the event filter which outlines which events should be billed upon. In this example I want to charge for any successful call to the /getCreditScore endpoint.

Lastly, I will select the metric to bill upon. In this example I will use Event Count so that every event will be result in a charge. Other options here include:

  • Unique Users
    • This will create a charge for each unique user who uses the endpoint.
  • Unique Sessions/API Keys
    • This will create a charge for each unique session or API key that access the endpoint.
  • Custom
    • This allows you to dial in a custom metric to bill upon if the above don’t fit your needs.

Once you have these details filled out, you’ll click Create in the top right corner.

example

After clicking Create, you’ll need to confirm the creation of the billing meter. If the billing meter is set up correctly, click Create Billing Meter.

example

Now, you’re billing meter will be available on the Billing Meters screen. After a short period of time and API usage, you will begin to see usage data flow over into Chargebee.

example

Note that User and Company tracking must be enabled in Moesif and the correct mapping of values is required to make sure that usage records get associated with the correct subscription. For more info on this, check out the docks which outline these particulars.

Now, we have successfully created a billing meter that will begin to send usage data to Chargebee. This integration is possible in a matter of minutes with no code required.

From Moesif

Updated: