payment_dta 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module DTA
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'payment_dta/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "payment_dta"
8
+ spec.version = DTA::VERSION
9
+ spec.require_paths = ["lib"]
10
+ spec.authors = ["Patrick Huesler"]
11
+ spec.description = "Generate Swiss DTA payment files to extract payments from your existing application"
12
+ spec.summary = "Ruby library to generate Swiss DTA payment files"
13
+ spec.email = "patrick.huesler@gmail.com"
14
+ spec.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ spec.license = "MIT"
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.homepage = "http://github.com/phuesler/payment_dta"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.2"
23
+ spec.add_development_dependency "rubigen"
24
+ spec.add_development_dependency "rdoc"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "rake"
28
+ end
29
+
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'payment_dta/payments/esr_payment'
2
3
  require 'payment_dta/payments/total_record'
3
4
  class Factory
@@ -75,8 +76,8 @@ class Factory
75
76
  :payment_amount_currency => 'CHF',
76
77
  :issuer_identification => 'ABC01',
77
78
  :transaction_number => rand(100000000000).to_s,
78
- :output_sequence_number => 1,
79
+ :output_sequence_number => 0,
79
80
  :payment_amount_value_date => Date.today.strftime('%y%m%d')
80
81
  }.merge(attributes)
81
82
  end
82
- end
83
+ end
@@ -32,7 +32,7 @@ describe BankChequePayment do
32
32
  end
33
33
 
34
34
  it 'should have a payment amount justified left filled with blanks' do
35
- Factory.create_bank_cheque_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949.75'.ljust(15)
35
+ Factory.create_bank_cheque_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949,75'.ljust(15)
36
36
  end
37
37
 
38
38
  it 'should have a reserve field' do
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
3
  require 'character_conversion'
3
4
 
@@ -237,7 +238,7 @@ def create_character_from_ut8_decimal_code(code)
237
238
  if code < 128
238
239
  code.chr
239
240
  else
240
- [code.to_s[0,3].to_i,code.to_s[3,3].to_i].pack("C*")
241
+ [code.to_s[0,3].to_i,code.to_s[3,3].to_i].pack("C*").force_encoding('utf-8')
241
242
  end
242
243
  end
243
244
  describe "dta character conversion and encoding" do
@@ -249,7 +250,7 @@ describe "dta character conversion and encoding" do
249
250
  end
250
251
 
251
252
  it "should encode the strings" do
252
- Converter.should_receive(:encode_characters).with("AEoeue").and_return(Iconv.conv("ISO-8859-1", "UTF8","Äöü"))
253
+ Converter.should_receive(:encode_characters).with("AEoeue").and_return("Äöü".encode('iso-8859-1'))
253
254
  Converter.dta_string("Äöü")
254
255
  end
255
256
 
@@ -267,14 +268,9 @@ describe "dta character conversion and encoding" do
267
268
  end
268
269
 
269
270
  describe 'DTA character encoding' do
270
-
271
- it "should have a default system encoding of utf8" do
272
- $KCODE.should == 'UTF8'
273
- end
274
-
275
271
  it "should convert the encoding from UTF8 to ISO Latincode 8859-1" do
276
272
  encoded_string = Converter.encode_characters("Ä")
277
- encoded_string.size.should == 1
273
+ encoded_string.bytes.to_a.size.should == 1
278
274
  end
279
275
  end
280
- end
276
+ end
@@ -33,7 +33,12 @@ describe DomesticCHFPayment do
33
33
  end
34
34
 
35
35
  it 'should have a payment amount justified left filled with blanks' do
36
- Factory.create_domestic_chf_payment(:payment_amount => '3949.75').segment1[102,12].should == '3949.75 '
36
+ Factory.create_domestic_chf_payment(:payment_amount => '3949,75').segment1[102,12].should == '3949,75 '
37
+ end
38
+
39
+ it 'should use the swift convention to format the amount' do
40
+ Factory.create_domestic_chf_payment(:payment_amount => '110.45').segment1[102,12].should == '110,45 '
41
+ Factory.create_domestic_chf_payment(:payment_amount => 237.05).segment1[102,12].should == '237,05 '
37
42
  end
