bankserv 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,21 +63,20 @@ module Bankserv
63
63
  end
64
64
 
65
65
  def self.eft_sequence_number
66
- self.active.eft_sequence_number or 1
66
+ sequence_number = self.active.eft_sequence_number || 1
67
+ sequence_number = 1 unless self.active.eft_sequence_number_updated_at.to_date == Date.today
68
+ sequence_number
67
69
  end
68
70
 
69
71
  def self.set_eft_sequence_number!(number)
70
72
  self.active.update_attributes!(eft_sequence_number: number, eft_sequence_number_updated_at: Time.now)
71
73
  end
72
74
 
73
- def self.reserve_eft_sequence_number!(reserved=nil)
75
+ def self.reserve_eft_sequence_number!(reserved = nil)
74
76
  reserved ||= self.eft_sequence_number
75
- reserved ||= 1
76
- reserved = 1 if self.active.eft_sequence_number_updated_at < Date.today.beginning_of_day
77
77
  self.set_eft_sequence_number!(reserved.to_i + 1)
78
78
  reserved
79
79
  end
80
-
81
80
 
82
81
  end
83
82
 
@@ -47,24 +47,6 @@ module Bankserv
47
47
  date.strftime("%y%m%d")
48
48
  end
49
49
 
50
- def self.last_sequence_number_today
51
- if last = Record.where("date(created_at) = ? AND record_type = 'standard_record'", Date.today).last
52
- document = last.set.get_document
53
- raise "Cannot determine sequence number" if ((document) && (document.reply_status != 'ACCEPTED'))
54
- end
55
-
56
- last.nil? ? 0 : last.data[:user_sequence_number].to_i
57
- end
58
-
59
- def self.user_sequence_number(transactions)
60
- # (Bankserv::Configuration.eft_sequence_number + transactions.count).to_s
61
- (Bankserv::Transmission::UserSet::Eft.last_sequence_number_today + transactions.count + 1).to_s
62
- end
63
-
64
- def user_sequence_number
65
- Bankserv::Transmission::UserSet::Eft.user_sequence_number(transactions)
66
- end
67
-
68
50
  def contra_records
69
51
  records.where(record_type: "contra_record")
70
52
  end
@@ -77,10 +59,6 @@ module Bankserv
77
59
  Bankserv::Configuration.reserve_user_generation_number!.to_s #Equal to the last accepted user gen number + 1
78
60
  end
79
61
 
80
- def reserve_eft_sequence_number(number=nil)
81
- Bankserv::Configuration.reserve_eft_sequence_number!(number).to_s
82
- end
83
-
84
62
  def build_header(options = {})
85
63
  self.generation_number = options[:user_generation_number] || get_user_generation_number
86
64
  record_data = Absa::H2h::Transmission::Eft.record_type('header').template_options
@@ -94,6 +72,8 @@ module Bankserv
94
72
  account_type_correct: @account_type_correct
95
73
  )
96
74
 
75
+ record_data.merge!(first_sequence_number: options[:first_sequence_number]) if options[:first_sequence_number]
76
+
97
77
  records.build(record_type: "header", data: record_data)
98
78
  end
99
79
 
@@ -118,7 +98,6 @@ module Bankserv
118
98
 
