arturmkrtchyan / iban4j

A Java library for generation and validation of the International Bank Account Numbers (IBAN ISO_13616) and Business Identifier Codes (BIC ISO_9362).
http://iban4j.org
Apache License 2.0
270 stars 124 forks source link

Generate IBAN for GB with sort code and account number #124

Closed fahim1D closed 4 months ago

fahim1D commented 11 months ago

Using the example from the README:

Iban iban = new Iban.Builder()
                    .countryCode(CountryCode.GB)
                    .bankCode(123456)
                    .accountNumber(12345678)
                    .build();

I encounter an IbanFormatException: [1234] must contain only upper case letters.

In the code above, I'm supplying sort code to the bankCode field. After I investigated the the iban4j code a little bit, I was able to get a working example by assigning the sort code to the branchCode field instead, and I supplied a bankCode consisting only of letters.

Iban iban = new Iban.Builder()
                    .countryCode(CountryCode.GB)
                    .bankCode("ABCD")
                    .branchCode(123456)
                    .accountNumber(12345678)
                    .build();

I was able to get a bank code using https://www.iban.com/calculate-iban, which only requires a sort code and account number.

Can iban4j calculate IBANs from just sort code and account number? The website was just to test the results of this library, but in production I won't have access to a bankCode property.

Note: I supplied a dummy bank code and account number but I believe the point still stands.

hajk1 commented 11 months ago

AFAIK in the UK, the sort code is used to identify the bank and the branch where an account is held. Each bank has a unique set of sort codes for its various branches. If you have the sort code, you can often determine the bank and its specific branch.

There are several methods to find out a bank branch using its sort code:

  1. Bank's Official Website or Mobile Application
  2. Online Directories
  3. Contacting the Bank Directly
  4. Using API Services

Iban4j is an offline library and tries to be generic for all the supporting countries. It's so tricky to try to keep up-to-date details that are country-specific and volatile. Maybe it's better to provide some online services in the future which are hardly possible to be free of charge.

@fahim1D Please confirm if I understood your desired requirement