An example app integrating Moesif with Chargebee for usage-based billing based Tutorial to Set Up Usage-Based API Billing with Moesif and Chargebee
- Moesif handles API metering and providing usage metrics to customers
- Chargebee handles invoicing customers and accepting payments through a gateway like Stripe.
This example app does a few things:
- Sync Chargebee Subscription info to Moesif
- Handle metered billing webhooks of type pending_invoice_created
- Calculate the usage by querying Moesif's Management API
- Add a line-item charged based on API usage for that customer
- Install all dependencies:
npm install
- Set the following environment variables
Environment variable | Description |
---|---|
CHARGEBEE_SITE | The slug of your Chargebee site which is the subdomain when logging into your dashboard. |
CHARGEBEE_API_KEY | A Chargebee API key that has at least read access to both subscriptions and customers. |
CHARGEBEE_WEBHOOK_USERNAME | The username you define when creating a new webhook in Chargebee |
CHARGEBEE_WEBHOOK_PASSWORD | The password you define when creating a new webhook in Chargebee |
MOESIF_APPLICATION_ID | Your Moesif Application Id displayed during onboarding and found under the API keys menu in Moesif |
MOESIF_MANAGEMENT_API_KEY | A generated management API key which has the scope read:events which can be found under the API keys menu in Moesif |
- Run the example, it will listen on port 5000.
node index.js
- Verify the app works:
- Your Chargebee users and companies will be synced to your Moesif app
- Set up a Chargebee webhook to the app's endpoint
POST /chargebee/webhooks