UNPKG

fedapay-cli

Version:
83 lines (82 loc) 2.83 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 = require("cli-ux"); const chalk_1 = tslib_1.__importDefault(require("chalk")); const transactions_1 = tslib_1.__importDefault(require("../transactions")); /** * TransactionToken class extending super class Transactions */ class TransactionsToken extends transactions_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(TransactionsToken); /** * @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); /** * @param integer * get the id of the transaction */ const id = flags.id; try { cli_ux_1.cli.action.start('Retrieve Transaction'); /** * @param Transaction * When we got a match the variable is filled up with a transaction object */ const transaction = await fedapay_1.Transaction.retrieve(id); cli_ux_1.cli.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(error.message); } } } exports.default = TransactionsToken; /** * @params String * Description of the command transactions:token */ TransactionsToken.description = 'Generate a payment token for a transaction.'; /** * The command usage * @var string */ TransactionsToken.usage = 'transactions:token [options]'; /** * @param object * Declaration of the command flags */ TransactionsToken.flags = Object.assign(Object.assign({}, transactions_1.default.flags), { id: command_1.flags.integer({ required: true, description: 'The transaction ID' }), help: command_1.flags.help({ char: 'h', description: 'Help for transactions:token command.' }) }); /** * @param String[] * Some example with the token command */ TransactionsToken.examples = [ 'transactions:token --api-key=[API-KEY] --environment=[env] --id=[ID]', ];