119
99
  record_data.merge!(
120
100
  rec_id: rec_id,
121
- user_sequence_number: user_sequence_number,
122
101
  user_nominated_account: transaction.contra_bank_details.account_number,
123
102
  user_branch: transaction.contra_bank_details.branch_code,
124
103
  user_code: Bankserv::Configuration.active.user_code,
@@ -143,7 +122,6 @@ module Bankserv
143
122
 
144
123
  record_data.merge!(
145
124
  rec_id: rec_id,
146
- user_sequence_number: user_sequence_number,
147
125
  bankserv_record_identifier: contra_bankserv_record_identifier,
148
126
  user_branch: transaction.bank_account.branch_code,
149
127
  user_nominated_account: transaction.bank_account.account_number.to_i.to_s,
@@ -214,7 +192,8 @@ module Bankserv
214
192
  private
215
193
 
216
194
  def set_sequence_numbers
217
- sequence_number = (header.data[:first_sequence_number] || reserve_eft_sequence_number).to_i
195
+ sequence_number = (header.data[:first_sequence_number] || Bankserv::Configuration.reserve_eft_sequence_number!).to_i
196
+
218
197
  header.data[:first_sequence_number] = sequence_number.to_s
219
198
  trailer.data[:first_sequence_number] = sequence_number.to_s
220
199
 
@@ -224,6 +203,7 @@ module Bankserv
224
203
  end
225
204
 
226
205
  trailer.data[:last_sequence_number] = (sequence_number - 1).to_s
206
+ Bankserv::Configuration.reserve_eft_sequence_number!(sequence_number - 1)
227
207
  end
228
208
 
229
209
  def decorate_header
@@ -1,3 +1,3 @@
1
1
  module Bankserv
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -2,7 +2,7 @@
2
2
  001T0495340405240405310405240405270000010037CORPSSV
3
3
  001T5063200504053538939953400000163200501019611899100000001000040524440000ALIMITTST SPP 1040524 01 HENNIE DU TOIT 00000000000000000000 21
4
4
  001T929534000001000016040524040527000014000002000002000020308000000020308000036311034141
5
- 001T0495340405240405310405240405270000010038CORPSSV
5
+ 001T0495340405240405310405240405270000020038CORPSSV
6
6
  001T5063200504053538939953400000263200501019611899100000001000040524440000ALIMITTST SPP 1040524 01 HENNIE DU TOIT 00000000000000000000 21
7
7
  001T929534000001000016040524040527000014000002000002000020308000000020308000036311034141
8
8
  999T000000020
@@ -172,13 +172,12 @@ describe Bankserv::InputDocument do
172
172
 
173
173
  t = Time.local(2008, 8, 8, 10, 5, 0)
174
174
  Timecop.travel(t)
175
- create(:configuration, client_code: "986", client_name: "TESTTEST", user_code: "9999", user_generation_number: 846, client_abbreviated_name: "TESTTEST", eft_sequence_number: 78, eft_sequence_number_updated_at: Time.now)
176
175
 
176
+ create(:configuration, client_code: "986", client_name: "TESTTEST", user_code: "9999", user_generation_number: 846, client_abbreviated_name: "TESTTEST", eft_sequence_number: 78, eft_sequence_number_updated_at: Time.now)
177
177
  create_credit_request
178
178
  end
179
179
 
180
180
  it "should build a new document with a credit set" do
181
- Bankserv::Transmission::UserSet::Eft.stub!(:last_sequence_number_today).and_return(77)
182
181
  Bankserv::Configuration.stub!(:live_env?).and_return(true)
183
182
  Bankserv::InputDocument.stub!(:fetch_next_transmission_number).and_return("846")
184
183
 
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.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-04-09 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70292450761780 !ruby/object:Gem::Requirement
17
+ requirement: &70340533489260 !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: *70292450761780
25
+ version_requirements: *70340533489260
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activerecord
28
- requirement: &70292450761280 !ruby/object:Gem::Requirement
28
+ requirement: &70340533488720 !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: *70292450761280
36
+ version_requirements: *70340533488720
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &70292450760860 !ruby/object:Gem::Requirement
39
+ requirement: &70340533488260 !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: *70292450760860
47
+ version_requirements: *70340533488260
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: absa-h2h
50
- requirement: &70292450760280 !ruby/object:Gem::Requirement
50
+ requirement: &70340533487680 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 0.0.13
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70292450760280
58
+ version_requirements: *70340533487680
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: absa-esd
61
- requirement: &70292450759780 !ruby/object:Gem::Requirement
61
+ requirement: &70340533487160 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.0.2
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70292450759780
69
+ version_requirements: *70340533487160
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: combustion
72
- requirement: &70292450759320 !ruby/object:Gem::Requirement
72
+ requirement: &70340533486680 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: 0.3.1
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70292450759320
80
+ version_requirements: *70340533486680
81
81
  description: ! "This engine allows users to inject requests into a queue to be processed.
82
82
  \n \n The queue handles bank account validations, credit payments,
83
83
  debit orders\n and collecting bank statements. "