IBAN + BIC
When IBAN validation is not enough.
Features
- IBAN validation (
ActiveModel::EachValidatorand control digits calculator function). - National account digits control validation (currently only ES included, others countries can be added).
- Associated tags to countries (currently only SEPA tag is available).
- BICs mapping from IBAN bank code part: COUNTRY + BANK => BIC code.
- Currently, static data only includes some ES banks, PRs are welcomed.
- Optional database model to allow apps to dynamically add new BICs mapping.
Usage
- Validator: add IBAN validation to your models.
validates :iban, iban: true
You can also validate that IBAN is from a SEPA country.
validates :iban, iban: { tags: [:sepa] }
- IBAN control digits calculation
2.4.1 :001 > IbanBic.calculate_check("ES0000030000300000000000")
=> 87
- IBAN parsing
2.4.1 :001 > IbanBic.parse("ES8700030000300000000000")
=> {"country"=>"ES", "iban_check"=>"87", "bank"=>"0003", "branch"=>"0000", "check"=>"30", "account"=>"0000000000"}
- BIC calculation (bank code must be in the static file or in the database)
2.4.1 :009 > IbanBic.calculate_bic("ES8700030000300000000000")
=> "BDEPESM1XXX"
Installation
- Add this line to your application's Gemfile
gem "iban_bic"
- Update bundle
$ bundle
- Run installer
3.a. Using BICs dynamic data from database
Add a bics table to your database and an initializer file for configuration:
$ bundle exec rails generate iban_bic:install
$ bundle exec rake db:migrate
Load static data to the created bics table:
$ bundle exec rake iban_bic:load_data
3.b. Using static data from YAML files
Create an initializer file for configuration:
$ bundle exec rails generate iban_bic:install --with-static-data
- Customize initializer if needed, adding validations for new countries, or overriding YAML files.
TO-DO
- Faker data generation
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.