bl-airtime-plugin-manager
v1.1.1
Published
BongoLive Airtime plugins manager. Manage lifecycle of the Operators/Billing plugins
Downloads
8
Readme
AIRTIME PLUGIN MANAGER
The plugins manager facilitates communication between MO and internal API through plugins.
Installation
# Using npm
npm -i airtime-plugin-manager --save
# Using yarn
yarn add airtime-plugin-manager
Usage
In order for the plugin to be effective, you need to import PluginManager
and extend either BasePlugin
or BaseBillingPlugin
as per your need.
Extend
BasePlugin
if you need to add new operator. ExtendBaseBillingPlugin
if you want to implement new logic for the billing.
Example:
Configuring the PluginManager
// Some where in your application entry e.g. app.js
const {PluginManager} = require('airtime-plugin-manager');
const path = require('path');
// Url pointing to the rabbitmq message.
const qUrl = 'amq://127.0.0.1';
// Internal messaging channel
const topic = 'disbursement';
new PluginManager()
// Configuration
.withConfig(path.join(__dirname, 'config.yaml'))
// We will eventually remove this (deprecated)
.useLogger(logger)
// Define the rabbitmq url
.rabbitMQUrl(qUrl)
// Define the queue channel
.rabbitMQTopic(topic)
// Define the path where the plugins will be found.
.pluginsPath(path.join(__dirname, 'plugins'))
// Spin the plugins manager
.run();
Developing the plugins
New MO plugin named my_new_mo.js
// This plugin is located at <root>/plugins/my_new_mo.js
const {BasePlugin} = require('airtime-plugin-manager');
class MyNewMoPlugin extends BasePlugin {
constructor() {
super();
}
// This is where you perform the transfer.
doTransfer(amount, msisdn) {
super.doTransfer(amount, msisdn);
}
}
New MO Billing plugin named my_new_mo_billing.js
// This plugin is located at <root>/plugins/billing/my_new_mo_billing.js
const {BaseBillingPlugin} = require('airtime-airtime-manager');
class MyNewMoBillingPlugin extends BaseBillingPlugin {
constructor() {
super();
}
onBlockCredits(args) {
// Block credits...
}
onDebitAccount(args) {
// Debit Account. Transaction went through
}
onCreditAccount(args) {
// Credit account. Transaction failed.
}
}
Integrating to your project.
To intergrate the airtime-plugin-manager
to your project, you need to specify your configuration in .yaml
file.
Assume the file named config.yaml
with the following options
new_mo:
name: my_mo_plugin
billing: my_mo_billing_plugin
That's it!