sepafm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # First the sepa gem is loaded by requiring it
2
- require 'sepa'
2
+ require 'sepafm'
3
3
 
4
4
  # The params hash is populated with the data that is needed for gem to function
5
5
  params = {
@@ -1,8 +1,185 @@
1
1
  # First the sepa gem is loaded by requiring it
2
- require 'sepa'
2
+ require 'sepafm'
3
3
 
4
- # A test payload with no actual data
5
- payload = "test_payload"
4
+ @invoice_bundle = []
5
+
6
+ invoice_1 = {
7
+ type: 'CINV',
8
+ amount: '700',
9
+ currency: 'EUR',
10
+ invoice_number: '123456'
11
+ }
12
+
13
+ invoice_2 = {
14
+ type: 'CINV',
15
+ amount: '300',
16
+ currency: 'EUR',
17
+ reference: '123456789',
18
+ }
19
+
20
+ invoice_3 = {
21
+ type: 'CREN',
22
+ amount: '-100',
23
+ currency: 'EUR',
24
+ invoice_number: '654321'
25
+ }
26
+
27
+ invoice_4 = {
28
+ type: 'CREN',
29
+ amount: '-500',
30
+ currency: 'EUR',
31
+ reference: '987654321'
32
+ }
33
+
34
+ @invoice_bundle.push(invoice_1)
35
+ @invoice_bundle.push(invoice_2)
36
+ @invoice_bundle.push(invoice_3)
37
+ @invoice_bundle.push(invoice_4)
38
+
39
+ trans_1_params = {
40
+ instruction_id: SecureRandom.hex,
41
+ end_to_end_id: SecureRandom.hex,
42
+ amount: '30.75',
43
+ currency: 'EUR',
44
+ bic: 'NDEAFIHH',
45
+ name: 'Testi Saaja Oy',
46
+ address: 'Kokeilukatu 66',
47
+ country: 'FI',
48
+ postcode: '00200',
49
+ town: 'Helsinki',
50
+ iban: 'FI7429501800000014',
51
+ reference: '00000000000000001245',
52
+ message: 'Maksu'
53
+ }
54
+
55
+ trans_2_params = {
56
+ instruction_id: SecureRandom.hex,
57
+ end_to_end_id: SecureRandom.hex,
58
+ amount: '1075.20',
59
+ currency: 'EUR',
60
+ bic: 'NDEAFIHH',
61
+ name: 'Testing Company',
62
+ address: 'Tynnyrikatu 56',
63
+ country: 'FI',
64
+ postcode: '00600',
65
+ town: 'Helsinki',
66
+ iban: 'FI7429501800000014',
67
+ reference: '000000000000000034795',
68
+ message: 'Siirto',
69
+ invoice_bundle: @invoice_bundle
70
+ }
71
+
72
+ trans_3_params = {
73
+ instruction_id: SecureRandom.hex,
74
+ end_to_end_id: SecureRandom.hex,
75
+ amount: '10000',
76
+ currency: 'EUR',
77
+ bic: 'NDEAFIHH',
78
+ name: 'Best Company Ever',
79
+ address: 'Banaanikuja 66',
80
+ country: 'FI',
81
+ postcode: '00900',
82
+ town: 'Helsinki',
83
+ iban: 'FI7429501800000014',
84
+ reference: '000000000000000013247',
85
+ message: 'Valuutan siirto toiselle tilille'
86
+ }
87
+
88
+ trans_4_params = {
89
+ instruction_id: SecureRandom.hex,
90
+ end_to_end_id: SecureRandom.hex,
91
+ amount: '12',
92
+ currency: 'EUR',
93
+ bic: 'NDEAFIHH',
94
+ name: 'Testi Saaja Oy',
95
+ address: 'Kokeilukatu 66',
96
+ country: 'FI',
97
+ postcode: '00200',
98
+ town: 'Helsinki',
99
+ iban: 'FI7429501800000014',
100
+ reference: '00000000000000001245',
101
+ message: 'Palkka heinakuulta',
102
+ salary: true,
103
+ social_security_number: '112233-0010'
104
+ }
105
+
106
+ trans_5_params = {
107
+ instruction_id: SecureRandom.hex,
108
+ end_to_end_id: SecureRandom.hex,
109
+ amount: '99.20',
110
+ currency: 'EUR',
111
+ bic: 'NDEAFIHH',
112
+ name: 'Testing Company',
113
+ address: 'Tynnyrikatu 56',
114
+ country: 'FI',
115
+ postcode: '00600',
116
+ town: 'Helsinki',
117
+ iban: 'FI7429501800000014',
118
+ reference: '000000000000000034795',
119
+ message: 'Elake',
120
+ pension: true
121
+ }
122
+
123
+ trans_6_params = {
124
+ instruction_id: SecureRandom.hex,
125
+ end_to_end_id: SecureRandom.hex,
126
+ amount: '15000',
127
+ currency: 'EUR',
128
+ bic: 'NDEAFIHH',
129
+ name: 'Best Company Ever',
130
+ address: 'Banaanikuja 66',
131
+ country: 'FI',
132
+ postcode: '00900',
133
+ town: 'Helsinki',
134
+ iban: 'FI7429501800000014',
135
+ reference: '000000000000000013247',
136
+ message: 'Palkka ajalta 15.6.2013 - 30.6.2013',
137
+ salary: true,
138
+ social_security_number: '112233-0096'
139
+ }
140
+
141
+ debtor = {
142
+ name: 'Testi Maksaja Oy',
143
+ address: 'Testing Street 12',
144
+ country: 'FI',
145
+ postcode: '00100',
146
+ town: 'Helsinki',
147
+ customer_id: '111111111',
148
+ iban: 'FI4819503000000010',
149
+ bic: 'NDEAFIHH'
150
+ }
151
+
152
+ payment_1_transactions = []
153
+ payment_2_transactions = []
154
+
155
+ payment_1_transactions.push(Sepa::Transaction.new(trans_1_params))
156
+ payment_1_transactions.push(Sepa::Transaction.new(trans_2_params))
157
+ payment_1_transactions.push(Sepa::Transaction.new(trans_3_params))
158
+
159
+ payment_2_transactions.push(Sepa::Transaction.new(trans_4_params))
160
+ payment_2_transactions.push(Sepa::Transaction.new(trans_5_params))
161
+ payment_2_transactions.push(Sepa::Transaction.new(trans_6_params))
162
+
163
+ payment_1_params = {
164
+ payment_info_id: SecureRandom.hex,
165
+ execution_date: '2013-08-10',
166
+ transactions: payment_1_transactions
167
+ }
168
+
169
+ payment_2_params = {
170
+ payment_info_id: SecureRandom.hex,
171
+ execution_date: '2013-08-15',
172
+ salary_or_pension: true,
173
+ transactions: payment_2_transactions
174
+ }
175
+
176
+ payments = []
177
+
178
+ payments.push(Sepa::Payment.new(debtor, payment_1_params))
179
+ payments.push(Sepa::Payment.new(debtor, payment_2_params))
180
+
181
+ payload = Sepa::Payload.new(debtor, payments)
182
+ payload = payload.to_xml
6
183
 
7
184
  # The params hash is populated with the data that is needed for gem to function.
8
185
  params = {
@@ -14,7 +191,7 @@ params = {
14
191
  private_key_path: "sepa/nordea_testing/keys/nordea.key",
15
192
 
16
193
  # Command :download_file_list, :upload_file, :download_file or :get_user_info.
17
- command: :get_user_info,
194
+ command: :upload_file,
18
195
 
19
196
  # Unique customer ID.
20
197
  customer_id: '11111111',
@@ -40,7 +217,7 @@ params = {
40
217
  # - NDCORPAYS = Yrityksen maksut XML (lähtevä)
41
218
  # - NDCAMT53L = Konekielinen XML-tiliote (saapuva)
42
219
  # - NDCAMT54L = Saapuvat XML viitemaksu (saapuva)
43
- file_type: 'TITO',
220
+ file_type: 'NDCORPAYS',
44
221
 
45
222
  # The WSDL file used by nordea. Is identical between banks except for the
46
223
  # address.
@@ -74,7 +251,7 @@ puts "\nSome info about response's certificate:\n" \
74
251
  "First day to use this certificate: #{response.certificate.not_before}\n" \
75
252
  "Expires: #{response.certificate.not_after}"
76
253
 
77
- puts "\nSome info about application response's certificate:\n" \
254
+ puts "\nSome info about application response's certificate:\n" \
78
255
  "Issuer: #{ar.certificate.issuer}\n" \
79
256
  "First day to use this certificate: #{ar.certificate.not_before}\n" \
80
257
  "Expires: #{ar.certificate.not_after}"
@@ -16,6 +16,10 @@ require 'sepa/userfiletype'
16
16
  require 'time'
17
17
  require 'sepa/response'
18
18
  require 'sepa/application_response'
19
+ require 'sepa/payload'
19
20
  require 'sepa/soap_builder'
20
21
  require 'sepa/soap_danske'
21
22
  require 'sepa/soap_nordea'
23
+ require 'sepa/transaction'
24
+ require 'sepa/payment'
25
+ require 'sepa/custom_exceptions'
@@ -0,0 +1,297 @@
1
+ require File.expand_path('../../test_helper.rb', __FILE__)
2
+
3
+ class TestPayload < MiniTest::Test
4
+ def setup
5
+ @schemas_path = File.expand_path('../../../lib/sepa/xml_schemas', __FILE__)
6
+
7
+ @invoice_bundle = []
8
+
9
+ invoice_1 = {
10
+ type: 'CINV',
11
+ amount: '700',
12
+ currency: 'EUR',
13
+ invoice_number: '123456'
14
+ }
15
+
16
+ invoice_2 = {
17
+ type: 'CINV',
18
+ amount: '300',
19
+ currency: 'EUR',
20
+ reference: '123456789',
21
+ }
22
+
23
+ invoice_3 = {
24
+ type: 'CREN',
25
+ amount: '-100',
26
+ currency: 'EUR',
27
+ invoice_number: '654321'
28
+ }
29
+
30
+ invoice_4 = {
31
+ type: 'CREN',
32
+ amount: '-500',
33
+ currency: 'EUR',
34
+ reference: '987654321'
35
+ }
36
+
37
+ @invoice_bundle.push(invoice_1)
38
+ @invoice_bundle.push(invoice_2)
39
+ @invoice_bundle.push(invoice_3)
40
+ @invoice_bundle.push(invoice_4)
41
+
42
+ trans_1_params = {
43
+ instruction_id: '70CEF29BEBA8396A1F806005EDA51DEE4CE',
44
+ end_to_end_id: '629CADFDAD5246AD915BA24A3C8E9FC3313',
45
+ amount: '30.75',
46
+ currency: 'EUR',
47
+ bic: 'NDEAFIHH',
48
+ name: 'Testi Saaja Oy',
49
+ address: 'Kokeilukatu 66',
50
+ country: 'FI',
51
+ postcode: '00200',
52
+ town: 'Helsinki',
53
+ iban: 'FI7429501800000014',
54
+ reference: '00000000000000001245',
55
+ message: 'Maksu'
56
+ }
57
+
58
+ trans_2_params = {
59
+ instruction_id: 'A552D3EBB207B4AC17DF97C7D548A0571B0',
60
+ end_to_end_id: 'CDE1206C8745D6FBDCD2BBB02DB6CB6D3BE',
61
+ amount: '1075.20',
62
+ currency: 'EUR',
63
+ bic: 'NDEAFIHH',
64
+ name: 'Testing Company',
65
+ address: 'Tynnyrikatu 56',
66
+ country: 'FI',
67
+ postcode: '00600',
68
+ town: 'Helsinki',
69
+ iban: 'FI7429501800000014',
70
+ reference: '000000000000000034795',
71
+ message: 'Siirto',
72
+ invoice_bundle: @invoice_bundle
73
+ }
74
+
75
+ trans_3_params = {
76
+ instruction_id: '44DB2850ABDFBEF2A32D0EE511BE5AB0B79',
77
+ end_to_end_id: 'A107CF858A22116D0C8EC1E78B078794B8C',
78
+ amount: '10000',
79
+ currency: 'EUR',
80
+ bic: 'NDEAFIHH',
81
+ name: 'Best Company Ever',
82
+ address: 'Banaanikuja 66',
83
+ country: 'FI',
84
+ postcode: '00900',
85
+ town: 'Helsinki',
86
+ iban: 'FI7429501800000014',
87
+ reference: '000000000000000013247',
88
+ message: 'Valuutan siirto toiselle tilille'
89
+ }
90
+
91
+ trans_4_params = {
92
+ instruction_id: '16A0C311AF72F3F5E8B6704EB3B6086047C',
93
+ end_to_end_id: 'B10CE2EC71DB76114DDA68C9DAAA77A59DB',
94
+ amount: '12',
95
+ currency: 'EUR',
96
+ bic: 'NDEAFIHH',
97
+ name: 'Testi Saaja Oy',
98
+ address: 'Kokeilukatu 66',
99
+ country: 'FI',
100
+ postcode: '00200',
101
+ town: 'Helsinki',
102
+ iban: 'FI7429501800000014',
103
+ reference: '00000000000000001245',
104
+ message: 'Palkka heinakuulta',
105
+ salary: true,
106
+ social_security_number: '112233-0000'
107
+ }
108
+
109
+ trans_5_params = {
110
+ instruction_id: 'E0C01A8D65EA0BAB7CF1D4337FBCC3D33D7',
111
+ end_to_end_id: 'B10CE2EC71DB76114DDA68C9DAAA77A59DB',
112
+ amount: '99.20',
113
+ currency: 'EUR',
114
+ bic: 'NDEAFIHH',
115
+ name: 'Testing Company',
116
+ address: 'Tynnyrikatu 56',
117
+ country: 'FI',
118
+ postcode: '00600',
119
+ town: 'Helsinki',
120
+ iban: 'FI7429501800000014',
121
+ reference: '000000000000000034795',
122
+ message: 'Elake',
123
+ pension: true
124
+ }
125
+
126
+ trans_6_params = {
127
+ instruction_id: 'FD19CD1844B20B0E65E66EA307668B1C3F8',
128
+ end_to_end_id: 'CE9FF7E7CE5961AA1207C828DBFE467182F',
129
+ amount: '15000',
130
+ currency: 'EUR',
131
+ bic: 'NDEAFIHH',
132
+ name: 'Best Company Ever',
133
+ address: 'Banaanikuja 66',
134
+ country: 'FI',
135
+ postcode: '00900',
136
+ town: 'Helsinki',
137
+ iban: 'FI7429501800000014',
138
+ reference: '000000000000000013247',
139
+ message: 'Palkka ajalta 15.6.2013 - 30.6.2013',
140
+ salary: true,
141
+ social_security_number: '112233-0001'
142
+ }
143
+
144
+ @debtor = {
145
+ name: 'Testi Maksaja Oy',
146
+ address: 'Testing Street 12',
147
+ country: 'FI',
148
+ postcode: '00100',
149
+ town: 'Helsinki',
150
+ customer_id: '0987654321',
151
+ iban: 'FI4819503000000010',
152
+ bic: 'NDEAFIHH'
153
+ }
154
+
155
+ payment_1_transactions = []
156
+ payment_2_transactions = []
157
+
158
+ payment_1_transactions.push(Sepa::Transaction.new(trans_1_params))
159
+ payment_1_transactions.push(Sepa::Transaction.new(trans_2_params))
160
+ payment_1_transactions.push(Sepa::Transaction.new(trans_3_params))
161
+
162
+ payment_2_transactions.push(Sepa::Transaction.new(trans_4_params))
163
+ payment_2_transactions.push(Sepa::Transaction.new(trans_5_params))
164
+ payment_2_transactions.push(Sepa::Transaction.new(trans_6_params))
165
+
166
+ payment_1_params = {
167
+ payment_info_id: 'F56D46DDA136A981F58C05999479E768C92',
168
+ execution_date: '2013-08-10',
169
+ transactions: payment_1_transactions
170
+ }
171
+
172
+ payment_2_params = {
173
+ payment_info_id: 'B60EECC432C306876FE3E23999DF7F43254',
174
+ execution_date: '2013-08-15',
175
+ salary_or_pension: true,
176
+ transactions: payment_2_transactions
177
+ }
178
+
179
+ @payments = []
180
+
181
+ @payments.push(Sepa::Payment.new(@debtor, payment_1_params))
182
+ @payments.push(Sepa::Payment.new(@debtor, payment_2_params))
183
+
184
+ @payload = Sepa::Payload.new(@debtor, @payments)
185
+ @pay_noko = Nokogiri::XML(@payload.to_xml)
186
+
187
+ @xmlns = 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.02'
188
+ end
189
+
190
+ def test_should_initialize_with_proper_params
191
+ assert Sepa::Payload.new(@debtor, @payments)
192
+ end
193
+
194
+ def test_validates_against_schema
195
+ xsd = Nokogiri::XML::Schema(
196
+ File.read("#{@schemas_path}/pain.001.001.02.xsd")
197
+ )
198
+ doc = Nokogiri::XML(@payload.to_xml)
199
+
200
+ assert xsd.valid?(doc)
201
+ end
202
+
203
+ def test_debtor_name_is_added_correctly_to_group_header
204
+ assert_equal @debtor[:name],
205
+ @pay_noko.at("//xmlns:InitgPty/xmlns:Nm", 'xmlns' => @xmlns).content
206
+ end
207
+
208
+ def test_debtors_first_address_line_is_added_correctly_to_group_header
209
+ assert_equal @debtor[:address],
210
+ @pay_noko.at(
211
+ "//xmlns:InitgPty/xmlns:PstlAdr/xmlns:AdrLine[1]", 'xmlns' => @xmlns
212
+ ).content
213
+ end
214
+
215
+ def test_debtors_second_address_line_is_added_correctly_to_group_header
216
+ assert_equal "#{@debtor[:country]}-#{@debtor[:postcode]}",
217
+ @pay_noko.at(
218
+ "//xmlns:InitgPty/xmlns:PstlAdr/xmlns:AdrLine[2]", 'xmlns' => @xmlns
219
+ ).content
220
+ end
221
+
222
+ def test_debtors_street_name_is_added_correctly_to_group_header
223
+ assert_equal @debtor[:address],
224
+ @pay_noko.at(
225
+ "//xmlns:InitgPty/xmlns:PstlAdr/xmlns:StrtNm", 'xmlns' => @xmlns
226
+ ).content
227
+ end
228
+
229
+ def test_debtors_postcode_is_added_correctly_to_group_header
230
+ assert_equal "#{@debtor[:country]}-#{@debtor[:postcode]}",
231
+ @pay_noko.at(
232
+ "//xmlns:InitgPty/xmlns:PstlAdr/xmlns:PstCd", 'xmlns' => @xmlns
233
+ ).content
234
+ end
235
+
236
+ def test_debtors_town_is_added_correctly_to_group_header
237
+ assert_equal @debtor[:town],
238
+ @pay_noko.at(
239
+ "//xmlns:InitgPty/xmlns:PstlAdr/xmlns:TwnNm", 'xmlns' => @xmlns
240
+ ).content
241
+ end
242
+
243
+ def test_debtors_country_is_added_correctly_to_group_header
244
+ assert_equal @debtor[:country],
245
+ @pay_noko.at(
246
+ "//xmlns:InitgPty/xmlns:PstlAdr/xmlns:Ctry", 'xmlns' => @xmlns
247
+ ).content
248
+ end
249
+
250
+ def test_nr_of_transactions_is_added_correctly_to_group_header
251
+ assert_equal '6',
252
+ @pay_noko.at(
253
+ "//xmlns:GrpHdr/xmlns:NbOfTxs", 'xmlns' => @xmlns
254
+ ).content
255
+ end
256
+
257
+ def test_should_raise_schema_error_if_doesnt_validate_against_schema
258
+ @debtor[:name] = 'a'*71
259
+ payload = Sepa::Payload.new(@debtor, @payments)
260
+ refute payload.valid?, payload.errors.join("\n")
261
+ end
262
+
263
+ def test_raises_key_error_if_debtor_name_missing
264
+ @debtor.delete(:name)
265
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
266
+ end
267
+
268
+ def test_raises_key_error_if_debtor_address_missing
269
+ @debtor.delete(:address)
270
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
271
+ end
272
+
273
+ def test_raises_key_error_if_debtor_country_missing
274
+ @debtor.delete(:country)
275
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
276
+ end
277
+
278
+ def test_raises_key_error_if_debtor_postcode_missing
279
+ @debtor.delete(:postcode)
280
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
281
+ end
282
+
283
+ def test_raises_key_error_if_debtor_town_missing
284
+ @debtor.delete(:town)
285
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
286
+ end
287
+
288
+ def test_raises_key_error_if_debtor_customer_id_missing
289
+ @debtor.delete(:customer_id)
290
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
291
+ end
292
+
293
+ def test_raises_key_error_if_payments_missing
294
+ @payments = nil
295
+ assert_raises(KeyError) { Sepa::Payload.new(@debtor, @payments) }
296
+ end
297
+ end