Class: Dscf::Banking::WithdrawalService

Inherits:
BaseTransactionService show all
Defined in:
app/services/dscf/banking/withdrawal_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseTransactionService

#errors

Instance Method Summary collapse

Methods inherited from BaseTransactionService

#failure?, #success?

Constructor Details

#initialize(account:, amount:, description:, transaction_type_code: "WITHDRAWAL") ⇒ WithdrawalService

Returns a new instance of WithdrawalService.



5
6
7
8
9
10
11
12
# File 'app/services/dscf/banking/withdrawal_service.rb', line 5

def initialize(account:, amount:, description:, transaction_type_code: "WITHDRAWAL")
  super()
  @account = 
  @amount = amount.to_f
  @description = description
  @transaction_type_code = transaction_type_code
  @transaction = nil
end

Instance Attribute Details

#transactionObject (readonly)

Returns the value of attribute transaction.



3
4
5
# File 'app/services/dscf/banking/withdrawal_service.rb', line 3

def transaction
  @transaction
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/dscf/banking/withdrawal_service.rb', line 14

def execute
  return self unless validate_withdrawal

  ActiveRecord::Base.transaction do
    create_withdrawal_transaction
    return self unless success?

    process_withdrawal
    return self unless success?
  end

  self
end