Skip to content

Commit

Permalink
Merge pull request #10 from viafintech/feature/qrr-support
Browse files Browse the repository at this point in the history
Add support for QRR type in structured remittance information
  • Loading branch information
tobischo authored Aug 3, 2024
2 parents 2f41ed4 + 9999e86 commit b26b7fa
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 17 additions & 2 deletions lib/sps_king/message/credit_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sps_king/structured_remittance_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sps_king/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SPS
VERSION = '0.4.0'
VERSION = '0.5.0'
end
33 changes: 31 additions & 2 deletions spec/lib/sps_king/message/credit_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@
end

it 'should contain payment_information with <ChrgBr>' do
puts subject

expect(subject)
.to have_xml('//Document/CstmrCdtTrfInitn/PmtInf[1]/ChrgBr', charge_bearer)
end
Expand Down Expand Up @@ -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 <Prtry>' do
expect(subject)
.to have_xml(
'//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/RmtInf/Strd/CdtrRefInf/Tp/CdOrPrtry/Prtry',
'QRR'
)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b26b7fa

Please sign in to comment.