@@ -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