Module: Bankserv::Eft

Included in:
Credit, Debit
Defined in:
lib/bankserv/eft.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#request_idObject

This module is tightly coupled to the Debit and Credit class. Any change here will ripple down…



5
6
7
# File 'lib/bankserv/eft.rb', line 5

def request_id
  @request_id
end

Class Method Details

.for_reference(reference) ⇒ Object



84
85
86
# File 'lib/bankserv/eft.rb', line 84

def self.for_reference(reference)
  Debit.for_reference(reference) + Credit.for_reference(reference)
end

Instance Method Details

#build!(options) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/bankserv/eft.rb', line 7

def build!(options)
  @request_id = options[:bankserv_request_id]
  
  options[:batches].each do |batch|
    build_batch! batch
  end
end

#build_batch!(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/bankserv/eft.rb', line 15

def build_batch!(options)
  batch_id = next_batch_id
  if self.partial_class_name == "Debit"
    build_standard!(batch_id, options[:debit])
    build_contra!(batch_id, options[:credit])
  else
    build_standard!(batch_id, options[:credit])
    build_contra!(batch_id, options[:debit])
  end
end

#build_contra!(batch_id, options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bankserv/eft.rb', line 30

def build_contra!(batch_id, options)
   = options.delete(:account_name)
   = options.delete(:account_type)
   = options.delete(:account_number)
  branch_code = options.delete(:branch_code)
  initials = options.delete(:initials)
  id_number = options.delete(:id_number)
  
   = BankAccount.create!(account_name: , account_type: , account_number: , 
                                 branch_code: branch_code, initials: initials)
                                 
  options = options.merge(record_type: "contra", batch_id: batch_id, bankserv_request_id: @request_id, bankserv_bank_account_id: .id)
  contra = new(options)
  contra.save!
end

#build_standard!(batch_id, options) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/bankserv/eft.rb', line 46

def build_standard!(batch_id, options)
  if options.is_a? Array
    options.each do |debit|
      create_standard!(batch_id, debit)
    end
  else
    create_standard!(batch_id, options)
  end
end

#create_standard!(batch_id, options) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bankserv/eft.rb', line 56

def create_standard!(batch_id, options)
   = options.delete(:account_name)
   = options.delete(:account_type)
   = options.delete(:account_number)
  branch_code = options.delete(:branch_code)
  initials = options.delete(:initials)
  id_number = options.delete(:id_number)
  
   = BankAccount.create!(account_name: , account_type: , account_number: , 
                                 branch_code: branch_code, initials: initials)
                                 
  options = options.merge(record_type: "standard", batch_id: batch_id, bankserv_request_id: @request_id, bankserv_bank_account_id: .id)
  standard = new(options)
  standard.save!
end

#has_test_work?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/bankserv/eft.rb', line 80

def has_test_work?
  unprocessed.select{|item| item.request.test?}.any?
end

#has_work?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/bankserv/eft.rb', line 76

def has_work?
  unprocessed.select{|item| not item.request.test?}.any?
end

#next_batch_idObject



72
73
74
# File 'lib/bankserv/eft.rb', line 72

def next_batch_id
  maximum('batch_id').nil? ? 1 : maximum('batch_id') + 1
end

#partial_class_nameObject



26
27
28
# File 'lib/bankserv/eft.rb', line 26

def partial_class_name
  self.name.split("::")[-1]
end