fedapay-cli
Version:
A command-line tool for FedaPay
108 lines (107 loc) • 4.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const fedapay_1 = require("fedapay");
const json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer"));
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const payouts_1 = tslib_1.__importDefault(require("../payouts"));
const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse"));
/**
* PayoutsCreate Class extending the superClass Payouts
*/
class PayoutsCreate extends payouts_1.default {
async run() {
const { flags } = this.parse(PayoutsCreate);
/**
* @param string
* api-key value
*/
const apiKey = this.userConfig.read('secret_key', flags['api-key']);
/**
* @param String
* sandbox or live
*/
const environment = this.userConfig.read('environment', flags.environment);
/**
* @param object
* parsing data flag input to object
*/
const data = dataparse_1.default.transform(flags.data);
/**
* @param string
* set api-key value for authenticating
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
try {
/**
* @param Payout
* created payout
*/
cli_ux_1.default.action.start('Creating payout');
const payout = await fedapay_1.Payout.create(data);
this.log(json_colorizer_1.default(JSON.stringify(payout, null, 2)));
if (flags['send-now']) {
/**
* @param boolean
* send after create payout
*/
cli_ux_1.default.action.start('Sending payout');
await payout.sendNow();
this.log(chalk_1.default.green('Payout sent'));
}
else if (flags.schedule) {
/**
* @param string
* schedule to a date
*/
cli_ux_1.default.action.start('Scheduling payout');
await payout.schedule(flags.schedule);
this.log(chalk_1.default.green(`Payout schedule for ${flags.schedule}`));
}
}
catch (error) {
this.log('Oups something occured');
this.error(error.message);
}
cli_ux_1.default.action.stop();
}
}
exports.default = PayoutsCreate;
/**
* @param string
* Description of the command payouts:create
*/
PayoutsCreate.description = 'Create a new payout.';
/**
* @param Object
* Insertion of the different commands flags
*/
PayoutsCreate.flags = Object.assign(Object.assign({}, payouts_1.default.flags), { data: command_1.flags.string({
char: 'd',
description: 'Data for the API request.',
required: false,
multiple: true
}), schedule: command_1.flags.string({
description: 'The DateTime of the schedule in the format YYYY-MM-DD HH:mm:ss GMT',
}), 'send-now': command_1.flags.boolean({
description: 'Send automatically the payout.',
default: false
}), help: command_1.flags.help({ char: 'h', description: 'Help for payouts:create.' }) });
/**
* @param string
* Set the command usage for help
*/
PayoutsCreate.usage = 'payouts:create [options]';
/**
* @param string[]
* examples of payouts:create command
*/
PayoutsCreate.examples = [
'payouts:create --api-key=[API-KEY] --environment=[env] -d amount=5000 -d currency[iso]=XOF -d mode=mtn -d customer[firstname]=Qan customer[lastname]=Sally customer[email]=nal@exemple.com customer[phone_number][number]=65423158 customer[phone_number][country]=bj',
'payouts:create --api-key=[API-KEY] --environment=[env] -d amount=5000 -d currency[iso]=XOF -d mode=mtn -d customer[id]=[ID]',
'payouts:create --api-key=[API-KEY] --environment=[env] -d amount=5000 -d currency[iso]=XOF -d mode=mtn -d customer[id]=[ID] --schedule="2020-8-12 11:41:51"',
'payouts:create --api-key=[API-KEY] --environment=[env] -d amount=5000 -d currency[iso]=XOF -d mode=mtn -d customer[id]=[ID] --send-now',
];