Class: Dscf::Banking::TransferService

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

Instance Attribute Summary collapse

Attributes inherited from BaseTransactionService

#errors

Instance Method Summary collapse

Methods inherited from BaseTransactionService

#failure?, #success?

Constructor Details

#initialize(debit_account:, credit_account:, amount:, description:, transaction_type_code: "TRANSFER") ⇒ TransferService

Returns a new instance of TransferService.



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

def initialize(debit_account:, credit_account:, amount:, description:, transaction_type_code: "TRANSFER")
  super()
  @debit_account = 
  @credit_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/transfer_service.rb', line 3

def transaction
  @transaction
end

Instance Method Details

#executeObject



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

def execute
  return self unless validate_transfer

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

    process_transaction(@transaction)
    return self unless success?
  end

  self
end