EPICS is a ruby implementation of the EBICS (Electronic Banking Internet Communication Standard).
It supports EBICS 2.4 (H003), 2.5 (H004) and 3.0 (H005). The default is 2.5 — see EBICS 3.0 (H005) for what differs on 3.0.
The client supports the complete initialization process comprising INI, HIA and HPB including the INI letter generation. It offers support for the most common download and upload order types (STA HAA HTD HPD PTK HAC HKD BKA C52 C53 C54 CD1 CDB CDD CCT VMK FDL FUL), and the H005-only types XEK, ZSR, and YCT.
Add this line to your application's Gemfile:
gem 'epics'Or install it yourself as:
$ gem install epics
In case you are new to EBICS, you'll have to complete an initialization process with your bank. Epics can help you generate all necessary keys and directly store them for later use. But first you'll have to lift some contractually work with your bank.
Once the paperwork is done, your bank should provide you with:
- a URL to their EBICS Server
- a HOST ID
- a PARTNER ID
- n User IDs (depends on your bank and needs)
Take these parameters and start setting up an UserID (repeat this for every user you want to initialize):
e = Epics::Client.setup("my-super-secret", "https://ebics.sandbox", "EBICS_HOST_ID", "EBICS_USER_ID", "EBICS_PARTNER_ID")
# the key size defaults to 4096 bits - pass a different one as the sixth argument
e = Epics::Client.setup("my-super-secret", "https://ebics.sandbox", "EBICS_HOST_ID", "EBICS_USER_ID", "EBICS_PARTNER_ID", 2048)
# for EBICS 3.0, ask for H005 — this also generates the X.509 certificates it requires
e = Epics::Client.setup(
"my-super-secret",
"https://ebics.sandbox",
"EBICS_HOST_ID",
"EBICS_USER_ID",
"EBICS_PARTNER_ID",
version: Epics::Keyring::VERSION_30,
)To use the keys later, just store them in a file
e.save_keys("/home/epics/my.key")
# or store the json elsewhere, but store it! for gods sake :DIt is really important to keep your keys around, once your user has been initialized you'll have to start over when you loose the keys!
Submit the keys to your bank:
e.INI # sends the signature key
e.HIA # sends the encryption and authentication keysThe next step is to print the INI letter and post it to your bank:
e.save_ini_letter( 'My Banks Name', "/home/epics/ini.html" )Open the generated HTML file in your favorite browser and print it (skipping header and footer sounds like a solid setting here). In case you're having difficulties with the encoding, try forcing your browser to use UTF-8.
Put the INI letter in an envelope and mail it to your bank!
Done! ... Well not completely :)
Once the bank confirms that your user is completely initialized, you'll have to download the public keys of your bank:
### see below for client creation
e.HPBThen again, save the keys or store the json somewhere safe.
You're now ready to go. Maybe try:
e.HAATo get a list of all supported order types.
We have many years of experience in developing innovative applications for the finance sector and integrating applications with financial institutions. - you might want to have a look at our portfolio If you need help we are happy to provide consulting or development services. Contact us: team@railslove.com
# read the keys from a file
e = Epics::Client.new(File.open('/tmp/my.key'), 'passphrase', 'url', 'host', 'user', 'partner')
# or provide a string hoding the key data
keys = File.read('/tmp/my.key')
e = Epics::Client.new(keys, 'passphrase', 'url', 'host', 'user', 'partner')You can choose to configure some default values like this
# For default values see `lib/epics.rb`
e = Epics::Client.new(keys, 'passphrase', 'url', 'host', 'user', 'partner', locale: :fr, product_name: 'Mon Epic Client EBICS')Only EBICS 2.4 numbers its own orders. 2.5 and 3.0 leave that to the bank. The counter runs
from A000 to ZZZZ and is not stored in the key file, so a process that restarts
begins at A000 again and re-sends order IDs the bank has already seen. Persist it
yourself and hand it back:
e = Epics::Client.new(
keys,
'passphrase',
'url',
'host',
'user',
'partner',
version: Epics::Keyring::VERSION_24,
order_id: last_used_order_id,
) # 'A0FC' or the integer it encodes
e.CD1(document)
store(e.current_order_id)Pass version: to Client.new and Client.setup. It defaults to 2.5.
Epics::Keyring::VERSION_24 # => "H003", EBICS 2.4
Epics::Keyring::VERSION_25 # => "H004", EBICS 2.5 (default)
Epics::Keyring::VERSION_30 # => "H005", EBICS 3.0
e = Epics::Client.new(
keys,
'passphrase',
'url',
'host',
'user',
'partner',
version: Epics::Keyring::VERSION_30,
)EBICS 3.0 carries the public keys inside ds:X509Data: there is no modulus/exponent form
as in 2.x, and the specification requires X.509 data in the key management order types
(EBICS 3.0.2 §3.9). An H005 client without certificates cannot run INI or HIA and raises
Epics::MissingCertificateError.
Client.setup therefore generates a self-signed certificate for each key when the version
is H005. Self-signed certificates are explicitly permitted for INI/HIA by the Swiss market
practice guidelines (§6.1). Confirm what your bank expects before relying on them.
e = Epics::Client.setup(
'passphrase',
'url',
'host',
'user',
'partner',
version: Epics::Keyring::VERSION_30,
)
e.INI # sends the signature key, as a certificate
e.HIA # sends the authentication and encryption keys, as certificates
e.save_ini_letter('My Banks Name', '/home/epics/ini.html')
e.save_keys('/home/epics/my.key')The subject defaults to the client's own identity (CN=<user>, OU=<partner>, O=<host>)
and the certificate does not expire. Both are configurable, as is turning generation off:
Epics::Client.setup(
'passphrase',
'url',
'host',
'user',
'partner',
version: Epics::Keyring::VERSION_30,
certificate_subject: '/CN=my.example.org/O=My Company/C=CH',
certificate_not_after: Time.utc(2030, 1, 1),
generate_certificates: false,
)Banks that require CA-issued certificates take precedence over generation — pass the PEM content and it is used as-is:
e = Epics::Client.new(
keys,
'passphrase',
'url',
'host',
'user',
'partner',
version: Epics::Keyring::VERSION_30,
x_509_certificate_a_content: File.read('cert_a.pem'),
x_509_certificate_x_content: File.read('cert_x.pem'),
x_509_certificate_e_content: File.read('cert_e.pem'),
)Certificates are stored in the key file alongside their key, so they are restored by
Client.new without passing the options again. Content that cannot be parsed raises
Epics::InvalidCertificateError naming the option it came from.
Client.setup uses A006 (RSASSA-PSS). Banks that still require A005 (RSASSA-PKCS1-v1_5)
can ask for it:
Epics::Client.setup(
'passphrase',
'url',
'host',
'user',
'partner',
version: Epics::Keyring::VERSION_30,
signature_version: Epics::Signature::A_VERSION_5,
)HPB reads the bank's keys from the certificates in its response and stores them with the
keyring, so save_keys keeps them. On H005 the key digests sent with each request are
SHA-256 fingerprints of those certificates rather than digests of the raw key.
EBICS 3.0 replaces order types with BTF service parameters, so on H005 HAA and
order_types return an array of hashes instead of an array of strings:
# H003/H004
e.order_types # => ["C53", "CCT", "STA", ...]
# H005
e.order_types # => [{ service_name: "EOP", scope: "CH", msg_name: "camt.053", container: "ZIP" },
# { service_name: "SCT", scope: "CH", msg_name: "pain.001" }, ...]Code that does order_types.include?('CCT') will silently find nothing on H005.
Download and upload order types send BTF parameters derived from the order type. Where a bank differs from the default, override them per call:
e.C53(from, to, scope: 'CH', msg_name_version: '08', container_type: 'ZIP')
e.CCT(document, service_option: 'CH001COR')Passing nil keeps the order type's default. To leave a parameter out of the request,
pass false. For example, the ZKB offers the pain.002 status report in version 10 only
without a container, while Z01 requests ZIP by default:
e.Z01(from, to, scope: 'CH', msg_name_version: '10', container_type: false)The Scope parameter identifies whose rulebook applies — an ISO country code such as CH
or DE, GLB for SEPA/SWIFT/CGI, or BIL for bilaterally agreed rules. Swiss market
practice requires it to be supplied (guidelines §5.2).
When it is absent the bank assumes a global definition.
On EBICS 2.4/2.5 these parameters have no equivalent and are ignored.
EBICS 3.0 replaces the order attribute (OZHNN, DZHNN) with SignatureFlag, which tells
the bank whether an upload carries the user's ES (electronic signature). Uploads always
include it and send SignatureFlag by default, the equivalent of OZHNN: the bank expects
every required signature in the request and rejects the order otherwise.
# spool into the EDS (distributed electronic signature, German VEU) when signatures are
# still missing, e.g. for a user who needs a second signer
e.CCT(document, request_eds: true)
# no SignatureFlag: the order is authorised outside EBICS, e.g. by an accompanying slip
# or in online banking
e.CCT(document, signature_flag: false)signature_flag: false only drops the flag; the user's signature is still sent.
On EBICS 2.4/2.5 both options have no effect and are silently ignored: uploads keep
their fixed order attribute (OZHNN for the payment uploads).
Since October 2025 a payer's bank has to verify the payee's name before a credit transfer
can be authorised (Verification of Payee, VoP). Banks such as GLS reject a credit transfer
with a single payment unless it goes through VoP. Upload it with the service option VOI
and spool it into the EDS (distributed electronic signature, German VEU); after the check
it waits there until it is signed or cancelled.
e.CCT(document, scope: nil, service_option: 'VOI', request_eds: true)
e.VPZ # => VoP status reports (pain.002), one per order
e.HVU # => XML listing the orders waiting in the EDS
service = { service_name: 'SCT', service_option: 'VOI', msg_name: 'pain.001' }
e.HVD('N02A', service) # => XML with the DataDigest and the display file
e.HVE('N02A', service) # sign: the bank executes the order
e.HVS('N02A', service) # cancel: nothing is paid
# sign only what you uploaded: the ES hash, i.e. SHA-256 of the document without CR and LF
e.HVE('N02A', service, digest: Digest::SHA256.digest(document.delete("\r\n")))The VoP report states the result per order (RCVC match, RVMC close match with the
account holder's name in AddtlInf, RVNM no match, RVNA not possible). On a full match
it may only carry the group status, matched by OrgnlMsgId to the pain.001's MsgId.
On EBICS 2.5 pass the order type instead of the service hash, e.g. e.HVE('N02A', 'CTV').
- INI (Sends the public key of the electronic signature.)
- HIA (Sends the public authentication (X002) and encryption (E002) keys.)
Currently this EPICS implementation supports the following order types:
- HPB (fetch your bank's public keys)
- STA (statements in MT940 format)
- HAA (available order types)
- HTD (user properties and settings)
- HPD (the available bank parameters)
- PTK (customer usage report in text format)
- HAC (customer usage report in xml format)
- VMK (customer usage report in xml format)
- XEK (account statements as PDF documents, H005 only)
- ZSR (payment status reports, H005 only)
- VPZ (Verification of Payee status reports)
- HVU / HVD (orders waiting in the EDS and their details)
- ... more coming soon
Example:
puts e.STA('2014-09-01', '2014-09-11')
# result is a MT940 feed
:20:1
:25:/PL12124012551111000015237873
:28C:00152
:60F:C081130PLN000000002535,03
:61:0810021002DN000000001273,23N641NONREF
:86:641^00PRZELEW MI¨DZYBANKOWY BETA/^34000
^3019401076^38PL54194010765205871800000000
^20wynagrodzenie z tytulu umow^21y o prac e
^32BANKA MONIKA
^62PODCHORAZYCH 16/1580-298 GD^63ANSK
:61:0810021002DN000000001287,40N641NONREF
:86:641^00PRZELEW MI¨DZYBANKOWY BETA/^34000
^3010201909^38PL74102019090000310200475772
^20wynagrodzenie z tytulu umow^21y o prac e
^32SZCZACHOR DOROTA
^62RATAJA 13B/1083-032 PSZCZOL^63KIIf the order data cannot be decrypted or inflated, e.g. because it arrived truncated,
the download is rejected to the bank with a negative receipt and
Epics::InvalidOrderDataError is raised, with the underlying error as its cause.
- CD1 (Uploads a SEPA Direct Debit document of type COR1)
- CDB (Uploads a SEPA Direct Debit document of type B2B)
- CDD (Uploads a SEPA Direct Debit document of type CORE)
- CCT (Uploads a SEPA Credit document)
- YCT (Uploads a multi-currency credit transfer, H005 only)
- ... more coming soon
Example:
puts e.CD1("i-am-PAIN-xml")
# res is a the transaction id and id of the order
# if the XML is a file in your FS, read it first and give if epics to consume
puts e.CD1(File.read("/where/the/xml/is/stored.xml"))Once you have a client, go ahead and start playing! There are 3 convenience methods that are hiding some strange names from you:
- debit( xml ) (submits a PAIN.008.003.02 document via CDD)
- credit( xml ) (submits a pain.001.003.03 document)
- statements( from, to ) (fetches an account statement via STA)
If you need more sophisticated EBICS order types, please read the next section about the supported functionalities.
Some banks require X.509 certificates for initialization (INI/HIA) even on EBICS 2.x, where the classic key-based workflow is otherwise used. On EBICS 3.0 they are mandatory — see EBICS 3.0 (H005).
Epics::Crypt::X509.generate builds a self-signed certificate for one of your keys:
certificate = Epics::Crypt::X509.generate(
client.signature_key, # or authentication_key / encryption_key
subject: '/CN=my.example.org/O=My Company/C=DE'
)
File.write('cert_a.pem', certificate.to_pem)It does not expire unless you say so. Pass not_before: and not_after: for a bounded
validity. On H005, Client.setup calls this for all three keys already, so you only need
it directly when adding certificates to an existing 2.x client.
Pass the PEM content when creating the client:
client = Epics::Client.new(
keys, # your key data as before
'passphrase',
'url',
'host',
'user',
'partner',
x_509_certificate_a_content: File.read('cert_a.pem'),
x_509_certificate_x_content: File.read('cert_x.pem'),
x_509_certificate_e_content: File.read('cert_e.pem'),
debug_mode: true # Optional: enables verbose logging of EBICS requests/responses
)save_keys stores the certificates with the keys, so later Client.new calls restore
them without the options.
Note: For production environments, your bank may require certificates issued by a trusted authority. Be sure to confirm your bank's requirements before proceeding.
client.save_ini_letter('Your Bank Name', 'initialization_letter.html')Where a key has a certificate, the letter prints the SHA-256 hash of that certificate as required for certificate-based registration, rather than the hash of the raw key.
Epics raises a different error for each way an order can fail. Errors about the bank's
answer inherit from Epics::Error, except Epics::InvalidOrderDataError. Network failures
come from Faraday, and setup mistakes point to your code or configuration.
The bank answered with an EBICS return code. Both errors carry code (e.g. "091005"),
symbol (e.g. "EBICS_INVALID_ORDER_TYPE") and short_text.
| Error | Raised when |
|---|---|
Epics::Error::TechnicalError |
The return code in the response header is not OK, e.g. EBICS_AUTHENTICATION_FAILED or EBICS_INVALID_ORDER_TYPE |
Epics::Error::BusinessError |
The return code in the response body is not OK, e.g. EBICS_NO_DOWNLOAD_DATA_AVAILABLE |
Retrying does not help here, apart from cases like EBICS_NO_DOWNLOAD_DATA_AVAILABLE,
which only means there is nothing new to fetch yet.
| Error | Superclass | Raised when | Attributes |
|---|---|---|---|
Epics::Error::HTTPError |
Epics::Error |
The HTTP status is not 2xx, e.g. a 503 page during a maintenance window |
status, reason_phrase, phase, order_type, retryable?, body_excerpt |
Epics::InvalidResponseError |
Epics::Error |
The response lacks a value EBICS requires: a ReturnCode (e.g. a login page behind a wrong URL, an empty body), NumSegments or a DataDigest |
field, body_excerpt |
Epics::InvalidOrderDataError |
StandardError |
The order data of a download cannot be decrypted or inflated, e.g. because it arrived truncated. The bank has already received a negative receipt | order_type, cause |
body_excerpt holds the first 500 characters of the response as UTF-8, converted from the
charset the bank declared, so the page the bank sent shows up in your logs; bytes that are
not valid UTF-8 become �. It comes from a system you do not control: an error page from
a firewall or gateway can echo parts of your request, such as your partner and user ID, so
treat it like any other response data when you send it to an error tracker. message and inspect do not contain it.
reason_phrase is the one the server sent, e.g. "Wartungsarbeiten", or the standard one
where it sent none. Like body_excerpt, it is always UTF-8. None of these errors is a
TechnicalError, so they never pose as an EBICS return code, and their code is nil.
begin
client.HTD
rescue Epics::Error::HTTPError => e
e.message # => "HTTP 503 Service Unavailable"
e.status # => 503
e.reason_phrase # => "Service Unavailable"
e.phase # => "Initialisation"
e.order_type # => "HTD"
e.retryable? # => true
endA gateway in front of the bank can answer with an error after the bank has already
accepted the request. A new attempt is a new transaction with a new signature, so the bank
does not recognise it as a duplicate. retryable? tells you whether sending the order again
is safe. It does not tell you whether a new attempt can succeed: a 404 after a change of
the bank's URL stays a 404, so check status as well. retryable? is false when the
failed request may have made the bank act:
phase |
Request that failed | retryable? |
|---|---|---|
"Initialisation" |
The first request of downloads (HTD, C53, BTD, ...) and uploads (CCT, BTU, ...). It carries no order data |
true. The bank may have opened a transaction, which expires without the order data |
"Initialisation" |
HVE and HVS, whose only request carries the signature or the cancellation |
false. The bank may have signed or cancelled the order, so check it with HVU or HVD first |
"Transfer" |
The order data of an upload | false. The bank may execute the order, so check it with HAC, PTK or the account statement first |
"Transfer" |
A further segment of a download | true. Restart the download |
"Receipt" |
The receipt that closes a download | true. The bank may already have marked the data as fetched, so download it again with a date range (from, to) |
nil |
Key management (INI, HIA, HPB) and HEV, which have no transaction phase |
true. No order or payment is involved |
nil |
A request no Epics::Client method sent, e.g. your own XML passed to client.post |
false. Epics cannot tell what reached the bank |
phase is the TransactionPhase of the request that failed, and order_type the order
type of the client method that sent it, e.g. "CCT" or "HVE", on EBICS 3.0 as well,
where the request itself says BTU. It is nil for HEV.
A failed receipt costs the order data of that download: Epics raises before it returns
the data, and the bank may already have marked it as fetched. A download of new data only,
e.g. client.C53 without a date range, then finds nothing, so fetch the same date range
again rather than reading EBICS_NO_DOWNLOAD_DATA_AVAILABLE as "nothing new".
Timeouts and connection failures are raised as Faraday's own errors, e.g.
Faraday::TimeoutError and Faraday::ConnectionFailed (both Faraday::Error). They carry
no phase. A timeout while an upload's order data is on its way may still have reached the
bank, so never retry an upload automatically after a Faraday::TimeoutError or
Faraday::ConnectionFailed: treat it like a failed "Transfer" and check the order first.
These point to a problem in your code or configuration and are raised before a request is sent or while Epics checks the bank's keys. A retry does not help.
| Error | Raised when |
|---|---|
Epics::MissingCertificateError |
EBICS 3.0 (H005) needs an X.509 certificate the client was not given |
Epics::InvalidCertificateError |
A certificate from a constructor option or the HPB response cannot be parsed |
Epics::MissingKeyError |
A key is needed that the client has not loaded, e.g. the bank's key before HPB has run |
Epics::VersionSupportError |
The order or option is not available for the client's EBICS version |
Epics::DataDigestMismatchError |
HVE or HVS find a different order in the EDS than the one you meant to sign; nothing was signed |
begin
statements = client.C53(from, to)
rescue Epics::Error::BusinessError => e
raise unless e.symbol == 'EBICS_NO_DOWNLOAD_DATA_AVAILABLE'
statements = [] # nothing new at the bank yet
rescue Epics::Error::HTTPError => e
if e.retryable? && [408, 429, 502, 503, 504].include?(e.status)
retry_later(e)
else
alert(e) # an upload or signature may have reached the bank, or a new attempt will not help
end
rescue Faraday::Error => e
retry_later(e) # a download only; for an upload, check the order before you send it again
rescue Epics::Error, Epics::InvalidOrderDataError => e
alert(e) # the bank rejected the order, or its answer could not be read
endRailslove is commited to provide the best developer tools for integrating with financial institutions. Epics is one of our many tools and services. If you are missing some features or something is not working as expected please create an issue.
This gem provides a full implementation of the Electronic Banking Internet Communication Standard and works with any bank that supports this standard. Please ask your bank if they support EBICS and what order types are available.
Besides EBCIS being a standard, some server implementations are slighty different. But most banks use the same EBICS server implementations. Commonly used and supported by Epics are:
- Business-Logics EBICS, Banking-Server
- Travic Corporate
Used for example by the following tested institutions:
- Handelsbank
- Deutsche Bank
- Commerzbank
- Kreissparkasse Mayen
- Postbank
- Sozialbank
- Sparkassen
- Volksbanken Raiffeisenbanken
- Hypo Vereinsbank
- BAWAG P.S.K. (AT)
- Bank Frick (LI)
- BNP Paribas (FR)
Is Epics working with your institution? Please help us to grow this list of supported banks:
For development purposes, you may want to use a proxy server in order to have a convenient look into request and response data.
To do so, it's sufficient to define http_proxy in your environment.
Also you may want to disable SSL verification - simply set EPICS_VERIFY_SSL to "false".
For example:
http_proxy=localhost:8080
EPICS_VERIFY_SSL=false
- ebics.de
- EBICS specification
- Common Integrative Implementation Guide to Supplement the EBICS Specification (pdf)
- Die Deutsche Kreditwirtschaft
Railslove has a Contributor License Agreement (CLA) which clarifies the intellectual property rights for contributions from individuals or entities. To ensure every developer has signed the CLA, we use CLA Assistant.
After checking out the repo, run bin/setup to install dependencies.
Then, run rspec to run the tests.
You can also run bin/console for an interactive prompt that will allow you to experiment.
- Contact team@railslove.com for information about the CLA
- Fork it ( https://github.com/[my-github-username]/epics/fork )
- Run
bin/setup - Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
- @punkle64
for adding XCT order type - @romanlehnert
for adding CDB order type - @gadimbaylisahil
for fixing CCS order type and attribute - you, for contributing too!
2014-2022 - built with love by Railslove and released under the GNU LESSER GENERAL PUBLIC LICENSE. We have built quite a number of FinTech products. If you need support we are happy to help. Please contact us at team@railslove.com.