sps_king 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +3 -3
  3. data/CHANGELOG.md +46 -23
  4. data/README.md +29 -13
  5. data/cliff.toml +3 -3
  6. data/gemfiles/{Gemfile-activemodel-6.1.x → Gemfile-activemodel-7.2.x} +1 -1
  7. data/gemfiles/{Gemfile-activemodel-7.0.x → Gemfile-activemodel-8.0.x} +1 -1
  8. data/lib/sps_king/account/address.rb +55 -0
  9. data/lib/sps_king/account/creditor_account.rb +3 -0
  10. data/lib/sps_king/account/creditor_address.rb +2 -34
  11. data/lib/sps_king/account/debtor_account.rb +1 -0
  12. data/lib/sps_king/account/debtor_address.rb +2 -31
  13. data/lib/sps_king/account.rb +3 -0
  14. data/lib/sps_king/converter.rb +14 -10
  15. data/lib/sps_king/message/credit_transfer.rb +120 -102
  16. data/lib/sps_king/message/direct_debit.rb +121 -118
  17. data/lib/sps_king/message.rb +54 -48
  18. data/lib/sps_king/structured_remittance_information.rb +3 -1
  19. data/lib/sps_king/transaction/credit_transfer_transaction.rb +3 -0
  20. data/lib/sps_king/transaction/direct_debit_transaction.rb +9 -6
  21. data/lib/sps_king/transaction.rb +10 -7
  22. data/lib/sps_king/validator.rb +9 -0
  23. data/lib/sps_king/version.rb +3 -1
  24. data/lib/sps_king.rb +1 -0
  25. data/spec/lib/sps_king/account/address_spec.rb +85 -0
  26. data/spec/lib/sps_king/account/creditor_account_spec.rb +14 -13
  27. data/spec/lib/sps_king/account/debtor_account_spec.rb +1 -0
  28. data/spec/lib/sps_king/account_spec.rb +12 -2
  29. data/spec/lib/sps_king/converter_spec.rb +25 -5
  30. data/spec/lib/sps_king/message/credit_transfer_spec.rb +205 -37
  31. data/spec/lib/sps_king/message/direct_debit_spec.rb +218 -102
  32. data/spec/lib/sps_king/message_spec.rb +23 -8
  33. data/spec/lib/sps_king/structured_remittance_information_spec.rb +8 -3
  34. data/spec/lib/sps_king/transaction/credit_transfer_transaction_spec.rb +14 -2
  35. data/spec/lib/sps_king/transaction/direct_debit_transaction_spec.rb +8 -7
  36. data/spec/lib/sps_king/transaction_spec.rb +62 -27
  37. data/spec/lib/sps_king/validator_spec.rb +38 -9
  38. data/spec/spec_helper.rb +8 -4
  39. data/spec/support/active_model.rb +3 -1
  40. data/spec/support/factories.rb +11 -10
  41. data/spec/support/validations.rb +2 -0
  42. data/sps_king.gemspec +1 -0
  43. metadata +8 -12
  44. data/spec/lib/sps_king/account/creditor_address_spec.rb +0 -14
  45. data/spec/lib/sps_king/account/debtor_address_spec.rb +0 -14
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe SPS::CreditTransfer do
@@ -171,11 +172,17 @@ describe SPS::CreditTransfer do
171
172
  end
172
173
 
173
174
  it 'should contain <PmtInfId>' do
174
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId', /#{message_id_regex}\/1/)
175
+ expect(subject).to have_xml(
176
+ '//Document/CstmrCdtTrfInitn/PmtInf/PmtInfId',
177
+ /#{message_id_regex}\/1/
178
+ )
175
179
  end
176
180
 
177
181
  it 'should contain <ReqdExctnDt>' do
178
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt', Date.new(1999, 1, 1).iso8601)
182
+ expect(subject).to have_xml(
183
+ '//Document/CstmrCdtTrfInitn/PmtInf/ReqdExctnDt',
184
+ Date.new(1999, 1, 1).iso8601
185
+ )
179
186
  end
180
187
 
181
188
  it 'should contain <PmtMtd>' do
@@ -195,45 +202,80 @@ describe SPS::CreditTransfer do
195
202
  end
