Skip to content

Commit 3a3f0b9

Browse files
committed
add sepa_direct_debit (direct_debit_mandate_reference_id, :direct_debit_creditor_id, direct_debit_iban - BT-89, BT-90, BT-91)
1 parent 186306b commit 3a3f0b9

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

lib/secretariat/constants.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ module Secretariat
5353
:DEBITADVICE => "31",
5454
:CREDITCARD => "48",
5555
:DEBIT => "49",
56+
:CREDITTRANSFER => "54",
57+
:DIRECTDEBIT => "55",
58+
:SEPACREDITTRANSFER => "58",
59+
:SEPADIRECTDEBIT => "59",
5660
:COMPENSATION => "97"
5761
}
5862

lib/secretariat/invoice.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ module Secretariat
4848
:tax_calculation_method,
4949
:notes,
5050
:attachments,
51+
:direct_debit_mandate_reference_id, # BT-89
52+
:direct_debit_creditor_id, # BT-90
53+
:direct_debit_iban, # BT-91
5154
keyword_init: true
5255
) do
5356

@@ -260,6 +263,9 @@ def to_xml(version: 1, validate: true)
260263
end
261264
trade_settlement = by_version(version, 'ApplicableSupplyChainTradeSettlement', 'ApplicableHeaderTradeSettlement')
262265
xml['ram'].send(trade_settlement) do
266+
if direct_debit_creditor_id
267+
xml['ram'].CreditorReferenceID direct_debit_creditor_id # BT-90
268+
end
263269
if payment_reference.present?
264270
xml['ram'].PaymentReference payment_reference
265271
end
@@ -278,6 +284,11 @@ def to_xml(version: 1, validate: true)
278284
xml['ram'].BICID payment_bic
279285
end
280286
end
287+
if direct_debit_iban
288+
xml['ram'].PayerPartyDebtorFinancialAccount do
289+
xml['ram'].IBANID direct_debit_iban
290+
end
291+
end
281292
end
282293
taxes.each do |tax|
283294
xml['ram'].ApplicableTradeTax do
@@ -311,6 +322,9 @@ def to_xml(version: 1, validate: true)
311322
Helpers.date_element(xml, payment_due_date)
312323
end
313324
end
325+
if direct_debit_mandate_reference_id
326+
xml['ram'].DirectDebitMandateID direct_debit_mandate_reference_id
327+
end
314328
end
315329

316330
monetary_summation = by_version(version, 'SpecifiedTradeSettlementMonetarySummation', 'SpecifiedTradeSettlementHeaderMonetarySummation')

test/invoice_test.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,64 @@ def make_eu_invoice(tax_category: :REVERSECHARGE)
5757
)
5858
end
5959

60+
def make_eu_invoice_with_sepa_direct_debit(tax_category: :REVERSECHARGE)
61+
seller = TradeParty.new(
62+
name: 'Depfu inc',
63+
street1: 'Quickbornstr. 46',
64+
city: 'Hamburg',
65+
postal_code: '20253',
66+
country_id: 'DE',
67+
vat_id: 'DE304755032'
68+
)
69+
buyer = TradeParty.new(
70+
name: 'Depfu inc',
71+
street1: 'Quickbornstr. 46',
72+
city: 'Hamburg',
73+
postal_code: '20253',
74+
country_id: 'SE',
75+
vat_id: 'SE304755032'
76+
)
77+
line_item = LineItem.new(
78+
name: 'Depfu Premium Plan',
79+
quantity: 1,
80+
gross_amount: BigDecimal('29'),
81+
net_amount: BigDecimal('29'),
82+
unit: :YEAR,
83+
charge_amount: BigDecimal('29'),
84+
tax_category: tax_category,
85+
tax_percent: 0,
86+
tax_amount: 0,
87+
origin_country_code: 'DE',
88+
currency_code: 'EUR',
89+
service_period_start: Date.today,
90+
service_period_end: Date.today + 364,
91+
)
92+
Invoice.new(
93+
id: '12345',
94+
issue_date: Date.today,
95+
# service_period on line_item. removed here to simplify testing of BillingSpecifiedPeriod presence
96+
# service_period_start: Date.today,
97+
# service_period_end: Date.today + 30,
98+
seller: seller,
99+
buyer: buyer,
100+
line_items: [line_item],
101+
currency_code: 'USD',
102+
payment_type: :CREDITCARD,
103+
payment_text: 'Kreditkarte',
104+
tax_category: tax_category,
105+
tax_amount: 0,
106+
basis_amount: BigDecimal('29'),
107+
grand_total_amount: BigDecimal('29'),
108+
due_amount: 0,
109+
paid_amount: 29,
110+
payment_due_date: Date.today + 14,
111+
notes: "This is a test invoice",
112+
direct_debit_mandate_reference_id: "MANDATE REFERENCE", # BT-89
113+
direct_debit_creditor_id: "DE98ZZZ09999999999", # BT-90
114+
direct_debit_iban: "DE02120300000000202051", # BT-91
115+
)
116+
end
117+
60118
def make_foreign_invoice(tax_category: :TAXEXEMPT)
61119
seller = TradeParty.new(
62120
name: 'Depfu inc',
@@ -381,6 +439,30 @@ def test_simple_eu_invoice_v2
381439
puts e.errors
382440
end
383441

442+
def test_simple_eu_invoice_v2_with_sepa_direct_debit
443+
begin
444+
xml = make_eu_invoice_with_sepa_direct_debit.to_xml(version: 2)
445+
rescue ValidationError => e
446+
pp e.errors
447+
end
448+
449+
assert_match(%r{<ram:CreditorReferenceID>DE98ZZZ09999999999</ram:CreditorReferenceID>}, xml)
450+
assert_match(%r{<ram:PayerPartyDebtorFinancialAccount>\s*<ram:IBANID>DE02120300000000202051\s*</ram:IBANID>}, xml)
451+
assert_match(%r{<ram:DirectDebitMandateID>MANDATE REFERENCE</ram:DirectDebitMandateID>}, xml)
452+
453+
v = Validator.new(xml, version: 2)
454+
errors = v.validate_against_schema
455+
if !errors.empty?
456+
puts xml
457+
errors.each do |error|
458+
puts error
459+
end
460+
end
461+
assert_equal [], errors
462+
rescue ValidationError => e
463+
puts e.errors
464+
end
465+
384466
def test_simple_foreign_invoice_v2_taxexpempt
385467
begin
386468
xml = make_foreign_invoice(tax_category: :TAXEXEMPT).to_xml(version: 2)

0 commit comments

Comments
 (0)