From 9753cee0d1f673d982f408b74fbe0666f13fa747 Mon Sep 17 00:00:00 2001 From: raj deenoo Date: Wed, 29 May 2024 09:12:31 +0200 Subject: [PATCH 1/3] halley-926 special char xml sepa --- lib/misc/epc_mapping.csv | 403 +++++++++++++++++++++++++++++++++++++ lib/sepa_king/converter.rb | 28 +-- spec/converter_spec.rb | 17 +- spec/direct_debit_spec.rb | 10 +- spec/transaction_spec.rb | 6 +- 5 files changed, 429 insertions(+), 35 deletions(-) create mode 100644 lib/misc/epc_mapping.csv diff --git a/lib/misc/epc_mapping.csv b/lib/misc/epc_mapping.csv new file mode 100644 index 0000000..13f6266 --- /dev/null +++ b/lib/misc/epc_mapping.csv @@ -0,0 +1,403 @@ +" "," " +&,+ +@,(at) +',' +""""," +;,"," +(,( +),) ++,+ +-,- +/,/ +0,0 +1,1 +2,2 +3,3 +4,4 +5,5 +6,6 +7,7 +8,8 +9,9 +:,: +",","," +<,< +>,> +?,? +A,A +B,B +C,C +D,D +E,E +F,F +G,G +H,H +I,I +J,J +K,K +L,L +M,M +N,N +O,O +P,P +Q,Q +R,R +S,S +T,T +U,U +V,V +W,W +X,X +Y,Y +Z,Z +[,( +\,/ +],) +_,- +`,' +a,a +b,b +c,c +d,d +e,e +f,f +g,g +h,h +i,i +j,j +k,k +l,l +m,m +n,n +o,o +p,p +q,q +r,r +s,s +t,t +u,u +v,v +w,w +x,x +y,y +z,z +{,( +|,/ +},) +~,- +¿,? +À,A +Á,A +Â,A +Ã,A +Ä,A +Å,A +Æ,A +Ç,C +È,E +É,E +Ê,E +Ë,E +Ì,I +Í,I +Î,I +Ï,I +Ð,D +Ñ,N +Ò,O +Ó,O +Ô,O +Õ,O +Ö,O +Ø,O +Ù,U +Ú,U +Û,U +Ü,U +Ý,Y +Þ,T +ß,s +à,a +á,a +â,a +ã,a +ä,a +å,a +æ,a +ç,c +è,e +é,e +ê,e +ë,e +ì,i +í,i +î,i +ï,i +ð,d +ñ,n +ò,o +ó,o +ô,o +õ,o +ö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y +ά,a +έ,e +ή,i +ί,i +ΰ,y +α,a +β,v +γ,g +δ,d +ε,e +ζ,z +η,i +θ,th +ι,i +κ,k +λ,l +μ,m +ν,n +ξ,x +ο,o +π,p +ρ,r +ς,s +σ,s +τ,t +υ,y +φ,f +χ,ch +ψ,ps +ω,o +ϊ,i +ϋ,y +ό,o +ύ,y +ώ,o +А,A +Б,B +В,V +Г,G +Д,D +Е,E +Ж,ZH +З,Z +И,I +Й,Y +К,K +Л,L +М,M +Н,N +О,O +П,P +Р,R +С,S +Т,T +У,U +Ф,F +Х,H +Ц,TS +Ч,CH +Ш,SH +Щ,SHT +Ъ,A +Ь,Y +Ю,YU +Я,YA +а,a +б,b +в,v +г,g +д,d +е,e +ж,zh +з,z +и,i +й,y +к,k +л,l +м,m +н,n +о,o +п,p +р,r +с,s +т,t +у,u +ф,f +х,h +ц,ts +ч,ch +ш,sh +щ,sht +ъ,a +ь,y +ю,yu +я,ya +€,E diff --git a/lib/sepa_king/converter.rb b/lib/sepa_king/converter.rb index 4141964..a97df03 100644 --- a/lib/sepa_king/converter.rb +++ b/lib/sepa_king/converter.rb @@ -15,24 +15,24 @@ def convert(*attributes, options) end module InstanceMethods - def convert_text(value) - return unless value + require 'csv' - value.to_s. - # Replace some special characters described as "Best practices" in Chapter 6.2 of this document: - # http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requirements-for-an-extended-character-set-unicode-subset-best-practices/ - gsub('€','E'). - gsub('@','(at)'). - gsub('_','-'). + # ‘.’, a full stop (U+002E) denotes that there is no restricted character + # set equivalent and hence a full stop is to be used. + FALLBACK_EPC_CHAR = '.'.freeze + private_constant :FALLBACK_EPC_CHAR - # Replace linebreaks by spaces - gsub(/\n+/,' '). + EPC_MAPPING = CSV.read("lib/misc/epc_mapping.csv", col_sep: ","). + each_with_object(Hash.new(FALLBACK_EPC_CHAR)) { |v, mappings| mappings[v.first] = v.last }. + freeze + private_constant :EPC_MAPPING - # Remove all invalid characters - gsub(/[^a-zA-Z0-9ÄÖÜäöüß&*$%\ \'\:\?\,\-\(\+\.\)\/]/, ''). + def convert_text(value) + return value unless value.present? - # Remove leading and trailing spaces - strip + # Map chars according to: + # http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requirements-for-an-extended-character-set-unicode-subset-best-practices/ + value.to_s.gsub(/\n+/,' ').each_char.map { |c| EPC_MAPPING[c] }.join.strip end def convert_decimal(value) diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb index ba00471..24fe717 100644 --- a/spec/converter_spec.rb +++ b/spec/converter_spec.rb @@ -5,15 +5,14 @@ include SEPA::Converter::InstanceMethods describe :convert_text do - it 'should convert special chars' do + it 'should map characters to the SEPA Requirements for an Extended Character Set' do expect(convert_text('10€')).to eq('10E') expect(convert_text('info@bundesbank.de')).to eq('info(at)bundesbank.de') expect(convert_text('abc_def')).to eq('abc-def') - end - - it 'should not change allowed special character' do - expect(convert_text('üöäÜÖÄß')).to eq('üöäÜÖÄß') - expect(convert_text('&*$%')).to eq('&*$%') + expect(convert_text('"=<>!')).to eq('".<>.') + expect(convert_text('ЖЩθĚŠũΦ')).to eq('ZHSHTthESuF') + expect(convert_text('&*$%')).to eq('+...') + expect(convert_text('"=<>!')).to eq('".<>.') end it 'should convert line breaks' do @@ -27,12 +26,8 @@ expect(convert_text(1234)).to eq('1234') end - it 'should remove invalid chars' do - expect(convert_text('"=<>!')).to eq('') - end - it 'should not touch valid chars' do - expect(convert_text("abc-ABC-0123- ':?,-(+.)/")).to eq("abc-ABC-0123- ':?,-(+.)/") + expect(convert_text("abc-ABC-0123- :?,-(+.)/")).to eq("abc-ABC-0123- :?,-(+.)/") end it 'should not touch nil' do diff --git a/spec/direct_debit_spec.rb b/spec/direct_debit_spec.rb index 1d7bd13..3edb3ee 100644 --- a/spec/direct_debit_spec.rb +++ b/spec/direct_debit_spec.rb @@ -288,7 +288,7 @@ end it 'should contain ' do - expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/Cdtr/Nm', 'Gläubiger GmbH') + expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/Cdtr/Nm', 'Glaubiger GmbH') end it 'should contain ' do @@ -329,8 +329,8 @@ end it 'should contain ' do - expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/Dbtr/Nm', 'Zahlemann & Söhne GbR') - expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/Dbtr/Nm', 'Meier & Schulze oHG') + expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/Dbtr/Nm', 'Zahlemann + Sohne GbR') + expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/Dbtr/Nm', 'Meier + Schulze oHG') end it 'should contain ' do @@ -340,7 +340,7 @@ it 'should contain ' do expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/RmtInf/Ustrd', 'Unsere Rechnung vom 10.08.2013') - expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/RmtInf/Ustrd', 'Vielen Dank für Ihren Einkauf') + expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[2]/RmtInf/Ustrd', 'Vielen Dank fur Ihren Einkauf.') end end @@ -477,7 +477,7 @@ end it 'should contain two payment_informations with ' do - expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/Cdtr/Nm', 'Gläubiger GmbH') + expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[1]/Cdtr/Nm', 'Glaubiger GmbH') expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf[2]/Cdtr/Nm', 'Creditor Inc.') end end diff --git a/spec/transaction_spec.rb b/spec/transaction_spec.rb index b3657f0..450030d 100644 --- a/spec/transaction_spec.rb +++ b/spec/transaction_spec.rb @@ -22,7 +22,7 @@ end it 'should not accept invalid value' do - expect(SEPA::Transaction).not_to accept(nil, '', 'X' * 71, for: :name) + expect(SEPA::Transaction).not_to accept(nil, '', {}, 'X' * 71, for: :name) end end @@ -66,10 +66,6 @@ ), for: :creditor_address) end end - - it 'should not accept invalid value' do - expect(SEPA::Transaction).not_to accept('', {} , for: :name) - end end context 'IBAN' do From 7773d502f5a34481ef8cbb9770503d7a1a658e0e Mon Sep 17 00:00:00 2001 From: raj deenoo Date: Wed, 29 May 2024 10:09:55 +0200 Subject: [PATCH 2/3] halley-926 fix relative path --- lib/sepa_king/converter.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sepa_king/converter.rb b/lib/sepa_king/converter.rb index a97df03..d47746c 100644 --- a/lib/sepa_king/converter.rb +++ b/lib/sepa_king/converter.rb @@ -21,8 +21,9 @@ module InstanceMethods # set equivalent and hence a full stop is to be used. FALLBACK_EPC_CHAR = '.'.freeze private_constant :FALLBACK_EPC_CHAR + mapping_path = File.join(File.dirname(__FILE__), "../misc/epc_mapping.csv") - EPC_MAPPING = CSV.read("lib/misc/epc_mapping.csv", col_sep: ","). + EPC_MAPPING = CSV.read(mapping_path, col_sep: ","). each_with_object(Hash.new(FALLBACK_EPC_CHAR)) { |v, mappings| mappings[v.first] = v.last }. freeze private_constant :EPC_MAPPING From 2f4dce4d7b8be2d6287b74bec24d9fcacf1263db Mon Sep 17 00:00:00 2001 From: raj deenoo Date: Thu, 30 May 2024 14:44:29 +0200 Subject: [PATCH 3/3] HALLEY-926 change version --- lib/sepa_king/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sepa_king/version.rb b/lib/sepa_king/version.rb index 9e01eae..3b466d7 100644 --- a/lib/sepa_king/version.rb +++ b/lib/sepa_king/version.rb @@ -1,3 +1,3 @@ module SEPA - VERSION = '0.14.0' + VERSION = '0.14.1' end