Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant convert bban to iban because bban for Norway is appended with "null" which increases its length and validation is failing #71

Closed
sanathkd opened this issue Aug 21, 2020 · 1 comment · May be fixed by #73 or #75
Milestone

Comments

@sanathkd
Copy link

sanathkd commented Aug 21, 2020

BBAN for Norway is appended with "null" which increases its length and hence validation is failing. Can you help me if i'm missing something? Or can this issue be fixed?

I feel its messed up in "iban.java" under method "formatIban()" when converting "toString" in the end.

        private String formatIban() {
            final StringBuilder sb = new StringBuilder();
            sb.append(countryCode.getAlpha2());
            sb.append(DEFAULT_CHECK_DIGIT);
            sb.append(formatBban());
            return sb.toString();
        }

Test Data BBAN: 44350343730
Code used:

String set = "44350343730";
String bankCode = "4435";
String account = "0343730";

Iban.Builder builder = new Iban.Builder();
builder.countryCode(CountryCode.NO);
builder.bankCode(bankCode);
builder.accountNumber(account);

Iban value = builder.build();

Error thrown:

Exception in thread "main" org.iban4j.IbanFormatException: [44350343730null] length is 15, expected BBAN length is: 11
	at org.iban4j.IbanUtil.validateBbanLength(IbanUtil.java:362)
	at org.iban4j.IbanUtil.validate(IbanUtil.java:79)
	at org.iban4j.Iban$Builder.build(Iban.java:365)
	at org.iban4j.Iban$Builder.build(Iban.java:337)
@hajk1
Copy link
Collaborator

hajk1 commented Oct 13, 2020

Norway BBAN structure requires 'National Check digit' and 6 character 'Account number'. I think you are providing both in the account number field which is not correct. You might change your code to the below:
`

        String bankCode = "4435";
        String account = "034373";
        String nationalCheckDigit = "0";
  

        Iban.Builder builder = new Iban.Builder();
        builder.countryCode(CountryCode.NO);
        builder.bankCode(bankCode);
        builder.accountNumber(account);
        builder.nationalCheckDigit(nationalCheckDigit);
        Iban value = builder.build();

`

By the way, it is much better to validate this in the library. I will commit a change in order to validate such a case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants