Class: Zold::Pay
- Inherits:
-
Object
- Object
- Zold::Pay
- Defined in:
- lib/zold/commands/pay.rb
Overview
Money sending command
Instance Method Summary collapse
-
#initialize(wallets:, remotes:, log: Log::Quiet.new) ⇒ Pay
constructor
A new instance of Pay.
- #run(args = []) ⇒ Object
Constructor Details
Instance Method Details
#run(args = []) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/zold/commands/pay.rb', line 41 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "Usage: zold pay wallet target amount [details] [options] Where: 'wallet' is the sender's wallet ID 'target' is the beneficiary (either wallet ID or invoice number)' 'amount' is the amount to pay, in ZLD, for example '14.95' 'details' is the optional text to attach to the payment Available options:" o.string '--private-key', 'The location of RSA private key (default: ~/.ssh/id_rsa)', require: true, default: '~/.ssh/id_rsa' o.bool '--force', 'Ignore all validations', default: false o.bool '--dont-pay-taxes', 'Don\'t pay taxes even if the wallet is in debt', default: false o.bool '--skip-propagate', 'Don\'t propagate the paying wallet after successful pay', default: false o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return raise 'Payer wallet ID is required as the first argument' if mine[0].nil? id = Id.new(mine[0]) from = @wallets.find(id) raise "Wallet #{id} doesn't exist, do 'zold pull' first" unless from.exists? raise 'Recepient\'s invoice or wallet ID is required as the second argument' if mine[1].nil? invoice = mine[1] unless invoice.include?('@') require_relative 'invoice' invoice = Invoice.new(wallets: @wallets, log: @log).run(['invoice', invoice]) end raise 'Amount is required (in ZLD) as the third argument' if mine[2].nil? amount = Amount.new(zld: mine[2].to_f) details = mine[3] || '-' if Tax.new(from).in_debt? && !opts['dont-pay-taxes'] require_relative 'taxes' Taxes.new(wallets: @wallets, remotes: @remotes, log: @log).run( ['taxes', "--private-key=#{opts['private-key']}", id.to_s] ) end pay(from, invoice, amount, details, opts) return if opts['skip-propagate'] require_relative 'propagate' Propagate.new(wallets: @wallets, log: @log).run(['propagate', from.id.to_s]) end |