Creating a Billing Meter With Recurly

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 automatically meter the usage for each company and charge your customers via Recurly. 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 Product and Price in Recurly. The integration also syncs subscription and revenue data from Recurly to Moesif so you can understand how API usage translates to revenue.

A graphical overview of the process looks like this:

example

In this walkthrough, we will create a very simple billing meter that integrates and publishes usage data to Recurly.

To follow this guide you will need:

  • A Moesif account and successful integration with your API(s)
  • A Recurly account

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:

  • Setting up plans and add-ons in Recurly
  • Adding the Moesif webhook to Recurly
  • Plugging the Recurly API details into Moesif
  • Configuring the billing parameters in Moesif
  • Activating the billing meter

Let’s get started!

Setting up plans and add-ons in Recurly

The first step to monetizing is to actually set up some plans in Recurly for usage to be billed against. To set up a plan in Recurly you’ll need to use the left-side menu to click on Configurations and then Plans.

example

Once you are on the Plans screen, you can click New Plan in the top right of the screen to create a new plan.

example

The plans can contain whatever configuration you need, but you must ensure that at least one Add-on is created. The add-on must be configured as:

  • Customer to be billed at end of the billing cycle
  • Charges are based on price per unit

Configuring this in a Recurly plan will look like this:

example

Once your plan is configured, click Create Plan at the bottom of the screen.

example

At this point, we now have a plan that we can integrate with Moesif and begin billing for usage.

Configuring Recurly in Moesif

Once your plans and add-ons are created, it’s time to begin to integrate Recurly with Moesif. To begin configuring Recurly in Moesif by going to the Billing Meters page and clicking the Edit Billing Provider dropdown in the top right corner of the screen.

example

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

Adding the Moesif webhook to Recurly

The first step in the integration is to add the Moesif webhook into the configuration in Recurly. Adding this allows Recurly to send subscription updates to Moesif.

To add the Moesif webhook to Recurly, from the left-side menu in Recurly select Integrations, and then Webhooks.

example

This will bring you to the Webhooks page where you can view existing webhooks and add new ones. To add a new webhook we will click the Configure button in the top right corner of the screen.

example

On the next screen, you’ll need to click the New Endpoint button in the top right corner of the screen.

example

From here we will plug in our Moesif API endpoint URL into the ENDPOINT URL field and add our Moesif Application ID into the HTTP AUTH USERNAME field.

example

Nothing should be entered in the HTTP AUTH PASSWORD field.

These details can all be found on the Recurly configuration page in Moesif mentioned in the previous section.

example

Plugging the Recurly API details into Moesif

For Moesif to add usage quantities to subscriptions in Recurly, we need to add the Recurly API details into Moesif. This is done in the Recurly configuration screen in Moesif, the same screen we’ve been working with previously.

example

Currently, Moesif only supports v3 of the Recurly API so that value is default and uneditable for the Recurly API Version field.

For the Recurly API Key field, you’ll need to retrieve the API key from Recurly to plug it in. To do that, in the left side menu click on Integrations and select API Credentials. You’ll then be able to see the private key for your API in the Default API Key field on the screen.

example

After copying the key from Recurly, you’ll paste this key into the Recurly API Key field back in Moesif. After doing this, back in Moesif you can scroll down to the bottom of the screen and click Save to save the configuration.

example

At this point, your Recurly integration is complete in Moesif and you can begin to use it.

Optionally, you have the ability to customize the Customer ID Source in Moesif as well. The default should work fine for most purposes but if you do need to customize it, it will allow you to specify how to map the Recurly subscription and account field to the company ID and user ID in Moesif.

Configuring the billing parameters in Moesif

Once the integration with Recurly is added, you can configure your billing parameters in Moesif. If you haven’t done so already, you’ll want to create a new Billing Meter. To do this, from Moesif you’ll need to click on the Billing Meter link in the left side menu as you did when you started the Recurly integration.

Once you’re on the Billing Meters screen, you’ll click the + Add Billing Meter button to begin creating a new billing meter.

example

Once on the Add Billing Meter screen, you’ll add in:

  • Billing meter name
  • Billing provider info
  • Add the filter to specify what events to bill upon

In the below example I have set up a billing plan called “My Billing Plan” which uses Recurly as my billing provider. I’ve also decided to bill on any API call which has a response of 200 OK.

example

Once you have your details dialed in, you’ll see a visual representation of the filter output at the bottom of the screen. Although billing will only happen going forward, you will be able to see historically how your filter is working with existing data. This can help to make sure, especially with more complex filtering, that you have everything configured the way you require it.

example

Activating the billing meter

Our final step in monetization is to save and activate the billing meter. To do this we simply need to make sure that billing meter is turned on at the top of the configuration page.

example

And lastly, we need to click Create at the top of the screen.

example

You’ll then be prompted to confirm the billing meters creation in the modal that pops up after clicking on the Create button.

It’s important to note that once a billing meter is created, the criteria for filtering can not be changed nor the billing provider details. Only the name can be changed as well as the status of the billing meter can be toggled on and off. This is for compliance and auditing purposes. Billing meters can also not be deleted but can be archived if no longer in use.

example

We should now see our new billing meter appear back on the Billing Meters home page.

example

Now, we have successfully created a billing meter that will begin to send usage data to Recurly. This integration is possible in a matter of minutes with no code required. For further info, you can also check out our docs.

Updated: