bankserv 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,8 +110,13 @@ class Bankserv::InputDocument < Bankserv::Document
110
110
  hash = {rec_status: document.rec_status}
111
111
  hash.merge!(internal: bankserv_service.config[:internal]) if bankserv_service.config.has_key?(:internal)
112
112
 
113
- document.set.sets << set.generate(hash)
114
- document.set.sets[-1].set = document.set # whaaaaaa?
113
+ generated_sets = set.generate(hash)
114
+ generated_sets = [generated_sets] unless generated_sets.is_a? Array
115
+
116
+ generated_sets.each do |set|
117
+ document.set.sets << set
118
+ document.set.sets[-1].set = document.set # whaaaaaa?
119
+ end
115
120
  end
116
121
 
117
122
  document.save!
@@ -46,7 +46,28 @@ module Bankserv
46
46
  def self.bankserv_service
47
47
  Bankserv::CreditService.where(active: true).last
48
48
  end
49
-
49
+
50
+ def self.generate(options = {})
51
+ efts = self.unprocessed_efts(options[:rec_status])
52
+
53
+ if efts.count > 0
54
+ sets = efts.group_by(&:batch_id).map do |batch_id, efts|
55
+ set = self.new
56
+ set.type_of_service = efts.first.request.data[:type_of_service]
57
+ set.accepted_report = efts.first.request.data[:accepted_report] || "Y"
58
+ set.account_type_correct = efts.first.request.data[:account_type_correct] || "Y"
59
+ set.build_header
60
+ set.build_batches(efts)
61
+ set.build_trailer
62
+ set
63
+ end
64
+ end
65
+ end
66
+
67
+ def build_batches(efts)
68
+ efts.select(&:standard?).each{|t| build_standard t}
69
+ efts.select(&:contra?).each{|t| build_contra t}
70
+ end
50
71
  end
51
72
  end
52
73
  end
@@ -43,13 +43,23 @@ module Bankserv
43
43
  Bankserv::Transmission::UserSet::Debit.bankserv_service
44
44
  #Bankserv::Service.where(active: true, type: 'debit').last
45
45
  end
46
-
47
46
 
48
47
  def self.bankserv_service
49
48
  Bankserv::DebitService.where(active: true).last
50
49
  #Bankserv::Service.where(active: true, type: 'debit').last
51
50
  end
52
51
 
52
+ def build_batches(efts)
53
+ build_header
54
+
55
+ efts.group_by(&:batch_id).each do |batch_id, eft|
56
+ eft.select(&:standard?).each{|t| build_standard t}
57
+ eft.select(&:contra?).each{|t| build_contra t}
58
+ end
59
+
60
+ build_trailer
61
+ end
62
+
53
63
  end
54
64
  end
55
65
  end
@@ -31,9 +31,7 @@ module Bankserv
31
31
  set.type_of_service = efts.first.request.data[:type_of_service]
32
32
  set.accepted_report = efts.first.request.data[:accepted_report] || "Y"
33
33
  set.account_type_correct = efts.first.request.data[:account_type_correct] || "Y"
34
- set.build_header
35
- set.build_batches(options[:rec_status])
36
- set.build_trailer
34
+ set.build_batches(efts)
37
35
  set
38
36
  end
39
37
  end
@@ -85,15 +83,6 @@ module Bankserv
85
83
  records.build(record_type: "trailer", data: record_data.merge(rec_id: rec_id))
86
84
  end
87
85
 
88
- def build_batches(rec_status)
89
- efts = self.class.unprocessed_efts(rec_status)
90
-
91
- efts.group_by(&:batch_id).each do |batch_id, eft|
92
- eft.select(&:standard?).each{|t| build_standard t}
93
- eft.select(&:contra?).each{|t| build_contra t}
94
- end
95
- end
96
-
97
86
  def build_standard(transaction)
98
87
  record_data = Absa::H2h::Transmission::Eft.record_type('standard_record').template_options
99
88
  homing_account_number = transaction.bank_account.account_number.to_i.to_s
@@ -1,3 +1,3 @@
1
1
  module Bankserv
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Bankserv::Debit do
3
+ describe Bankserv::Credit do
4
4
 
