sepa_king_extended 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +30 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +267 -0
  9. data/Rakefile +6 -0
  10. data/gemfiles/Gemfile-activemodel-3.0.x +5 -0
  11. data/gemfiles/Gemfile-activemodel-3.1.x +5 -0
  12. data/gemfiles/Gemfile-activemodel-3.2.x +5 -0
  13. data/gemfiles/Gemfile-activemodel-4.0.x +5 -0
  14. data/gemfiles/Gemfile-activemodel-4.1.x +5 -0
  15. data/gemfiles/Gemfile-activemodel-4.2.x +5 -0
  16. data/gemfiles/Gemfile-activemodel-5.0.x +5 -0
  17. data/gemfiles/Gemfile-activemodel-5.1.x +5 -0
  18. data/lib/schema/pain.001.001.03.xsd +921 -0
  19. data/lib/schema/pain.001.002.03.xsd +450 -0
  20. data/lib/schema/pain.001.003.03.xsd +474 -0
  21. data/lib/schema/pain.008.001.02.xsd +879 -0
  22. data/lib/schema/pain.008.002.02.xsd +597 -0
  23. data/lib/schema/pain.008.003.02.xsd +614 -0
  24. data/lib/sepa_king/account/creditor_account.rb +8 -0
  25. data/lib/sepa_king/account/debtor_account.rb +5 -0
  26. data/lib/sepa_king/account.rb +19 -0
  27. data/lib/sepa_king/converter.rb +51 -0
  28. data/lib/sepa_king/message/credit_transfer.rb +99 -0
  29. data/lib/sepa_king/message/direct_debit.rb +151 -0
  30. data/lib/sepa_king/message.rb +135 -0
  31. data/lib/sepa_king/transaction/credit_transfer_transaction.rb +30 -0
  32. data/lib/sepa_king/transaction/direct_debit_transaction.rb +45 -0
  33. data/lib/sepa_king/transaction.rb +44 -0
  34. data/lib/sepa_king/validator.rb +68 -0
  35. data/lib/sepa_king/version.rb +3 -0
  36. data/lib/sepa_king.rb +16 -0
  37. data/sepa_king_extended.gemspec +32 -0
  38. data/spec/account_spec.rb +42 -0
  39. data/spec/converter_spec.rb +74 -0
  40. data/spec/credit_transfer_spec.rb +364 -0
  41. data/spec/credit_transfer_transaction_spec.rb +58 -0
  42. data/spec/creditor_account_spec.rb +23 -0
  43. data/spec/debtor_account_spec.rb +12 -0
  44. data/spec/direct_debit_spec.rb +469 -0
  45. data/spec/direct_debit_transaction_spec.rb +69 -0
  46. data/spec/examples/pain.001.001.03.xml +89 -0
  47. data/spec/examples/pain.001.002.03.xml +89 -0
  48. data/spec/examples/pain.001.003.03.xml +89 -0
  49. data/spec/examples/pain.008.002.02.xml +134 -0
  50. data/spec/examples/pain.008.003.02.xml +134 -0
  51. data/spec/message_spec.rb +88 -0
  52. data/spec/spec_helper.rb +33 -0
  53. data/spec/support/active_model.rb +30 -0
  54. data/spec/support/custom_matcher.rb +60 -0
  55. data/spec/support/factories.rb +24 -0
  56. data/spec/support/validations.rb +27 -0
  57. data/spec/transaction_spec.rb +88 -0
  58. data/spec/validation_spec.rb +25 -0
  59. data/spec/validator_spec.rb +99 -0
  60. metadata +254 -0
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::Account do
5
+ describe :new do
6
+ it 'should not accept unknown keys' do
7
+ expect {
8
+ SEPA::Account.new foo: 'bar'
9
+ }.to raise_error(NoMethodError)
10
+ end
11
+ end
12
+
13
+ describe :name do
14
+ it 'should accept valid value' do
15
+ expect(SEPA::Account).to accept('Gläubiger GmbH', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
16
+ end
17
+
18
+ it 'should not accept invalid value' do
19
+ expect(SEPA::Account).not_to accept(nil, '', 'X' * 71, for: :name)
20
+ end
21
+ end
22
+
23
+ describe :iban do
24
+ it 'should accept valid value' do
25
+ expect(SEPA::Account).to accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
26
+ end
27
+
28
+ it 'should not accept invalid value' do
29
+ expect(SEPA::Account).not_to accept(nil, '', 'invalid', for: :iban)
30
+ end
31
+ end
32
+
33
+ describe :bic do
34
+ it 'should accept valid value' do
35
+ expect(SEPA::Account).to accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
36
+ end
37
+
38
+ it 'should not accept invalid value' do
39
+ expect(SEPA::Account).not_to accept('', 'invalid', for: :bic)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::Converter do
5
+ include SEPA::Converter::InstanceMethods
6
+
7
+ describe :convert_text do
8
+ it 'should convert special chars' do
9
+ expect(convert_text('10€')).to eq('10E')
10
+ expect(convert_text('info@bundesbank.de')).to eq('info(at)bundesbank.de')
11
+ expect(convert_text('abc_def')).to eq('abc-def')
12
+ end
13
+
14
+ it 'should not change allowed special character' do
15
+ expect(convert_text('üöäÜÖÄß')).to eq('üöäÜÖÄß')
16
+ expect(convert_text('&*$%')).to eq('&*$%')
17
+ end
18
+
19
+ it 'should convert line breaks' do
20
+ expect(convert_text("one\ntwo")) .to eq('one two')
21
+ expect(convert_text("one\ntwo\n")) .to eq('one two')
22
+ expect(convert_text("\none\ntwo\n")).to eq('one two')
23
+ expect(convert_text("one\n\ntwo")) .to eq('one two')
24
+ end
25
+
26
+ it 'should convert number' do
27
+ expect(convert_text(1234)).to eq('1234')
28
+ end
29
+
30
+ it 'should remove invalid chars' do
31
+ expect(convert_text('"=<>!')).to eq('')
32
+ end
33
+
34
+ it 'should not touch valid chars' do
35
+ expect(convert_text("abc-ABC-0123- ':?,-(+.)/")).to eq("abc-ABC-0123- ':?,-(+.)/")
36
+ end
37
+
38
+ it 'should not touch nil' do
39
+ expect(convert_text(nil)).to eq(nil)
40
+ end
41
+ end
42
+
43
+ describe :convert_decimal do
44
+ it "should convert Integer to BigDecimal" do
45
+ expect(convert_decimal(42)).to eq(BigDecimal('42.00'))
46
+ end
47
+
48
+ it "should convert Float to BigDecimal" do
49
+ expect(convert_decimal(42.12)).to eq(BigDecimal('42.12'))
50
+ end
51
+
52
+ it 'should round' do
53
+ expect(convert_decimal(1.345)).to eq(BigDecimal('1.35'))
54
+ end
55
+
56
+ it 'should not touch nil' do
57
+ expect(convert_decimal(nil)).to eq(nil)
58
+ end
59
+
60
+ it 'should not convert zero value' do
61
+ expect(convert_decimal(0)).to eq(nil)
62
+ end
63
+
64
+ it 'should not convert negative value' do
65
+ expect(convert_decimal(-3)).to eq(nil)
66
+ end
67
+
68
+ it 'should not convert invalid value' do
69
+ expect(convert_decimal('xyz')).to eq(nil)
70
+ expect(convert_decimal('NaN')).to eq(nil)
71
+ expect(convert_decimal('Infinity')).to eq(nil)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,364 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::CreditTransfer do
5
+ let(:message_id_regex) { /SEPA-KING\/[0-9a-z_]{22}/ }
6
+ let(:credit_transfer) {
7
+ SEPA::CreditTransfer.new name: 'Schuldner GmbH',
8
+ bic: 'BANKDEFFXXX',
9
+ iban: 'DE87200500001234567890'
10
+ }
11
+
12
+ describe :new do
13
+ it 'should accept missing options' do
14
+ expect {
15
+ SEPA::CreditTransfer.new
16
+ }.to_not raise_error
17
+ end
18
+ end
19
+
20
+ describe :add_transaction do
21
+ it 'should add valid transactions' do
22
+ 3.times do
23
+ credit_transfer.add_transaction(credit_transfer_transaction)
24
+ end
25
+
26
+ expect(credit_transfer.transactions.size).to eq(3)
27
+ end
28
+
29
+ it 'should fail for invalid transaction' do
30
+ expect {
31
+ credit_transfer.add_transaction name: ''
32
+ }.to raise_error(ArgumentError)
33
+ end
34
+ end
35
+
36
+ describe :to_xml do
37
+ context 'for invalid debtor' do
38
+ it 'should fail' do
39
+ expect {
40
+ SEPA::CreditTransfer.new.to_xml
41
+ }.to raise_error(RuntimeError)
42
+ end
43
+ end
44
+
45
+ context 'for valid debtor' do
46
+ context 'without BIC (IBAN-only)' do
47
+ subject do
48
+ sct = SEPA::CreditTransfer.new name: 'Schuldner GmbH',
49
+ iban: 'DE87200500001234567890'
50
+
51
+ sct.add_transaction name: 'Telekomiker AG',
52
+ bic: 'PBNKDEFF370',
53
+ iban: 'DE37112589611964645802',
54
+ amount: 102.50,
55
+ reference: 'XYZ-1234/123',
56
+ remittance_information: 'Rechnung vom 22.08.2013'
57
+
58
+ sct
59
+ end
60
+
61
+ it 'should create valid XML file' do
62
+ expect(subject.to_xml).to validate_against('pain.001.003.03.xsd')
63
+ end
64
+
65
+ it 'should fail for pain.001.001.03' do
66
+ expect {
67
+ subject.to_xml(SEPA::PAIN_001_001_03)
68
+ }.to raise_error(RuntimeError)
69
+ end
70
+
71
+ it 'should fail for pain.001.002.03' do
72
+ expect {
73
+ subject.to_xml(SEPA::PAIN_001_002_03)
74
+ }.to raise_error(RuntimeError)
75
+ end
76
+ end
77
+
78
+ context 'with BIC' do
79
+ subject do
80
+ sct = credit_transfer
81
+
82
+ sct.add_transaction name: 'Telekomiker AG',
83
+ bic: 'PBNKDEFF370',
84
+ iban: 'DE37112589611964645802',
85
+ amount: 102.50,
86
+ reference: 'XYZ-1234/123',
87
+ remittance_information: 'Rechnung vom 22.08.2013'
88
+
89
+ sct
90
+ end
91
+
92
+ it 'should validate against pain.001.001.03' do
93
+ expect(subject.to_xml('pain.001.001.03')).to validate_against('pain.001.001.03.xsd')
94
+ end
95
+
96
+ it 'should validate against pain.001.002.03' do
97
+ expect(subject.to_xml('pain.001.002.03')).to validate_against('pain.001.002.03.xsd')
98
+ end
99
+
100
+ it 'should validate against pain.001.003.03' do
101
+ expect(subject.to_xml('pain.001.003.03')).to validate_against('pain.001.003.03.xsd')
102
+ end
103
+ end
104
+
105
+ context 'without requested_date given' do
106
+ subject do
107
+ sct = credit_transfer
108
+
109
+ sct.add_transaction name: 'Telekomiker AG',
110
+ bic: 'PBNKDEFF370',
111
+ iban: 'DE37112589611964645802',
112
+ amount: 102.50,
113
+ reference: 'XYZ-1234/123',
114
+ remittance_information: 'Rechnung vom 22.08.2013'
115
+
116
+ sct.add_transaction name: 'Amazonas GmbH',
117
+ iban: 'DE27793589132923472195',
118
+ amount: 59.00,
119
+ reference: 'XYZ-5678/456',
120
+ remittance_information: 'Rechnung vom 21.08.2013'
121
+
122
+ sct.to_xml
123
+ end
124
+
125
+ it 'should create valid XML file' do
126
+ expect(subject).to validate_against('pain.001.003.03.xsd')
127
+ end
128
+
129
+ it 'should have message_identification' do
130
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/GrpHdr/MsgId', message_id_regex)
131
+ end
132
+
133
+ it 'should contain <PmtInfId>' do
134
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /#{message_id_regex}\/1/)
135
+ end
136
+
137
+ it 'should contain <ReqdExctnDt>' do
138
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.new(1999, 1, 1).iso8601)
139
+ end
140
+
141
+ it 'should contain <PmtMtd>' do
142
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtMtd', 'TRF')
143
+ end
144
+
145
+ it 'should contain <BtchBookg>' do
146
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/BtchBookg', 'true')
147
+ end
148
+
149
+ it 'should contain <NbOfTxs>' do
150
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/NbOfTxs', '2')
151
+ end
152
+
153
+ it 'should contain <CtrlSum>' do
154
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CtrlSum', '161.50')
155
+ end
156
+
157
+ it 'should contain <Dbtr>' do
158
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/Dbtr/Nm', 'Schuldner GmbH')
159
+ end
160
+
161
+ it 'should contain <DbtrAcct>' do
162
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAcct/Id/IBAN', 'DE87200500001234567890')
163
+ end
164
+
165
+ it 'should contain <DbtrAgt>' do
166
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAgt/FinInstnId/BIC', 'BANKDEFFXXX')
167
+ end
168
+
169
+ it 'should contain <EndToEndId>' do
170
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/EndToEndId', 'XYZ-1234/123')
171
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/PmtId/EndToEndId', 'XYZ-5678/456')
172
+ end
173
+
174
+ it 'should contain <Amt>' do
175
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt', '102.50')
176
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Amt/InstdAmt', '59.00')
177
+ end
178
+
179
+ it 'should contain <CdtrAgt> for every BIC given' do
180
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAgt/FinInstnId/BIC', 'PBNKDEFF370')
181
+ expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAgt')
182
+ end
183
+
184
+ it 'should contain <Cdtr>' do
185
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Cdtr/Nm', 'Telekomiker AG')
186
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Cdtr/Nm', 'Amazonas GmbH')
187
+ end
188
+
189
+ it 'should contain <CdtrAcct>' do
190
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAcct/Id/IBAN', 'DE37112589611964645802')
191
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAcct/Id/IBAN', 'DE27793589132923472195')
192
+ end
193
+
194
+ it 'should contain <RmtInf>' do
195
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Ustrd', 'Rechnung vom 22.08.2013')
196
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/RmtInf/Ustrd', 'Rechnung vom 21.08.2013')
197
+ end
198
+ end
199
+
200
+ context 'with different requested_date given' do
201
+ subject do
202
+ sct = credit_transfer
203
+
204
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 1)
205
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2)
206
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2)
207
+
208
+ sct.to_xml
209
+ end
210
+
211
+ it 'should contain two payment_informations with <ReqdExctnDt>' do
212
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
213
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 2).iso8601)
214
+
215
+ expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
216
+ end
217
+
218
+ it 'should contain two payment_informations with different <PmtInfId>' do
219
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId', /#{message_id_regex}\/1/)
220
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId', /#{message_id_regex}\/2/)
221
+ end
222
+ end
223
+
224
+ context 'with different batch_booking given' do
225
+ subject do
226
+ sct = credit_transfer
227
+
228
+ sct.add_transaction(credit_transfer_transaction.merge batch_booking: false)
229
+ sct.add_transaction(credit_transfer_transaction.merge batch_booking: true)
230
+ sct.add_transaction(credit_transfer_transaction.merge batch_booking: true)
231
+
232
+ sct.to_xml
233
+ end
234
+
235
+ it 'should contain two payment_informations with <BtchBookg>' do
236
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
237
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
238
+
239
+ expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
240
+ end
241
+ end
242
+
243
+ context 'with transactions containing different group criteria' do
244
+ subject do
245
+ sct = credit_transfer
246
+
247
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 1, batch_booking: false, amount: 1)
248
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 1, batch_booking: true, amount: 2)
249
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2, batch_booking: false, amount: 4)
250
+ sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2, batch_booking: true, amount: 8)
251
+
252
+ sct.to_xml
253
+ end
254
+
255
+ it 'should contain multiple payment_informations' do
256
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
257
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
258
+
259
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 1).iso8601)
260
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
261
+
262
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/ReqdExctnDt', (Date.today + 2).iso8601)
263
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/BtchBookg', 'false')
264
+
265
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/ReqdExctnDt', (Date.today + 2).iso8601)
266
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/BtchBookg', 'true')
267
+ end
268
+
269
+ it 'should have multiple control sums' do
270
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/CtrlSum', '1.00')
271
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/CtrlSum', '2.00')
272
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/CtrlSum', '4.00')
273
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/CtrlSum', '8.00')
274
+ end
275
+ end
276
+
277
+ context 'with instruction given' do
278
+ subject do
279
+ sct = credit_transfer
280
+
281
+ sct.add_transaction name: 'Telekomiker AG',
282
+ iban: 'DE37112589611964645802',
283
+ amount: 102.50,
284
+ instruction: '1234/ABC'
285
+
286
+ sct.to_xml
287
+ end
288
+
289
+ it 'should create valid XML file' do
290
+ expect(subject).to validate_against('pain.001.003.03.xsd')
291
+ end
292
+
293
+ it 'should contain <InstrId>' do
294
+ expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/InstrId', '1234/ABC')
295
+ end
296
+ end
297
+
298
+ context 'with a different currency given' do
299
+ subject do
300
+ sct = credit_transfer
301
+
302
+ sct.add_transaction name: 'Telekomiker AG',
303
+ iban: 'DE37112589611964645802',
304
+ bic: 'PBNKDEFF370',
305
+ amount: 102.50,
306
+ currency: 'CHF'
307
+
308
+ sct
309
+ end
310
+
311
+ it 'should validate against pain.001.001.03' do
312
+ expect(subject.to_xml('pain.001.001.03')).to validate_against('pain.001.001.03.xsd')
313
+ end
314
+
315
+ it 'should have a CHF Ccy' do
316
+ doc = Nokogiri::XML(subject.to_xml('pain.001.001.03'))
317
+ doc.remove_namespaces!
318
+
319
+ nodes = doc.xpath('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt')
320
+ expect(nodes.length).to eql(1)
321
+ expect(nodes.first.attribute('Ccy').value).to eql('CHF')
322
+ end
323
+
324
+ it 'should fail for pain.001.002.03' do
325
+ expect {
326
+ subject.to_xml(SEPA::PAIN_001_002_03)
327
+ }.to raise_error(RuntimeError)
328
+ end
329
+
330
+ it 'should fail for pain.001.003.03' do
331
+ expect {
332
+ subject.to_xml(SEPA::PAIN_001_003_03)
333
+ }.to raise_error(RuntimeError)
334
+ end
335
+ end
336
+
337
+ context 'with a transaction without a bic' do
338
+ subject do
339
+ sct = credit_transfer
340
+
341
+ sct.add_transaction name: 'Telekomiker AG',
342
+ iban: 'DE37112589611964645802',
343
+ amount: 102.50
344
+
345
+ sct
346
+ end
347
+
348
+ it 'should validate against pain.001.001.03' do
349
+ expect(subject.to_xml('pain.001.001.03')).to validate_against('pain.001.001.03.xsd')
350
+ end
351
+
352
+ it 'should fail for pain.001.002.03' do
353
+ expect {
354
+ subject.to_xml(SEPA::PAIN_001_002_03)
355
+ }.to raise_error(RuntimeError)
356
+ end
357
+
358
+ it 'should validate against pain.001.003.03' do
359
+ expect(subject.to_xml(SEPA::PAIN_001_003_03)).to validate_against('pain.001.003.03.xsd')
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::CreditTransferTransaction do
5
+ describe :initialize do
6
+ it 'should initialize a valid transaction' do
7
+ expect(
8
+ SEPA::CreditTransferTransaction.new name: 'Telekomiker AG',
9
+ iban: 'DE37112589611964645802',
10
+ bic: 'PBNKDEFF370',
11
+ amount: 102.50,
12
+ reference: 'XYZ-1234/123',
13
+ remittance_information: 'Rechnung 123 vom 22.08.2013'
14
+ ).to be_valid
15
+ end
16
+ end
17
+
18
+ describe :schema_compatible? do
19
+ context 'for pain.001.003.03' do
20
+ it 'should succeed' do
21
+ expect(SEPA::CreditTransferTransaction.new({})).to be_schema_compatible('pain.001.003.03')
22
+ end
23
+
24
+ it 'should fail for invalid attributes' do
25
+ expect(SEPA::CreditTransferTransaction.new(:currency => 'CHF')).not_to be_schema_compatible('pain.001.003.03')
26
+ end
27
+ end
28
+
29
+ context 'pain.001.002.03' do
30
+ it 'should succeed for valid attributes' do
31
+ expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'SEPA')).to be_schema_compatible('pain.001.002.03')
32
+ end
33
+
34
+ it 'should fail for invalid attributes' do
35
+ expect(SEPA::CreditTransferTransaction.new(:bic => nil)).not_to be_schema_compatible('pain.001.002.03')
36
+ expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'URGP')).not_to be_schema_compatible('pain.001.002.03')
37
+ expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).not_to be_schema_compatible('pain.001.002.03')
38
+ end
39
+ end
40
+
41
+ context 'for pain.001.001.03' do
42
+ it 'should succeed for valid attributes' do
43
+ expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).to be_schema_compatible('pain.001.001.03')
44
+ expect(SEPA::CreditTransferTransaction.new(:bic => nil)).to be_schema_compatible('pain.001.003.03')
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'Requested date' do
50
+ it 'should allow valid value' do
51
+ expect(SEPA::CreditTransferTransaction).to accept(nil, Date.new(1999, 1, 1), Date.today, Date.today.next, Date.today + 2, for: :requested_date)
52
+ end
53
+
54
+ it 'should not allow invalid value' do
55
+ expect(SEPA::CreditTransferTransaction).not_to accept(Date.new(1995,12,21), Date.today - 1, for: :requested_date)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::CreditorAccount do
5
+ it 'should initialize a new account' do
6
+ expect(
7
+ SEPA::CreditorAccount.new name: 'Gläubiger GmbH',
8
+ bic: 'BANKDEFFXXX',
9
+ iban: 'DE87200500001234567890',
10
+ creditor_identifier: 'DE98ZZZ09999999999'
11
+ ).to be_valid
12
+ end
13
+
14
+ describe :creditor_identifier do
15
+ it 'should accept valid value' do
16
+ expect(SEPA::CreditorAccount).to accept('DE98ZZZ09999999999', 'AT12ZZZ00000000001', 'IT97ZZZA1B2C3D4E5F6G7H8', 'NL97ZZZ123456780001', 'FR12ZZZ123456', for: :creditor_identifier)
17
+ end
18
+
19
+ it 'should not accept invalid value' do
20
+ expect(SEPA::CreditorAccount).not_to accept('', 'invalid', 'DE98ZZZ099999999990', 'DEAAAAAAAAAAAAAAAA', for: :creditor_identifier)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::DebtorAccount do
5
+ it 'should initialize a new account' do
6
+ expect(
7
+ SEPA::DebtorAccount.new name: 'Gläubiger GmbH',
8
+ bic: 'BANKDEFFXXX',
9
+ iban: 'DE87200500001234567890'
10
+ ).to be_valid
11
+ end
12
+ end