Class: BankAccount

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/bank_account.rb

Overview

Table Definition ###############################

create_table :bank_accounts do |t|
  t.string :routing_number
  t.string :crypted_private_account_number
  t.string :name_on_account
  t.references :bank_account_type

  t.timestamps
end

add_index :bank_accounts, :bank_account_type_id, :name => 'bank_accounts_account_type_idx'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mask_number(number) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/bank_account.rb', line 84

def mask_number(number)
  total_chars = number.length
  total_chars -= 4
  result = ''
  result.tap do |str|
    total_chars.times do
      str << 'X'
    end
  end
  result + number[number.length-4..number.length]
end

Instance Method Details

#account_numberObject

These methods are exposed for the purposes of displaying a version of the account number string containing the last four digits of the account number. The idea is to make it painfully obvious when any coder is using the private_account_number, which should be used only in limited circumstances.



38
39
40
41
42
43
44
# File 'app/models/bank_account.rb', line 38

def 
  if self.
    BankAccount.mask_number(self.)
  else
    ''
  end
end

#account_number=(num) ⇒ Object

Note that the setter method allows the same variable to be set, and delegates through the encryption process



49
50
51
# File 'app/models/bank_account.rb', line 49

def (num)
  self.=num
end

#financial_txnsObject



53
54
55
# File 'app/models/bank_account.rb', line 53

def financial_txns
  self.biz_txn_events.where('biz_txn_record_type = ?', 'FinancialTxn').collect(&:biz_txn_record)
end

#purchase(financial_txn, gateway_wrapper, gateway_options = {}, gateway_account_number = nil, gateway_routing_number = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/bank_account.rb', line 65

def purchase(financial_txn, gateway_wrapper, gateway_options={}, =nil, gateway_routing_number=nil)
   = self. unless 
  gateway_routing_number = self.routing_number unless gateway_routing_number

  #call some service to pay via bank accounts
  result = gateway_wrapper.purchase(, gateway_routing_number, financial_txn.money.amount)

  unless result[:payment].nil?
    result[:payment].financial_txn = financial_txn
    result[:payment].save
    financial_txn.payments << result[:payment]
    financial_txn.save
  end

  result
end

#refundObject



98
99
100
# File 'app/models/bank_account.rb', line 98

def refund
  # implement a refund on an account
end

#successful_paymentsObject



57
58
59
60
61
62
63
# File 'app/models/bank_account.rb', line 57

def successful_payments
  payments = []
  self.financial_txns.each do |financial_txn|
    payments << financial_txn.payments.last if financial_txn.has_captured_payment?
  end
  payments
end