38
43
 
39
44
  it 'should have a reserve field' do
@@ -25,8 +25,8 @@ describe DTAFile do
25
25
  file << Factory.create_esr_payment
26
26
  file << Factory.create_esr_payment
27
27
 
28
- file.records.to_a.first.output_sequence_number.should == "00001"
29
- file.records.to_a[1].output_sequence_number.should == "00002"
28
+ file.records.to_a.first.entry_sequence_number.should == "00001"
29
+ file.records.to_a[1].entry_sequence_number.should == "00002"
30
30
  end
31
31
 
32
32
  it "should calculate the total amount" do
@@ -36,6 +36,12 @@ describe DTAFile do
36
36
  file.total.should == (420.50 + 320.20)
37
37
  end
38
38
 
39
+ it 'should correctly sum up floats' do
40
+ file = DTAFile.new nil
41
+ 3.times { file << Factory.create_esr_payment(:payment_amount => 0.1) }
42
+ file.total.should eq 0.3
43
+ end
44
+
39
45
  describe DTAFile, "file records" do
40
46
  before(:each) do
41
47
  @record1 = Factory.create_esr_payment(:payment_amount => 2222.22)
@@ -53,7 +59,14 @@ describe DTAFile do
53
59
  end
54
60
 
55
61
  it "should add a total record" do
56
- @file_records.last.should include(Factory.create_total_record(:total_amount => 6666.66).to_dta)
62
+ @file_records.last.should include(Factory.create_total_record(
63
+ :entry_sequence_number => 3, :total_amount => 6666.66).to_dta)
64
+ end
65
+
66
+ describe '#dta_string' do
67
+ it 'equals file contents' do
68
+ @dta_file.dta_string.size.should == IO.read(@path).size
69
+ end
57
70
  end
58
71
  end
59
72
 
@@ -32,7 +32,7 @@ describe 'ESRPayment' do
32
32
  end
33
33
 
34
34
  it 'should have a payment amount justified left filled with blanks' do
35
- Factory.create_esr_payment(:payment_amount => '3949.75').segment1[102,12].should == '3949.75 '
35
+ Factory.create_esr_payment(:payment_amount => '3949.75').segment1[102,12].should == '3949,75 '
36
36
  end
37
37
 
38
38
  it 'should have a reserve field' do
@@ -154,4 +154,4 @@ describe 'ESRPayment' do
154
154
  (@record1 < @record2).should be_true
155
155
  end
156
156
  end
157
- end
157
+ end
@@ -33,7 +33,7 @@ describe FinancialInstitutionPayment do
33
33
  end
34
34
 
35
35
  it 'should have a payment amount justified left filled with blanks' do
36
- Factory.create_financial_institution_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949.75'.ljust(15)
36
+ Factory.create_financial_institution_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949,75'.ljust(15)
37
37
  end
38
38
 
39
39
  it 'should have a reserve field' do
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
3
  require 'payments/iban_payment'
3
4
 
@@ -32,7 +33,7 @@ describe IBANPayment do
32
33
  end
33
34
 
34
35
  it 'should have a payment amount justified left filled with blanks' do
35
- Factory.create_iban_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949.75'.ljust(15)
36
+ Factory.create_iban_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949,75'.ljust(15)
36
37
  end
37
38
 
38
39
  it 'should have a reserve field' do
@@ -64,6 +65,11 @@ describe IBANPayment do
64
65
  Factory.create_iban_payment(:ordering_partys_address_line3 => '8000 Zurich').segment2[84,35].should == '8000 Zurich'.ljust(35)
65
66
  end
66
67
 