196
203
 
197
204
  it 'should contain <Dbtr>' do
198
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/Dbtr/Nm', 'Schuldner GmbH')
205
+ expect(subject).to have_xml(
206
+ '//Document/CstmrCdtTrfInitn/PmtInf/Dbtr/Nm',
207
+ 'Schuldner GmbH'
208
+ )
199
209
  end
200
210
 
201
211
  it 'should contain <DbtrAcct>' do
202
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAcct/Id/IBAN', 'CH5481230000001998736')
212
+ expect(subject).to have_xml(
213
+ '//Document/CstmrCdtTrfInitn/PmtInf/DbtrAcct/Id/IBAN',
214
+ 'CH5481230000001998736'
215
+ )
203
216
  end
204
217
 
205
218
  it 'should contain <DbtrAgt>' do
206
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/DbtrAgt/FinInstnId/BIC', 'RAIFCH22')
219
+ expect(subject).to have_xml(
220
+ '//Document/CstmrCdtTrfInitn/PmtInf/DbtrAgt/FinInstnId/BIC',
221
+ 'RAIFCH22'
222
+ )
207
223
  end
208
224
 
209
225
  it 'should contain <EndToEndId>' do
210
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/EndToEndId', 'XYZ-1234/123')
211
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/PmtId/EndToEndId', 'XYZ-5678/456')
226
+ expect(subject).to have_xml(
227
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/EndToEndId', 'XYZ-1234/123'
228
+ )
229
+ expect(subject).to have_xml(
230
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/PmtId/EndToEndId', 'XYZ-5678/456'
231
+ )
212
232
  end
213
233
 
214
234
  it 'should contain <Amt>' do
215
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt', '102.50')
216
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Amt/InstdAmt', '59.00')
235
+ expect(subject).to have_xml(
236
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt', '102.50'
237
+ )
238
+ expect(subject).to have_xml(
239
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Amt/InstdAmt', '59.00'
240
+ )
217
241
  end
218
242
 
219
243
  it 'should contain <CdtrAgt> for every BIC given' do
220
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAgt/FinInstnId/BIC', 'CRESCHZZ80A')
221
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAgt/FinInstnId/BIC', 'RAIFCH22C32')
244
+ expect(subject).to have_xml(
245
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAgt/FinInstnId/BIC', 'CRESCHZZ80A'
246
+ )
247
+ expect(subject).to have_xml(
248
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAgt/FinInstnId/BIC', 'RAIFCH22C32'
249
+ )
222
250
  end
223
251
 
224
252
  it 'should contain <Cdtr>' do
225
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Cdtr/Nm', 'Contoso AG')
226
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Cdtr/Nm', 'Amazonas GmbH')
253
+ expect(subject).to have_xml(
254
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Cdtr/Nm',
255
+ 'Contoso AG'
256
+ )
257
+ expect(subject).to have_xml(
258
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/Cdtr/Nm',
259
+ 'Amazonas GmbH'
260
+ )
227
261
  end
228
262
 
229
263
  it 'should contain <CdtrAcct>' do
230
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAcct/Id/IBAN', 'CH9300762011623852957')
231
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAcct/Id/IBAN', 'CH7081232000001998736')
264
+ expect(subject).to have_xml(
265
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/CdtrAcct/Id/IBAN', 'CH9300762011623852957'
266
+ )
267
+ expect(subject).to have_xml(
268
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/CdtrAcct/Id/IBAN', 'CH7081232000001998736'
269
+ )
232
270
  end
233
271
 
234
272
  it 'should contain <RmtInf>' do
235
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Ustrd', 'Rechnung vom 22.08.2013')
236
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/RmtInf/Ustrd', 'Rechnung vom 21.08.2013')
273
+ expect(subject).to have_xml(
274
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Ustrd', 'Rechnung vom 22.08.2013'
275
+ )
276
+ expect(subject).to have_xml(
277
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[2]/RmtInf/Ustrd', 'Rechnung vom 21.08.2013'
278
+ )
237
279
  end
238
280
  end
239
281
 
@@ -249,15 +291,27 @@ describe SPS::CreditTransfer do
249
291
  end
