Skip to content

Commit

Permalink
Allow empty debtor BIC for pain.001.001.03 credit transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
A1bi committed Jul 22, 2022
1 parent 70b0475 commit 18c3d1f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/sepa_king/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def to_xml(schema_name=self.known_schemas.first)
builder.Document(xml_schema(schema_name)) do
builder.__send__(xml_main_tag) do
build_group_header(builder)
build_payment_informations(builder)
build_payment_informations(builder, schema_name)
end
end
end
Expand All @@ -63,9 +63,9 @@ def schema_compatible?(schema_name)
raise ArgumentError.new("Schema #{schema_name} is unknown!") unless self.known_schemas.include?(schema_name)

case schema_name
when PAIN_001_002_03, PAIN_008_002_02, PAIN_001_001_03, PAIN_001_001_03_CH_02
when PAIN_001_002_03, PAIN_008_002_02
account.bic.present? && transactions.all? { |t| t.schema_compatible?(schema_name) }
when PAIN_001_003_03, PAIN_008_003_02, PAIN_008_001_02
when PAIN_001_001_03, PAIN_001_001_03_CH_02, PAIN_001_003_03, PAIN_008_003_02, PAIN_008_001_02
transactions.all? { |t| t.schema_compatible?(schema_name) }
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sepa_king/message/credit_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def transaction_group(transaction)
}
end

def build_payment_informations(builder)
def build_payment_informations(builder, schema_name)
# Build a PmtInf block for every group of transactions
grouped_transactions.each do |group, transactions|
# All transactions with the same requested_date are placed into the same PmtInf block
Expand Down Expand Up @@ -52,7 +52,7 @@ def build_payment_informations(builder)
builder.FinInstnId do
if account.bic
builder.BIC(account.bic)
else
elsif schema_name != PAIN_001_001_03_CH_02
builder.Othr do
builder.Id('NOTPROVIDED')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sepa_king/message/direct_debit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def transaction_group(transaction)
}
end

def build_payment_informations(builder)
def build_payment_informations(builder, schema_name)
# Build a PmtInf block for every group of transactions
grouped_transactions.each do |group, transactions|
builder.PmtInf do
Expand Down
19 changes: 14 additions & 5 deletions spec/credit_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,29 @@
bic: 'PBNKDEFF370',
iban: 'DE37112589611964645802',
amount: 102.50,
currency: currency,
reference: 'XYZ-1234/123',
remittance_information: 'Rechnung vom 22.08.2013'

sct
end

it 'should create valid XML file' do
let(:currency) { nil }

it 'should validate against pain.001.003.03' do
expect(subject.to_xml(SEPA::PAIN_001_003_03)).to validate_against('pain.001.003.03.xsd')
end

it 'should fail for pain.001.001.03' do
expect {
subject.to_xml(SEPA::PAIN_001_001_03)
}.to raise_error(SEPA::Error, /Incompatible with schema/)
it 'should validate against pain.001.001.03' do
expect(subject.to_xml(SEPA::PAIN_001_001_03)).to validate_against('pain.001.001.03.xsd')
end

context 'with CHF as currency' do
let(:currency) { 'CHF' }

it 'should validate against pain.001.001.03.ch.02' do
expect(subject.to_xml(SEPA::PAIN_001_001_03_CH_02)).to validate_against('pain.001.001.03.ch.02.xsd')
end
end

it 'should fail for pain.001.002.03' do
Expand Down

0 comments on commit 18c3d1f

Please sign in to comment.