Class: Dscf::Payment::BankingIntegrationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/dscf/payment/banking_integration_service.rb

Instance Method Summary collapse

Instance Method Details

#transfer(from_account, to_account, amount, description, transaction_type_code: "TRANSFER") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/dscf/payment/banking_integration_service.rb', line 3

def transfer(, , amount, description, transaction_type_code: "TRANSFER")
  validate_transfer_params(, , amount)

  transfer_service = Dscf::Banking::TransferService.new(
    debit_account: ,
    credit_account: ,
    amount: amount,
    description: description,
    transaction_type_code: transaction_type_code
  )

  result = transfer_service.execute

  unless result.success?
    raise BankingTransactionError.new("Banking transfer failed: #{result.errors.join(", ")}")
  end

  result.transaction
rescue AccountNotActiveError, InvalidAmountError, InsufficientFundsError, BankingTransactionError
  raise
rescue => e
  raise BankingTransactionError.new("Banking transfer error: #{e.message}")
end