UNPKG

fedapay-cli

Version:
100 lines (99 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const command_1 = require("@oclif/command"); const cli_ux_1 = tslib_1.__importDefault(require("cli-ux")); const fedapay_1 = require("fedapay"); const json_colorizer_1 = tslib_1.__importDefault(require("json-colorizer")); const chalk_1 = tslib_1.__importDefault(require("chalk")); const transactions_1 = tslib_1.__importDefault(require("../transactions")); const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse")); /* * TransactionCreate Class extending the superClass Transactions */ class TransactionsCreate extends transactions_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(TransactionsCreate); /** * @param String * your api's key */ 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 * The data obtained after transformation */ 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 { /** * @param Transaction * Created transaction */ cli_ux_1.default.action.start('Retrieve transaction'); const transaction = await fedapay_1.Transaction.create(data); this.log(chalk_1.default.green('Transaction created successfully!')); this.log(json_colorizer_1.default(JSON.stringify(transaction, null, 2))); if (flags['with-token']) { /** * @param Object * Your token */ cli_ux_1.default.action.start('Generating transaction token'); const token = await transaction.generateToken(); this.log(chalk_1.default.bold.italic('Your token is : ')); this.log(json_colorizer_1.default(JSON.stringify(token, null, 2))); } } catch (error) { this.log('Oups something occured'); this.error(error.message); } cli_ux_1.default.action.stop(); } } exports.default = TransactionsCreate; /** * @params String * Description of the command transactions:create */ TransactionsCreate.description = 'Create a new transaction.'; /** * The command usage * @var string */ TransactionsCreate.usage = 'transactions:create [options]'; /** * @params Object * Insertion of the different commands flags */ TransactionsCreate.flags = Object.assign(Object.assign({}, transactions_1.default.flags), { data: command_1.flags.string({ char: 'd', description: 'Data for the API request.', required: true, multiple: true, }), 'with-token': command_1.flags.boolean({ description: 'add the token to your transactions.', default: false, }), help: command_1.flags.help({ char: 'h', description: 'Help for transactions:create.' }) }); /** * @param Sting[] * Some example of use of the transaction:create command */ TransactionsCreate.examples = [ 'transactions:create --api-key=[API-KEY] --environment=[env] -d amount=2500 -d description="Sending money to mum" -d currency[iso]=XOF -d customer[email]=john.doe@example.com', 'transactions:create --api-key=[API-KEY] --environment=[env] --with-token -d amount=2500 -d description="Sending money to mum" -d currency[iso]=XOF -d customer[email]=john.doe@example.com' ];