68
+ it 'should have the correct length when containing umlauts' do
69
+ Factory.create_iban_payment(:ordering_partys_address_line3 => '8000 Zürich').
70
+ segment2[84,35].should == '8000 Zuerich'.ljust(35)
71
+ end
72
+
67
73
  it 'should have a reserve field' do
68
74
  Factory.create_iban_payment.segment2[114,9].should == ' '.ljust(9)
69
75
  end
@@ -124,6 +130,12 @@ describe IBANPayment do
124
130
  Factory.create_iban_payment(:beneficiary_address_line1 => 'Michael Recipient').segment4[2,35].should == 'Michael Recipient'.ljust(35)
125
131
  end
126
132
 
133
+ it 'should truncate input longer than 35 characters' do
134
+ name = 'Joannes Chrysostomus Wolfgangus Theophilus Mozart'
135
+ Factory.create_iban_payment(:beneficiary_address_line1 => name).
136
+ beneficiary_address_line1(35).should == name[0, 35]
137
+ end
138
+
127
139
  it 'should have a beneficiary address line 2' do
128
140
  Factory.create_iban_payment(:beneficiary_address_line2 => 'Empfaengerstrasse 1').segment4[37,35].should == 'Empfaengerstrasse 1'.ljust(35)
129
141
  end
@@ -7,25 +7,25 @@ shared_examples_for "all headers" do
7
7
  it 'should have a total length of 51 characters' do
8
8
  Factory.create_payment(@type).header.size.should == 51
9
9
  end
10
-
10
+
11
11
  it 'should fill out a blank output sequence number' do
12
12
  Factory.create_payment(@type).header[18,5].should == '00000'
13
13
  end
14
-
14
+
15
15
  it 'should set the creation date' do
16
16
  Factory.create_payment(@type).header[23,6].should == Date.today.strftime('%y%m%d')
17
17
  end
18
-
18
+
19
19
  it 'should set the data file sender identification' do
20
20
  Factory.create_payment(@type,:data_file_sender_identification => 'ABC12').header[36,5].should == 'ABC12'
21
21
  end
22
-
22
+
23
23
  it 'should should set the entry sequence number' do
24
24
  Factory.create_payment(@type,:entry_sequence_number => 1).header[41,5].should == '00001'
25
25
  end
26
-
26
+
27
27
  it 'should set the processing flag to 0' do
28
- Factory.create_payment(@type).header[50,1].should == '0'
28
+ Factory.create_payment(@type).header[50,1].should == '0'
29
29
  end
30
30
  end
31
31
 
@@ -33,27 +33,27 @@ describe ESRPayment, 'header' do
33
33
  before(:each) do
34
34
  @type = :esr
35
35
  end
36
-
36
+
37
37
  it_should_behave_like 'all headers'
38
-
38
+
39
39
  it 'should set a the correct processing date' do
40
40
  Factory.create_esr_payment(:requested_processing_date => '051021').header[0,6].should == '051021'
41
41
  end
42
-
42
+
43
43
  it 'should fill the beneficiarys bank clearing number with blanks' do
44
44
  Factory.create_esr_payment.header[6,12].should == ''.ljust(12,' ')
45
45
  end
46
46
 
47
47
  it 'should set the ordering party bank clearing number' do
48
- Factory.create_esr_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
48
+ Factory.create_esr_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '254 '
49
49
  end
50
50
 
51
51
  it 'should should set the transaction type to 826' do
52
- Factory.create_esr_payment.header[46,3].should == '826'
52
+ Factory.create_esr_payment.header[46,3].should == '826'
53
53
  end
54
54
 
55
55
  it 'should set the payment type to 0' do
56
- Factory.create_esr_payment.header[49,1].should == '0'
56
+ Factory.create_esr_payment.header[49,1].should == '0'
57
57
  end
58
58
  end
59
59
 
@@ -62,25 +62,25 @@ describe DomesticCHFPayment, 'header' do
62
62
  @type = :domestic_chf
