fedapay-cli
Version:
A command-line tool for FedaPay
79 lines (78 loc) • 2.72 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 = require("cli-ux");
const customers_1 = tslib_1.__importDefault(require("../customers"));
const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse"));
/**
* CustomersCreate class extending the superClass Customers
*/
class CustomersCreate extends customers_1.default {
async run() {
/**
* @param object
* get flags value
*/
const { flags } = this.parse(CustomersCreate);
/**
* @param string
* api key value
*/
const apiKey = this.userConfig.read('secret_key', flags['api-key']);
/**
* @param string
* environment type
*/
const environment = this.userConfig.read('environment', flags.environment);
/**
* @param object
* result of transforming flags.data into Typescript Object
*/
const data = dataparse_1.default.transform(flags.data);
/**
* Set Apikey and environment to connect to fedapay
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
try {
cli_ux_1.cli.action.start('Creating customer');
const customer = await fedapay_1.Customer.create(data);
this.log(json_colorizer_1.default(JSON.stringify(customer, null, 2)));
}
catch (error) {
this.error(error.message);
}
cli_ux_1.cli.action.stop();
}
}
exports.default = CustomersCreate;
/**
* @param string
* Description of the command Customer:create
*/
CustomersCreate.description = 'Create a new customer.';
/**
* @param object
* Declaration of the command flags
*/
CustomersCreate.flags = Object.assign(Object.assign({}, customers_1.default.flags), { data: command_1.flags.string({
description: 'Data for the API request.',
required: true,
char: 'd',
multiple: true
}), help: command_1.flags.help({ char: 'h', description: 'Help for customers:create.' }) });
/**
* @param string
* Set the command usage for help
*/
CustomersCreate.usage = 'customers:create [options]';
/**
* @param string[]
* some examples of the custommers create use for help
*/
CustomersCreate.examples = [
'customers:create --api-key=[API-KEY] --environment=[env] -d firstname=John -d lastname=Doe -d email=customertest1@tom.com -d phone_number[number]=68452896 -d phone_number[country]=BJ'
];