app/models/perfect_money_merchant/account.rb
# Transfer money to whatever perfect money account
# @param [String] payee_account payee account code number
# @param [Float] amount amount of money
# @return [Hash] Perfect Money http response body
#
# PerfectMoneyMerchant::Account.transfer('U8259997',0.01)
Transfer money to whatever perfect money account
Transfer money to whatever perfect money account
def transfer!(payee_account, amount)
				if payee_account =~ /\A([UE])\d{7}\z/
					currency = $1 == 'U' ? 'usd' : 'eur'
					account = joins(:units).
						where.not(login: nil, password: nil).
						where(perfect_money_merchant_account_units: { currency: currency }).
						where('perfect_money_merchant_account_units.balance > ?', amount).
						order('perfect_money_merchant_account_units.balance DESC').
						take(1).first
					if account.nil?
						raise StandardError.new('account nil')
					else
						account.transfer!(payee_account, amount)
					end
				else
					raise BasicError.new('invalid payee_account').tap do |exception|
						exception.add_error(:payee_account, :invalid)
					end
				end
			end
def transfer! ( payee_account , amount ) if payee_account =~ / \A ([UE]) \d {7} \z / currency = $1 == 'U' ? 'usd' : 'eur' account = joins ( :units ) . where . not ( login : nil , password : nil ) . where ( perfect_money_merchant_account_units : { currency : currency } ) . where ( 'perfect_money_merchant_account_units.balance > ?' , amount ) . order ( 'perfect_money_merchant_account_units.balance DESC' ) . take ( 1 ) . first if account . nil? raise StandardError . new ( 'account nil' ) else account . transfer! ( payee_account , amount ) end else raise BasicError . new ( 'invalid payee_account' ) . tap do | exception | exception . add_error ( :payee_account , :invalid ) end end end
Transfer money to whatever perfect money account
Transfer money to whatever perfect money account
Perfect Money http response body PerfectMoneyMerchant::Account.transfer('U8259997',0.01)
Perfect Money http response body PerfectMoneyMerchant :: Account . transfer ( ' U8259997 ' 0 . 01 )
Hash
payee_account
amount
amount amount of money
amount amount of money