63
63
  end
64
64
  it_should_behave_like 'all headers'
65
-
65
+
66
66
  it 'should set a the correct processing date' do
67
67
  Factory.create_domestic_chf_payment(:requested_processing_date => '051021').header[0,6].should == '051021'
68
68
  end
69
-
69
+
70
70
  it 'should fill the beneficiarys bank clearing number with blanks' do
71
71
  Factory.create_domestic_chf_payment(:beneficiary_bank_clearing_number => "99999").header[6,12].should == '99999'.ljust(12,' ')
72
72
  end
73
-
73
+
74
74
  it 'should set the ordering party bank clearing number' do
75
- Factory.create_domestic_chf_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
75
+ Factory.create_domestic_chf_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '254 '
76
76
  end
77
-
77
+
78
78
  it 'should should set the transaction type to 827' do
79
- Factory.create_domestic_chf_payment.header[46,3].should == '827'
79
+ Factory.create_domestic_chf_payment.header[46,3].should == '827'
80
80
  end
81
81
 
82
82
  it 'should set the payment type to 0' do
83
- Factory.create_domestic_chf_payment.header[49,1].should == '0'
83
+ Factory.create_domestic_chf_payment.header[49,1].should == '0'
84
84
  end
85
85
  end
86
86
 
@@ -88,27 +88,27 @@ describe FinancialInstitutionPayment, 'header' do
88
88
  before(:each) do
89
89
  @type = :financial_institution
90
90
  end
91
-
91
+
92
92
  it_should_behave_like 'all headers'
93
-
93
+
94
94
  it 'should fill the requested processing date with zeros' do
95
95
  Factory.create_financial_institution_payment.header[0,6].should == '000000'
96
96
  end
97
-
97
+
98
98
  it 'should fill the beneficiarys bank clearing number with blanks' do
99
99
  Factory.create_financial_institution_payment.header[6,12].should == ''.ljust(12,' ')
100
100
  end
101
-
101
+
102
102
  it 'should set the ordering party bank clearing number' do
103
- Factory.create_financial_institution_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
103
+ Factory.create_financial_institution_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '254 '
104
104
  end
105
105
 
106
106
  it 'should should set the transaction type to 830' do
107
- Factory.create_financial_institution_payment.header[46,3].should == '830'
107
+ Factory.create_financial_institution_payment.header[46,3].should == '830'
108
108
  end
109
109
 
110
110
  it 'should set the payment type to 0' do
111
- Factory.create_financial_institution_payment.header[49,1].should == '0'
111
+ Factory.create_financial_institution_payment.header[49,1].should == '0'
112
112
  end
113
113
  end
114
114
 
@@ -116,27 +116,27 @@ describe BankChequePayment, 'header' do
116
116
  before(:each) do
117
117
  @type = :bank_cheque
118
118
  end
119
-
119
+
120
120
  it_should_behave_like 'all headers'
121
-
121
+
122
122
  it 'should fill the requested processing date with zeros' do
123
123
  Factory.create_bank_cheque_payment.header[0,6].should == '000000'
124
124
  end
125
-
125
+
126
126
  it 'should fill the beneficiarys bank clearing number with blanks' do
127
127
  Factory.create_bank_cheque_payment.header[6,12].should == ''.ljust(12,' ')
128
128
  end
129
-
129
+
130
130
  it 'should set the ordering party bank clearing number' do
131
- Factory.create_bank_cheque_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
131
+ Factory.create_bank_cheque_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '254 '
132
132
  end
133
-
133
+
134
134
  it 'should should set the transaction type to 832' do
135
- Factory.create_bank_cheque_payment.header[46,3].should == '832'
135
+ Factory.create_bank_cheque_payment.header[46,3].should == '832'
136
136
  end
137
137
 
138
138
  it 'should set the payment type to 0' do
