Skip to content

Commit a8e54f8

Browse files
author
Tobias Schoknecht
committed
Allow setting initiating party
1 parent 1cfbb15 commit a8e54f8

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/sepa_king/account.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Account
44
include ActiveModel::Validations
55
extend Converter
66

7-
attr_accessor :name, :iban, :bic
7+
attr_accessor :name, :iban, :bic, :initiating_party
88
convert :name, to: :text
99

1010
validates_length_of :name, within: 1..70

lib/sepa_king/message.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ def xml_schema(schema_name)
134134
end
135135

136136
def build_group_header(builder)
137+
other_id = nil
138+
if account.respond_to?(:creditor_identifier)
139+
other_id = account.creditor_identifier
140+
end
141+
142+
if account.initiating_party != nil
143+
other_id = account.initiating_party
144+
end
145+
137146
builder.GrpHdr do
138147
builder.MsgId(message_identification)
139148
builder.CreDtTm(creation_date_time)
@@ -144,10 +153,10 @@ def build_group_header(builder)
144153
builder.Id do
145154
builder.OrgId do
146155
builder.Othr do
147-
builder.Id(account.creditor_identifier)
156+
builder.Id(other_id)
148157
end
149158
end
150-
end if account.respond_to? :creditor_identifier
159+
end if other_id
151160
end
152161
end
153162
end

spec/direct_debit_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@
263263
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/GrpHdr/InitgPty/Id/OrgId/Othr/Id', direct_debit.account.creditor_identifier)
264264
end
265265

266+
context 'when initiating party is set' do
267+
let(:direct_debit) do
268+
SEPA::DirectDebit.new name: 'Gläubiger GmbH',
269+
bic: 'BANKDEFFXXX',
270+
iban: 'DE87200500001234567890',
271+
creditor_identifier: 'DE98ZZZ09999999999',
272+
initiating_party: 'EXAMPLE1'
273+
end
274+
275+
it 'should have initiating party' do
276+
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/GrpHdr/InitgPty/Id/OrgId/Othr/Id', direct_debit.account.initiating_party)
277+
end
278+
end
279+
266280
it 'should contain <PmtInfId>' do
267281
expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/PmtInfId', /#{message_id_regex}\/1/)
268282
end

0 commit comments

Comments
 (0)