Track usage for billing

If your product offers a usage based billing component such as monthly active users then you will need a way to track usage and calculate the invoice total at the end of each period.

Bunny provides an API for tracking feature usage and will take care of the billing calculations for you.

Usage calculations

When a usage based charge is added to a price list in Bunny you will need to set the Usage Calculation Type to one of the following values. This will determine how the usage is calculated at billing time.

  • Sum - Default. The billing process will take a sum of quantity values for all feature usage records created during the billing period.

  • Max - The billing process will take the maximum quantity value from all feature usage records created during the billing period.

  • Last - The billing process will take the quantity value of the last feature usage record created during the billing period.

Prerequisites

Before you can start tracking feature usage from your SaaS application you need to complete the following steps on the Bunny side first.

  1. Create a Feature in Bunny with Is Unit enabled. Then create a product plan and price list with a usage based charge using the feature unit. Take note of the code that you set for the feature as you will need that in the next step.

  2. Create a subscription based on the plan and price list that you setup in the previous step and take note of the Subscription ID number.

Create a feature usage record

Feature usage is tracked via the featureUsageCreate mutation. If the usageAt attribute is not supplied then it will default to the current datetime.

FeatureUsageAttributes

{
  "attributes": {
    "quantity": 1,
    "usageAt": "2018/10/21 11:53:12 00",
    "subscriptionId": 123456,
    "featureCode": "users"
  }
}

Mutation

mutation featureUsageCreate ($attributes: FeatureUsageAttributes!) {
  featureUsageCreate (attributes: $attributes) {
    errors
  }
}

Last updated

Was this helpful?