From 67009889b5678d81bbe81881a34738a0db2b0ce9 Mon Sep 17 00:00:00 2001 From: Tobias Schoknecht Date: Wed, 31 Jul 2024 16:12:02 +0200 Subject: [PATCH 1/4] Add support for QRR as value for proprietary --- lib/sps_king/structured_remittance_information.rb | 2 +- spec/lib/sps_king/structured_remittance_information_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sps_king/structured_remittance_information.rb b/lib/sps_king/structured_remittance_information.rb index c86ace2..6648045 100644 --- a/lib/sps_king/structured_remittance_information.rb +++ b/lib/sps_king/structured_remittance_information.rb @@ -6,7 +6,7 @@ class StructuredRemittanceInformation attr_accessor :proprietary, :reference - validates_inclusion_of :proprietary, in: %w(ESR IPI) + validates_inclusion_of :proprietary, in: %w(ESR IPI QRR) validates_length_of :reference, within: 1..35 convert :proprietary, :reference, to: :text diff --git a/spec/lib/sps_king/structured_remittance_information_spec.rb b/spec/lib/sps_king/structured_remittance_information_spec.rb index 33e90c7..ebe7925 100644 --- a/spec/lib/sps_king/structured_remittance_information_spec.rb +++ b/spec/lib/sps_king/structured_remittance_information_spec.rb @@ -12,7 +12,7 @@ describe :proprietary do it 'should accept valid value' do - expect(SPS::StructuredRemittanceInformation).to accept('ESR', 'IPI', for: :proprietary) + expect(SPS::StructuredRemittanceInformation).to accept('ESR', 'IPI', 'QRR', for: :proprietary) end it 'should not accept invalid value' do From b77bdf0360215e805be364f547c5159028f7c2f0 Mon Sep 17 00:00:00 2001 From: Tobias Schoknecht Date: Wed, 31 Jul 2024 16:12:37 +0200 Subject: [PATCH 2/4] Bump version --- lib/sps_king/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sps_king/version.rb b/lib/sps_king/version.rb index 54d66f4..29b5cc2 100644 --- a/lib/sps_king/version.rb +++ b/lib/sps_king/version.rb @@ -1,3 +1,3 @@ module SPS - VERSION = '0.4.0' + VERSION = '0.4.1' end From 2845184e8e3d2322b474cf170f2499f1a191c528 Mon Sep 17 00:00:00 2001 From: Tobias Schoknecht Date: Wed, 31 Jul 2024 17:00:01 +0200 Subject: [PATCH 3/4] Allow structured remittance information optionally for credits --- README.md | 13 ++++++++ lib/sps_king/message/credit_transfer.rb | 19 +++++++++-- .../sps_king/message/credit_transfer_spec.rb | 33 +++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ada99ef..f635bd3 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,19 @@ sct.add_transaction( # String, max. 140 char remittance_information: 'Rechnung vom 22.08.2013', + # OPTIONAL: Structured remittance information, in German "Strukturierter Verwendungszweck". Required for e.g. Swiss QR transfers + # StructuredRemittanceInformation + structured_remittance_information: SPS::StructuredRemittanceInformation.new( + # Defines how the reference field should be interpreted for Swiss Direct Debits + # One of these strings: + # 'IPI' ("IPI-Verwendungszweck") + # 'QRR' ("QR-Referenz") + proprietary: 'QRR', + # if proprietary is 'IPI': 20 character IPI remittance + # if proprietary is 'QRR': 27 character QR reference + reference: '000008207791225857421286694' + ), + # OPTIONAL: Requested execution date, in German "Ausführungstermin" # Date requested_date: Date.new(2013,9,5), diff --git a/lib/sps_king/message/credit_transfer.rb b/lib/sps_king/message/credit_transfer.rb index ef04cf6..bb6d4e7 100644 --- a/lib/sps_king/message/credit_transfer.rb +++ b/lib/sps_king/message/credit_transfer.rb @@ -132,9 +132,24 @@ def build_transaction(builder, transaction) builder.IBAN(transaction.iban) end end - if transaction.remittance_information + if transaction.remittance_information || transaction.structured_remittance_information builder.RmtInf do - builder.Ustrd(transaction.remittance_information) + if transaction.remittance_information + builder.Ustrd(transaction.remittance_information) + end + + if transaction.structured_remittance_information + builder.Strd do + builder.CdtrRefInf do + builder.Tp do + builder.CdOrPrtry do + builder.Prtry(transaction.structured_remittance_information.proprietary) + end + end + builder.Ref(transaction.structured_remittance_information.reference) + end + end + end end end end diff --git a/spec/lib/sps_king/message/credit_transfer_spec.rb b/spec/lib/sps_king/message/credit_transfer_spec.rb index bb211e0..b074f5d 100644 --- a/spec/lib/sps_king/message/credit_transfer_spec.rb +++ b/spec/lib/sps_king/message/credit_transfer_spec.rb @@ -273,8 +273,6 @@ end it 'should contain payment_information with ' do - puts subject - expect(subject) .to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ChrgBr', charge_bearer) end @@ -366,6 +364,37 @@ ) end end + + context 'with structured remittance information given' do + subject do + sct = credit_transfer + + sct.add_transaction( + name: 'Contoso AG', + iban: 'CH5481230000001998736', + bic: 'RAIFCH22', + amount: 102.50, + structured_remittance_information: SPS::StructuredRemittanceInformation.new( + proprietary: 'QRR', + reference: '185744810000000000200800628' + ) + ) + + sct.to_xml + end + + it 'should create valid XML file' do + expect(subject).to validate_against('pain.001.001.03.ch.02.xsd') + end + + it 'should contain ' do + expect(subject) + .to have_xml( + '//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Strd/CdtrRefInf/Tp/CdOrPrtry/Prtry', + 'QRR' + ) + end + end end end end From 9999e86702307cca11244015ce59d4de322118d1 Mon Sep 17 00:00:00 2001 From: Tobias Schoknecht Date: Sat, 3 Aug 2024 09:30:54 +0200 Subject: [PATCH 4/4] Bump version to 0.5.0 --- lib/sps_king/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sps_king/version.rb b/lib/sps_king/version.rb index 29b5cc2..23b22c3 100644 --- a/lib/sps_king/version.rb +++ b/lib/sps_king/version.rb @@ -1,3 +1,3 @@ module SPS - VERSION = '0.4.1' + VERSION = '0.5.0' end