Skip to content

Commit 698c3dd

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 698c3dd

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-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: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,119 @@ def make_eu_invoice(tax_category: :REVERSECHARGE)
5757
)
5858
end
5959

60+
def make_eu_invoice_with_line_item_billing_period(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+
)
113+
end
114+
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+
end
172+
60173
def make_foreign_invoice(tax_category: :TAXEXEMPT)
61174
seller = TradeParty.new(
62175
name: 'Depfu inc',
@@ -381,6 +494,31 @@ def test_simple_eu_invoice_v2
381494
puts e.errors
382495
end
383496

497+
def test_simple_eu_invoice_v2_with_line_item_billing_period
498+
begin
499+
xml = make_eu_invoice_with_line_item_billing_period.to_xml(version: 2)
500+
rescue ValidationError => e
501+
pp e.errors
502+
end
503+
504+
assert_match(/<ram:CategoryCode>AE<\/ram:CategoryCode>/, xml)
505+
assert_match(/<ram:ExemptionReason>Reverse Charge<\/ram:ExemptionReason>/, xml)
506+
assert_match(/<ram:RateApplicablePercent>/, xml)
507+
assert_match(/<ram:BillingSpecifiedPeriod>/, xml)
508+
509+
v = Validator.new(xml, version: 2)
510+
errors = v.validate_against_schema
511+
if !errors.empty?
512+
puts xml
513+
errors.each do |error|
514+
puts error
515+
end
516+
end
517+
assert_equal [], errors
518+
rescue ValidationError => e
519+
puts e.errors
520+
end
521+
384522
def test_simple_foreign_invoice_v2_taxexpempt
385523
begin
386524
xml = make_foreign_invoice(tax_category: :TAXEXEMPT).to_xml(version: 2)

0 commit comments

Comments
 (0)