250
292
 
251
293
  it 'should contain two payment_informations with <ReqdExctnDt>' do
252
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
253
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 2).iso8601)
294
+ expect(subject).to have_xml(
295
+ '//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt',
296
+ (Date.today + 1).iso8601
297
+ )
298
+ expect(subject).to have_xml(
299
+ '//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt',
300
+ (Date.today + 2).iso8601
301
+ )
254
302
 
255
303
  expect(subject).not_to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]')
256
304
  end
257
305
 
258
306
  it 'should contain two payment_informations with different <PmtInfId>' do
259
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId', /#{message_id_regex}\/1/)
260
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId', /#{message_id_regex}\/2/)
307
+ expect(subject).to have_xml(
308
+ '//Document/CstmrCdtTrfInitn/PmtInf[1]/PmtInfId',
309
+ /#{message_id_regex}\/1/
310
+ )
311
+ expect(subject).to have_xml(
312
+ '//Document/CstmrCdtTrfInitn/PmtInf[2]/PmtInfId',
313
+ /#{message_id_regex}\/2/
314
+ )
261
315
  end
262
316
  end
263
317
 
@@ -273,8 +327,6 @@ describe SPS::CreditTransfer do
273
327
  end
274
328
 
275
329
  it 'should contain payment_information with <ChrgBr>' do
276
- puts subject
277
-
278
330
  expect(subject)
279
331
  .to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ChrgBr', charge_bearer)
280
332
  end
@@ -305,30 +357,69 @@ describe SPS::CreditTransfer do
305
357
  subject do
306
358
  sct = credit_transfer
307
359
 
308
- sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 1, batch_booking: false, amount: 1)
309
- sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 1, batch_booking: true, amount: 2)
310
- sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2, batch_booking: false, amount: 4)
311
- sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2, batch_booking: true, amount: 8)
312
- sct.add_transaction(credit_transfer_transaction.merge requested_date: Date.today + 2, batch_booking: true, category_purpose: 'SALA', amount: 6)
360
+ sct.add_transaction(
361
+ credit_transfer_transaction.merge requested_date: Date.today + 1,
362
+ batch_booking: false,
363
+ amount: 1
364
+ )
365
+ sct.add_transaction(
366
+ credit_transfer_transaction.merge requested_date: Date.today + 1,
367
+ batch_booking: true,
368
+ amount: 2
369
+ )
370
+ sct.add_transaction(
371
+ credit_transfer_transaction.merge requested_date: Date.today + 2,
372
+ batch_booking: false,
373
+ amount: 4
374
+ )
375
+ sct.add_transaction(
376
+ credit_transfer_transaction.merge requested_date: Date.today + 2,
377
+ batch_booking: true,
378
+ amount: 8
379
+ )
380
+ sct.add_transaction(
381
+ credit_transfer_transaction.merge requested_date: Date.today + 2,
382
+ batch_booking: true,
383
+ category_purpose: 'SALA',
384
+ amount: 6
385
+ )
313
386
 
314
387
  sct.to_xml
315
388
  end
316
389
 
317
390
  it 'should contain multiple payment_informations' do
318
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt', (Date.today + 1).iso8601)
391
+ expect(subject).to have_xml(
392
+ '//Document/CstmrCdtTrfInitn/PmtInf[1]/ReqdExctnDt',
393
+ (Date.today + 1).iso8601
394
+ )
319
395
  expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/BtchBookg', 'false')
320
396
 
321
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt', (Date.today + 1).iso8601)
397
+ expect(subject).to have_xml(
398
+ '//Document/CstmrCdtTrfInitn/PmtInf[2]/ReqdExctnDt',
399
+ (Date.today + 1).iso8601
400
+ )
322
401
  expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[2]/BtchBookg', 'true')
323
402
 
324
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/ReqdExctnDt', (Date.today + 2).iso8601)
403
+ expect(subject).to have_xml(
404
+ '//Document/CstmrCdtTrfInitn/PmtInf[3]/ReqdExctnDt',
405
+ (Date.today + 2).iso8601
406
+ )
325
407
  expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[3]/BtchBookg', 'false')
