Skip to content

Commit 5167709

Browse files
ronaldhalfbyte
authored andcommitted
add sepa_direct_debit (direct_debit_mandate_reference_id, :direct_debit_creditor_id, direct_debit_iban - BT-89, BT-90, BT-91)
1 parent ec4957e commit 5167709

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
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: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,65 @@ def make_eu_invoice_with_line_item_billing_period(tax_category: :REVERSECHARGE)
112112
)
113113
end
114114

115+
def make_eu_invoice_with_sepa_direct_debit(tax_category: :REVERSECHARGE)
116+
seller = TradeParty.new(
117+
name: 'Depfu inc',
118+
street1: 'Quickbornstr. 46',
119+
city: 'Hamburg',
120+
postal_code: '20253',
121+
country_id: 'DE',
122+
vat_id: 'DE304755032'
123+
)
124+
buyer = TradeParty.new(
125+
name: 'Depfu inc',
126+
street1: 'Quickbornstr. 46',
127+
city: 'Hamburg',
128+
postal_code: '20253',
129+
country_id: 'SE',
130+
vat_id: 'SE304755032'
131+
)
132+
line_item = LineItem.new(
133+
name: 'Depfu Premium Plan',
134+
quantity: 1,
135+
gross_amount: BigDecimal('29'),
136+
net_amount: BigDecimal('29'),
137+
unit: :YEAR,
138+
charge_amount: BigDecimal('29'),
139+
tax_category: tax_category,
140+
tax_percent: 0,
141+
tax_amount: 0,
142+
origin_country_code: 'DE',
143+
currency_code: 'EUR',
144+
service_period_start: Date.today,
145+
service_period_end: Date.today + 364,
146+
)
147+
Invoice.new(
148+
id: '12345',
149+
issue_date: Date.today,
150+
# service_period on line_item. removed here to simplify testing of BillingSpecifiedPeriod presence
151+
# service_period_start: Date.today,
152+
# service_period_end: Date.today + 30,
153+
seller: seller,
154+
buyer: buyer,
155+
line_items: [line_item],
156+
currency_code: 'USD',
157+
payment_type: :CREDITCARD,
158+
payment_text: 'Kreditkarte',
159+
tax_category: tax_category,
160+
tax_amount: 0,
161+
basis_amount: BigDecimal('29'),
162+
grand_total_amount: BigDecimal('29'),
163+
due_amount: 0,
164+
paid_amount: 29,
165+
payment_due_date: Date.today + 14,
166+
notes: "This is a test invoice",
167+
direct_debit_mandate_reference_id: "MANDATE REFERENCE", # BT-89
168+
direct_debit_creditor_id: "DE98ZZZ09999999999", # BT-90
169+
direct_debit_iban: "DE02120300000000202051", # BT-91
170+
171+
)
172+
end
173+
115174
def make_foreign_invoice(tax_category: :TAXEXEMPT)
116175
seller = TradeParty.new(
117176
name: 'Depfu inc',
@@ -439,15 +498,36 @@ def test_simple_eu_invoice_v2
439498
def test_simple_eu_invoice_v2_with_line_item_billing_period
440499
begin
441500
xml = make_eu_invoice_with_line_item_billing_period.to_xml(version: 2)
501+
assert_match(/<ram:CategoryCode>AE<\/ram:CategoryCode>/, xml)
502+
assert_match(/<ram:ExemptionReason>Reverse Charge<\/ram:ExemptionReason>/, xml)
503+
assert_match(/<ram:RateApplicablePercent>/, xml)
504+
assert_match(/<ram:BillingSpecifiedPeriod>/, xml)
442505
rescue ValidationError => e
443506
pp e.errors
444507
end
508+
v = Validator.new(xml, version: 2)
509+
errors = v.validate_against_schema
510+
if !errors.empty?
511+
puts xml
512+
errors.each do |error|
513+
puts error
514+
end
515+
end
516+
assert_equal [], errors
517+
rescue ValidationError => e
518+
puts e.errors
519+
end
445520

446-
assert_match(/<ram:CategoryCode>AE<\/ram:CategoryCode>/, xml)
447-
assert_match(/<ram:ExemptionReason>Reverse Charge<\/ram:ExemptionReason>/, xml)
448-
assert_match(/<ram:RateApplicablePercent>/, xml)
449-
assert_match(/<ram:BillingSpecifiedPeriod>/, xml)
521+
def test_simple_eu_invoice_v2_with_sepa_direct_debit
522+
begin
523+
xml = make_eu_invoice_with_sepa_direct_debit.to_xml(version: 2)
524+
assert_match(%r{<ram:CreditorReferenceID>DE98ZZZ09999999999</ram:CreditorReferenceID>}, xml)
525+
assert_match(%r{<ram:PayerPartyDebtorFinancialAccount>\s*<ram:IBANID>DE02120300000000202051\s*</ram:IBANID>}, xml)
526+
assert_match(%r{<ram:DirectDebitMandateID>MANDATE REFERENCE</ram:DirectDebitMandateID>}, xml)
450527

528+
rescue ValidationError => e
529+
pp e.errors
530+
end
451531
v = Validator.new(xml, version: 2)
452532
errors = v.validate_against_schema
453533
if !errors.empty?

0 commit comments

Comments
 (0)