1.0.1 • Published 3 years ago

fusebill-js v1.0.1

Weekly downloads
8
License
-
Repository
-
Last release
3 years ago

fusebill-js-sdk

Javascript / node.js wrapper for the Fusebill API

Installing

npm install fusebill-js

Instantiate client

const Fusebill = require('fusebill-js')
const fusebill = new Fusebill({
  apiKey: 'abc',
  checkLimit: false // (Optional) Specify whether to check the API limit on each call. Default: true
})

To change the base url:

const fusebill = new Fusebill({ apiKey: YOUR_API_KEY, baseURL: 'https://some-url' })

Changing rate limiter options

Bottleneck is used for rate limiting. To override the default settings, pass a limiter object when instantiating the client. Bottleneck options can be found here.

const fusebill = new Fusebill({
  apiKey: YOUR_API_KEY,
  limiter: {
    maxConcurrent: 2,
    minTime: 1000 / 9,
  }
})

Usage

All methods return a promise. The success case includes the returned object from the response. Use the API method via:

fusebill.catalog.plans
  .list(options)
  .then(results => {
    console.log(results)
  })
  .catch(err => {
    console.error(err)
  })

Samples

Please see repository with samples applications with common cases.

API limits

Fusebill has API limits (180,000 per day by default). To prevent from consuming it all-at-once, this library checks API quotas regularly and will fail requests if the total is too close to the max. By default

Available Methods

Index

// plans
fusebill.catalog.plans.list(opts)
fusebill.catalog.plans.read(planId, opts)

// products
fusebill.catalog.products.summary(opts)
fusebill.catalog.products.list(opts)
fusebill.catalog.products.read(productId, opts)

// plan products
fusebill.catalog.planProducts.listByPlan(planId, opts)
fusebill.catalog.planProducts.listByCatalogProduct(productId, opts)
fusebill.catalog.planProducts.read(planProductId, opts)
fusebill.catalog.planProducts.patch(data)

// plan families
fusebill.catalog.planFamilies.list(opts)
fusebill.catalog.planFamilies.listByPlanId(planId, opts)
fusebill.catalog.planFamilies.read(planFamilyId, opts)
fusebill.catalog.planFamilies.readBySubscriptionId(subscriptionId, opts)

// discounts
fusebill.catalog.discounts.list(opts)
fusebill.catalog.discounts.read(discountId, opts)

// custom fields
fusebill.catalog.customFields.updateOnSubscription(data)
fusebill.catalog.customFields.updateOnSubscriptionProduct(data)
fusebill.catalog.customFields.updateOnPurchase(data)

Not wrapped endpoint(s)

It is possible to access the fusebill request method directly, it could be handy if wrapper doesn't have implementation for some endpoint yet. Using of exposed request method benefits by the bottleneck throttling, auth and request parsing and formatting already in place

Note: This library uses Axios for http calls.

fusebill.apiRequest({
  method: 'PUT',
  path: '/some/api/not/wrapped/yet',
  data: { key: 'value' }
})
 // qs is not part of axios and we use this for custom transformations on query
fusebill.apiRequest({
  method: 'GET',
  path: '/some/api/not/wrapped/yet',
  qs: { query: { someKey: 'someValue'}, pageSize: 100}
})