326
408
 
327
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/ReqdExctnDt', (Date.today + 2).iso8601)
409
+ expect(subject).to have_xml(
410
+ '//Document/CstmrCdtTrfInitn/PmtInf[4]/ReqdExctnDt',
411
+ (Date.today + 2).iso8601
412
+ )
328
413
  expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[4]/BtchBookg', 'true')
329
414
 
330
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[5]/ReqdExctnDt', (Date.today + 2).iso8601)
331
- expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[5]/PmtTpInf/CtgyPurp/Cd', 'SALA')
415
+ expect(subject).to have_xml(
416
+ '//Document/CstmrCdtTrfInitn/PmtInf[5]/ReqdExctnDt',
417
+ (Date.today + 2).iso8601
418
+ )
419
+ expect(subject).to have_xml(
420
+ '//Document/CstmrCdtTrfInitn/PmtInf[5]/PmtTpInf/CtgyPurp/Cd',
421
+ 'SALA'
422
+ )
332
423
  end
333
424
 
334
425
  it 'should have multiple control sums' do
@@ -361,11 +452,88 @@ describe SPS::CreditTransfer do
361
452
  it 'should contain <InstrId>' do
362
453
  expect(subject)
363
454
  .to have_xml(
364
- '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/InstrId',
365
- '1234/ABC'
366
- )
455
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/InstrId',
456
+ '1234/ABC'
457
+ )
458
+ end
459
+ end
460
+
461
+ context 'with structured remittance information given' do
462
+ subject do
463
+ sct = credit_transfer
464
+
465
+ sct.add_transaction(
466
+ name: 'Contoso AG',
467
+ iban: 'CH5481230000001998736',
468
+ bic: 'RAIFCH22',
469
+ amount: 102.50,
470
+ structured_remittance_information: SPS::StructuredRemittanceInformation.new(
471
+ proprietary: 'QRR',
472
+ reference: '185744810000000000200800628'
473
+ )
474
+ )
475
+
476
+ sct.to_xml
477
+ end
478
+
479
+ it 'should create valid XML file' do
480
+ expect(subject).to validate_against('pain.001.001.03.ch.02.xsd')
481
+ end
482
+
483
+ it 'should contain <Prtry>' do
484
+ expect(subject)
485
+ .to have_xml(
486
+ '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Strd/CdtrRefInf/Tp/CdOrPrtry/Prtry',
487
+ 'QRR'
488
+ )
367
489
  end
368
490
  end
369
491
  end
492
+
493
+ context 'with no encoding specified' do
494
+ subject do
495
+ sct = credit_transfer
496
+
497
+ sct.add_transaction(
498
+ name: 'Contoso AG',
499
+ bic: 'CRESCHZZ80A',
500
+ iban: 'CH9300762011623852957',
501
+ service_level: 'SEPA',
502
+ amount: 102.50,
503
+ reference: 'XYZ-1234/123',
504
+ remittance_information: 'Rechnung vom 22.08.2013'
505
+ )
506
+
507
+ sct.to_xml(SPS::PAIN_001_001_03_CH_02)
508
+ end
509
+
510
+ it 'should include encoding in the xml string' do
511
+ expect(subject).to include('encoding')
512
+ expect(subject).to include('UTF-8')
513
+ end
514
+ end
515
+
516
+ context 'with encoding specified' do
517
+ subject do
518
+ sct = credit_transfer
519
+
520
+ sct.add_transaction(
521
+ name: 'Contoso AG',
522
+ bic: 'CRESCHZZ80A',
523
+ iban: 'CH9300762011623852957',
524
+ service_level: 'SEPA',
525
+ amount: 102.50,
526
+ reference: 'XYZ-1234/123',
527
+ remittance_information: 'Rechnung vom 22.08.2013'
528
+ )
529
+
530
+ sct.to_xml(SPS::PAIN_001_001_03_CH_02, 'ISO-8859-8')
531
+ end
532
+
533
+ it 'should include encoding in the xml string' do
534
+ expect(subject).to include('encoding')
535
+ expect(subject).to include('ISO-8859-8')
536
+ end
537
+ end
370
538
  end
371
539
  end