diff --git a/epics.gemspec b/epics.gemspec index 8fd1a2a..8a481e2 100644 --- a/epics.gemspec +++ b/epics.gemspec @@ -41,6 +41,7 @@ Gem::Specification.new do |spec| spec.post_install_message += "\e[32m" + ('*' * 60) + "\n\e[0m" spec.add_dependency 'faraday', '>= 1.10.0' + spec.add_dependency 'i18n', '>= 1.1.0' spec.add_dependency 'nokogiri', '>= 1.16.5' spec.add_dependency 'rubyzip', '>= 2.3.2' spec.add_dependency 'rexml', '>= 3.2.8' diff --git a/lib/epics.rb b/lib/epics.rb index e8fc3df..2376cd5 100644 --- a/lib/epics.rb +++ b/lib/epics.rb @@ -1,6 +1,7 @@ require 'openssl' require 'base64' require 'erb' +require 'i18n' require 'json' require 'zlib' require 'zip' @@ -12,6 +13,7 @@ require "epics/key" require "epics/response" require "epics/error" +require 'epics/letter_renderer' require "epics/middleware/xmlsig" require "epics/middleware/parse_ebics" require "epics/generic_request" @@ -52,6 +54,8 @@ require "epics/signer" require "epics/client" +I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'letter/locales', '*.yml')] + module Epics end diff --git a/lib/epics/client.rb b/lib/epics/client.rb index 904959f..deda7c3 100644 --- a/lib/epics/client.rb +++ b/lib/epics/client.rb @@ -3,6 +3,7 @@ class Epics::Client attr_accessor :passphrase, :url, :host_id, :user_id, :partner_id, :keys, :keys_content attr_writer :iban, :bic, :name + attr_accessor :locale def_delegators :connection, :post @@ -14,6 +15,7 @@ def initialize(keys_content, passphrase, url, host_id, user_id, partner_id) self.host_id = host_id self.user_id = user_id self.partner_id = partner_id + self.locale = :de end def inspect @@ -68,9 +70,12 @@ def self.setup(passphrase, url, host_id, user_id, partner_id, keysize = 2048) client end + def letter_renderer + @letter_renderer ||= Epics::LetterRenderer.new(self) + end + def ini_letter(bankname) - raw = File.read(File.join(File.dirname(__FILE__), '../letter/', 'ini.erb')) - ERB.new(raw).result(binding) + letter_renderer.render(bankname) end def save_ini_letter(bankname, path) diff --git a/lib/epics/letter_renderer.rb b/lib/epics/letter_renderer.rb new file mode 100644 index 0000000..75424d6 --- /dev/null +++ b/lib/epics/letter_renderer.rb @@ -0,0 +1,22 @@ +class Epics::LetterRenderer + extend Forwardable + + TEMPLATE_PATH = File.join(File.dirname(__FILE__), '../letter/', 'ini.erb') + I18N_SCOPE = 'epics.letter' + + def initialize(client) + @client = client + end + + def translate(key) + I18n.translate(key, locale: @client.locale, scope: I18N_SCOPE) + end + + alias_method :t, :translate + + def_delegators :@client, :user_id, :partner_id, :a, :x, :e + + def render(bankname) + ERB.new(File.read(TEMPLATE_PATH)).result(binding) + end +end diff --git a/lib/letter/ini.erb b/lib/letter/ini.erb index eefc344..878d0a1 100644 --- a/lib/letter/ini.erb +++ b/lib/letter/ini.erb @@ -4,30 +4,41 @@
- Datum + <%= t('date') %> | - <%= Date.today.strftime("%d.%m.%Y") %> + <%= Date.today.strftime('%d.%m.%Y') %> |
- Uhrzeit + <%= t('time') %> | - <%= Time.now.strftime("%H:%M:%S") %> + <%= Time.now.strftime('%H:%M:%S') %> |
- Empfänger + <%= t('recipient') %> | <%= bankname %> @@ -43,129 +54,123 @@ |
- Kunden-ID + Partner-ID | <%= partner_id %> |
Öffentlicher Schlüssel für die elektronische Unterschrift (A006)
+<%= t('certificate_type') %> : A006
Exponent (<%= a.key.e.num_bytes * 8 %> Bit):
-<%= a.e %>
<%= a.e %>
Modulus (<%= a.key.n.num_bytes * 8 %> Bit):
-<%= a.n.scan(/.{2}/).join(" ") %>
<%= a.n.scan(/.{2}/).join(' ') %>
Hash (SHA-256):
-
- <%= Base64.decode64(a.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %>
-
Ich bestätige hiermit den obigen öffentlichen Schlüssel für meine elektronische Unterschrift.
+<%= Base64.decode64(a.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %>
+ Ort/Datum + | ++ Name/Firma + | ++ <%= t('signature') %> + | +
+ _________________________ + | ++ _________________________ + | ++ |
- _________________________ + <%= t('date') %> | - _________________________ + <%= Date.today.strftime('%d.%m.%Y') %> | +
- _________________________ + <%= t('time') %> + | ++ <%= Time.now.strftime('%H:%M:%S') %> |
- Ort/Datum + <%= t('recipient') %> | - Name/Firma + <%= bankname %> | +
- Unterschrift + User-ID + | ++ <%= user_id %> + | +
+ Partner-ID + | ++ <%= partner_id %> |
- Datum - | -- <%= Date.today.strftime("%d.%m.%Y") %> - | -
- Uhrzeit - | -- <%= Time.now.strftime("%H:%M:%S") %> - | -
- Empfänger - | -- <%= bankname %> - | -
- User-ID - | -- <%= user_id %> - | -
- Kunden-ID - | -- <%= partner_id %> - | -
Öffentlicher Authentifikationsschlüssel (X002)
+<%= t('certificate_type') %> : X002
Exponent (<%= x.key.e.num_bytes * 8 %> Bit):
-<%= x.e %>
<%= x.e %>
Modulus (<%= x.key.n.num_bytes * 8 %> Bit):
-<%= x.n.scan(/.{2}/).join(" ") %>
<%= x.n.scan(/.{2}/).join(' ') %>
Hash (SHA-256):
-
- <%= Base64.decode64(x.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %>
-
Fortsetzung auf Seite 2 ...
- -<%= Base64.decode64(x.public_digest).unpack('H*').join.upcase.scan(/.{2}/).join(' ') %>
- Datum + <%= t('date') %> | - <%= Date.today.strftime("%d.%m.%Y") %> + <%= Date.today.strftime('%d.%m.%Y') %> |
- Uhrzeit + <%= t('time') %> | - <%= Time.now.strftime("%H:%M:%S") %> + <%= Time.now.strftime('%H:%M:%S') %> |
- Empfänger + <%= t('recipient') %> | <%= bankname %> @@ -181,51 +186,47 @@ |
- Kunden-ID + Partner-ID | <%= partner_id %> |
Öffentlicher Verschlüsselungsschlüssel (E002)
+<%= t('certificate_type') %> : E002
Exponent (<%= e.key.e.num_bytes * 8 %> Bit):
-<%= e.e %>
<%= e.e %>
Modulus (<%= e.key.n.num_bytes * 8 %> Bit):
-<%= e.n.scan(/.{2}/).join(" ") %>
<%= e.n.scan(/.{2}/).join(' ') %>
<%= t('certificate') %>:
Hash (SHA-256):
-<%= Base64.decode64(e.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %>
Ich bestätige hiermit die obigen öffentlichen Schlüssel für meinen EBICS-Zugang.
-<%= Base64.decode64(e.public_digest).unpack('H*').join.upcase.scan(/.{2}/).join(' ') %>
- _________________________ + Ort/Datum | - _________________________ + Name/Firma | - _________________________ + <%= t('signature') %> | |
- Ort/Datum - | -- Name/Firma + _________________________ | - Unterschrift + _________________________ | +