139
- Factory.create_bank_cheque_payment.header[49,1].should == '0'
139
+ Factory.create_bank_cheque_payment.header[49,1].should == '0'
140
140
  end
141
141
  end
142
142
 
@@ -144,27 +144,27 @@ describe IBANPayment, 'header' do
144
144
  before(:each) do
145
145
  @type = :iban
146
146
  end
147
-
147
+
148
148
  it_should_behave_like 'all headers'
149
-
149
+
150
150
  it 'should fill the requested processing date with zeros' do
151
151
  Factory.create_iban_payment.header[0,6].should == '000000'
152
152
  end
153
-
153
+
154
154
  it 'should fill the beneficiarys bank clearing number with blanks' do
155
155
  Factory.create_iban_payment.header[6,12].should == ''.ljust(12,' ')
156
156
  end
157
-
157
+
158
158
  it 'should set the ordering party bank clearing number' do
159
- Factory.create_iban_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
159
+ Factory.create_iban_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '254 '
160
160
  end
161
-
161
+
162
162
  it 'should should set the transaction type to 836' do
163
- Factory.create_iban_payment.header[46,3].should == '836'
163
+ Factory.create_iban_payment.header[46,3].should == '836'
164
164
  end
165
165
 
166
166
  it 'should set the payment type to 1' do
167
- Factory.create_iban_payment.header[49,1].should == '1'
167
+ Factory.create_iban_payment.header[49,1].should == '1'
168
168
  end
169
169
  end
170
170
 
@@ -172,27 +172,27 @@ describe SpecialFinancialInstitutionPayment, 'header' do
172
172
  before(:each) do
173
173
  @type = :special_financial_institution
174
174
  end
175
-
175
+
176
176
  it_should_behave_like 'all headers'
177
-
177
+
178
178
  it 'should fill the requested processing date with zeros' do
179
179
  Factory.create_special_financial_institution_payment.header[0,6].should == '000000'
180
180
  end
181
-
181
+
182
182
  it 'should fill the beneficiarys bank clearing number with blanks' do
183
183
  Factory.create_special_financial_institution_payment.header[6,12].should == ''.ljust(12,' ')
184
184
  end
185
-
185
+
186
186
  it 'should set the ordering party bank clearing number' do
187
- Factory.create_special_financial_institution_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
187
+ Factory.create_special_financial_institution_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '254 '
188
188
  end
189
189
 
190
190
  it 'should should set the transaction type to 837' do
191
- Factory.create_special_financial_institution_payment.header[46,3].should == '837'
191
+ Factory.create_special_financial_institution_payment.header[46,3].should == '837'
192
192
  end
193
193
 
194
194
  it 'should set the payment type to 1' do
195
- Factory.create_special_financial_institution_payment.header[49,1].should == '1'
195
+ Factory.create_special_financial_institution_payment.header[49,1].should == '1'
196
196
  end
197
197
  end
198
198
 
@@ -200,22 +200,22 @@ describe TotalRecord, 'header' do
200
200
  before(:each) do
201
201
  @type = :total
202
202
  end
203
-
203
+
204
204
  it_should_behave_like 'all headers'
205
-
205
+
206
206
  it 'should fill the ordering party bank clearing number with blanks' do
207
207
  Factory.create_total_payment.header[29,7].should == ' '
208
208
  end
209
-
209
+
210
210
  it 'should should set the transaction type to 890' do
211
- Factory.create_total_payment.header[46,3].should == '890'
211
+ Factory.create_total_payment.header[46,3].should == '890'
212
212
  end
213
-
213
+
214
214
  it 'should set the payment type to 0' do
215
- Factory.create_total_payment.header[49,1].should == '0'
215
+ Factory.create_total_payment.header[49,1].should == '0'
216
216
  end
217
-
217
+
218
218
  it 'should set a the correct processing date' do
219
219
  Factory.create_total_payment.header[0,6].should == '000000'
220
220
  end
221
- end
221
+ end