UNPKG

fedapay-cli

Version:
87 lines (86 loc) 3.04 kB
"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 transactions_1 = tslib_1.__importDefault(require("../transactions")); const dataparse_1 = tslib_1.__importDefault(require("../../helpers/dataparse")); /** * TransactionUpdate extending the superClass Transactions */ class TransactionsUpdate extends transactions_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(TransactionsUpdate); /** * @param String * your api's key */ const apiKey = this.userConfig.read('secret_key', flags['api-key']); /** * @param string * environment type */ const environment = this.userConfig.read('environment', flags.environment); /** * Set Apikey and environment to connect to fedapay */ fedapay_1.FedaPay.setApiKey(apiKey); fedapay_1.FedaPay.setEnvironment(environment); try { /** * @param integer * get the id of the transaction */ const id = flags.id; /** * @param Object * The data obtained after transformation */ const data = dataparse_1.default.transform(flags.data); cli_ux_1.default.action.start('Updating transaction'); const transaction = await fedapay_1.Transaction.update(id, data); this.log(json_colorizer_1.default(JSON.stringify(transaction, null, 2))); } catch (error) { this.error(error.message); } } } exports.default = TransactionsUpdate; /** * @params String * Description of the command transactions:update */ TransactionsUpdate.description = 'Update a transaction.'; /** * The command usage * @var string */ TransactionsUpdate.usage = 'transactions:update [options]'; /** * @param object * Declaration of the command flags */ TransactionsUpdate.flags = Object.assign(Object.assign({}, transactions_1.default.flags), { id: command_1.flags.integer({ required: true, description: 'The transaction ID.' }), data: command_1.flags.string({ description: 'Data for the API request.', required: true, multiple: true, char: 'd', }), help: command_1.flags.help({ char: 'h', description: 'Help for transactions:update command.' }) }); /** * @param Sting[] * Some example of use of the transaction:update command */ TransactionsUpdate.examples = [ 'transactions:update --api-key=[API-KEY] --environment=[env] --id=[ID] -d amount=2500', 'transactions:update --api-key=[API-KEY] --environment=[env] --id=[ID] -d amount=1780 -d customer[email]=geronimo@apache.com' ];