5
5
  context "queuing a batch of credit orders" do
6
6
 
@@ -35,16 +35,17 @@ describe Bankserv::Transmission::UserSet::Credit do
35
35
  }
36
36
 
37
37
  bankserv_service.request(@hash)
38
- @batch = Bankserv::Transmission::UserSet::Credit.generate(rec_status: "T")
39
- @batch.save
38
+ @batches = Bankserv::Transmission::UserSet::Credit.generate(rec_status: "T")
39
+ @batches.each {|x| x.save!}
40
40
  end
41
41
 
42
- it "should return true when a batch needs to be processed" do
42
+ it "should return true when a set needs to be processed" do
43
43
  Bankserv::Transmission::UserSet::Credit.has_test_work?.should be_true
44
44
  end
45
45
 
46
- it "should create a batch with a header when the job begins" do
47
- @batch.header.data.should == {
46
+ it "should create 2 sets with a header when the job begins" do
47
+
48
+ @batches.first.header.data.should == {
48
49
  rec_id: "020",
49
50
  rec_status: "T",
50
51
  bankserv_record_identifier: "04",
@@ -59,28 +60,64 @@ describe Bankserv::Transmission::UserSet::Credit do
59
60
  accepted_report: "Y",
60
61
  account_type_correct: "Y"
61
62
  }
63
+
64
+ @batches.second.header.data.should == {
65
+ rec_id: "020",
66
+ rec_status: "T",
67
+ bankserv_record_identifier: "04",
68
+ bankserv_user_code: "9534",
69
+ bankserv_creation_date: Time.now.strftime("%y%m%d"),
70
+ bankserv_purge_date: Time.now.strftime("%y%m%d"),
71
+ first_action_date: Time.now.strftime("%y%m%d"),
72
+ last_action_date: Time.now.strftime("%y%m%d"),
73
+ first_sequence_number: "5",
74
+ user_generation_number: "38",
75
+ type_of_service: "SAMEDAY",
76
+ accepted_report: "Y",
77
+ account_type_correct: "Y"
78
+ }
79
+
62
80
  end
63
81
 
64
- it "should create a 2 batches of debit transactions when the job begins" do
65
- @batch.contra_records.size.should == 2
82
+ it "should create a contra record for each set" do
83
+ @batches.each do |batch|
84
+ batch.contra_records.size.should == 1
85
+ end
66
86
  end
67
87
 
68
88
  it "should create a batch with a trailer when the job begins" do
69
- @batch.trailer.data.should == {
89
+ @batches.first.trailer.data.should == {
70
90
  rec_id: "020",
71
91
  rec_status: "T",
72
92
  bankserv_record_identifier: "92",
73
93
  bankserv_user_code: "9534",
74
94
  first_sequence_number: "1",
95
+ last_sequence_number: "4",
96
+ first_action_date: Time.now.strftime("%y%m%d"),
97
+ last_action_date: Time.now.strftime("%y%m%d"),
98
+ no_debit_records: "1",
99
+ no_credit_records: "3",
100
+ no_contra_records: "1",
101
+ total_debit_value: "1000000",
102
+ total_credit_value: "1000000",
103
+ hash_total_of_homing_account_numbers: "138655402067"
104
+ }
105
+
106
+ @batches.second.trailer.data.should == {
107
+ rec_id: "020",
108
+ rec_status: "T",
109
+ bankserv_record_identifier: "92",
110
+ bankserv_user_code: "9534",
111
+ first_sequence_number: "5",
75
112
  last_sequence_number: "8",
76
113
  first_action_date: Time.now.strftime("%y%m%d"),
77
114
  last_action_date: Time.now.strftime("%y%m%d"),
78
- no_debit_records: "2",
79
- no_credit_records: "6",
80
- no_contra_records: "2",
81
- total_debit_value: "2500000",
82
- total_credit_value: "2500000",
83
- hash_total_of_homing_account_numbers: "277310804125"
115
+ no_debit_records: "1",
116
+ no_credit_records: "3",
117
+ no_contra_records: "1",
118
+ total_debit_value: "1500000",
119
+ total_credit_value: "1500000",
120
+ hash_total_of_homing_account_numbers: "138655402058"
84
121
  }
85
122
  end
86
123
 
@@ -88,5 +125,48 @@ describe Bankserv::Transmission::UserSet::Credit do
88
125
  Bankserv::DebitService.active.last.config[:generation_number].should == Bankserv::CreditService.active.last.config[:generation_number]
89
126
  end
90
127
  end
128
+
129
+ context "Building credit transmission with multiple sets" do
130
+
131
+ before(:each) do
132
+ tear_it_down
133
+
134
+ @credit_service = Bankserv::CreditService.register(client_code: '10', client_name: "LDC USER 10 AFRICA (PTY)", client_abbreviated_name: 'ALIMITTST', user_code: "9534", generation_number: 37, transmission_status: "T", transmission_number: "1")
135
+ debit_service = Bankserv::DebitService.register(client_code: '12346', client_name: "TESTTEST", client_abbreviated_name: 'TESTTEST', user_code: "9999", generation_number: 37, transmission_status: "L", transmission_number: "1")
136
+
137
+ @data = [{
138
+ debit: {
139
+ account_number: "907654321", branch_code: "632005", account_type: 'savings', id_number: '8207205263083', initials: "RC", account_name: "Rawson Milnerton", amount: 500000, user_ref: 234, action_date: Date.today },
140
+ credit:
141
+ { account_number: "13123123123", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "235"}
142
+ }]
143
+
144
+ @data2 = [{
145
+ debit: {
146
+ account_number: "907654321", branch_code: "632005", account_type: 'savings', id_number: '8207205263083', initials: "RC", account_name: "Rawson Milnerton", amount: 500000, user_ref: 234, action_date: Date.today },
147
+ credit:
148
+ { account_number: "13123123123", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "235"}
149
+ }]
150
+
151
+ @hash = {
152
+ type: 'credit',
153
+ data: { type_of_service: "BATCH", batches: @data }
154
+ }
155
+
156
+ @hash2 = {
157
+ type: 'credit',
158
+ data: { type_of_service: "BATCH", batches: @data2 }
159
+ }
160
+
161
+ @credit_service.request(@hash)
162
+ @credit_service.request(@hash2)
163
+ end
164
+
165
+ it "should build a transmission with 3 sets" do
166
+ document = Bankserv::InputDocument.generate!(@credit_service)
167
+ document.sets.size.should == 3
168
+ end
169
+
170
+ end
91
171
 
92
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankserv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-07 00:00:00.000000000Z
13
+ date: 2012-08-08 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70297965684020 !ruby/object:Gem::Requirement
17
+ requirement: &70160002412140 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70297965684020
25
+ version_requirements: *70160002412140
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activerecord
28
- requirement: &70297965673820 !ruby/object:Gem::Requirement
28
+ requirement: &70160002411500 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70297965673820
36
+ version_requirements: *70160002411500
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &70297965673280 !ruby/object:Gem::Requirement
39
+ requirement: &70160002411000 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70297965673280
47
+ version_requirements: *70160002411000
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: absa-h2h
50
- requirement: &70297965672640 !ruby/object:Gem::Requirement
50
+ requirement: &70160002410280 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 0.1.6
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70297965672640
58
+ version_requirements: *70160002410280
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: absa-esd
61
- requirement: &70297965672020 !ruby/object:Gem::Requirement
61
+ requirement: &70160002409740 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.0.3
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70297965672020
69
+ version_requirements: *70160002409740
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: absa-notify-me
72
- requirement: &70297965671460 !ruby/object:Gem::Requirement
72
+ requirement: &70160002409240 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 0.0.7
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *70297965671460
80
+ version_requirements: *70160002409240
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: combustion
83
- requirement: &70297965670880 !ruby/object:Gem::Requirement
83
+ requirement: &70160002408640 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: 0.3.1
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70297965670880
91
+ version_requirements: *70160002408640
92
92
  description: ! "This engine allows users to inject requests into a queue to be processed.
93
93
  \n \n The queue handles bank account validations, credit payments,
94
94
  debit orders\n and collecting bank statements/notify me statements. "