IBAN + BIC

When IBAN validation is not enough.

Travis Codecov Scrutinizer Dependency Status

Features

  • IBAN validation (ActiveModel::EachValidator and 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

  1. 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] }
  1. IBAN control digits calculation
2.4.1 :001 > IbanBic.calculate_check("ES0000030000300000000000")
 => 87
  1. IBAN parsing
2.4.1 :001 > IbanBic.parse("ES8700030000300000000000")
=> {"country"=>"ES", "iban_check"=>"87", "bank"=>"0003", "branch"=>"0000", "check"=>"30", "account"=>"0000000000"}
  1. BIC calculation (bank code must be in the static file or in the database)
2.4.1 :009 > IbanBic.calculate_bic("ES8700030000300000000000")
 => "BDEPESM1XXX"

Installation

  1. Add this line to your application's Gemfile
gem "iban_bic"
  1. Update bundle
$ bundle
  1. 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
  1. 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.