UNPKG

fedapay-cli

Version:
93 lines (92 loc) 3.21 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 cli_ux_1 = tslib_1.__importDefault(require("cli-ux")); const chalk_1 = tslib_1.__importDefault(require("chalk")); const transactions_1 = tslib_1.__importDefault(require("../transactions")); /** * TransactionDelete class extending super class Transactions */ class TransactionsDelete extends transactions_1.default { async run() { /** * @param object * get flags value */ const { flags } = this.parse(TransactionsDelete); /** * @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 { /** * @param Transaction * result of the retrieve */ cli_ux_1.default.action.start('Retrieving transaction'); const transaction = await fedapay_1.Transaction.retrieve(id); const confirm = flags.confirm || await cli_ux_1.default.confirm('Are you sure to continue? [Y/n]'); if (confirm) { cli_ux_1.default.action.start('Deleting transaction'); await transaction.delete(); this.log(chalk_1.default.green('Transaction deleted successfully.')); } else { this.log(chalk_1.default.yellow('Deletion canceled.')); } } catch (error) { this.error(error.message); } cli_ux_1.default.action.stop(); } } exports.default = TransactionsDelete; /** * @params String * Description of the command transactions:delete */ TransactionsDelete.description = 'Delete a transaction.'; /** * The command usage * @var string */ TransactionsDelete.usage = 'transactions:delete [options]'; /** * @param object * Declaration of the command flags */ TransactionsDelete.flags = Object.assign(Object.assign({}, transactions_1.default.flags), { id: command_1.flags.integer({ description: 'The transaction ID.', required: true, }), confirm: command_1.flags.boolean({ description: 'Skip the warning prompt and automatically confirm the command being entered.', default: false, char: 'c' }), help: command_1.flags.help({ char: 'h', description: 'Help for transactions:delete.' }) }); /** * @param String[] * Some example of use of the delete command */ TransactionsDelete.examples = [ 'transactions:delete --api-key=[api_key] --environment=[env] --id=[ID]', 'transactions:delete --api-key=[api_key] --environment=[env] --id=[ID] -c', ];