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

Fixes iban checksum calculation #2591

Merged
merged 3 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/faker/default/bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ def iban_checksum(country_code, account)
d =~ /[A-Z]/ ? (d.ord - 55).to_s : d
end.join.to_i

# This is answer to (iban_to_num + checksum) % 97 == 1
checksum = (1 - account_to_number) % 97
# This is the correct answer to (iban_to_num + checksum) % 97 == 1
# See steps 6 & 7 - https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
srcoley marked this conversation as resolved.
Show resolved Hide resolved
checksum = 98 - (account_to_number % 97)

# Use leftpad to make the size always to 2
checksum.to_s.rjust(2, '0')
Expand Down
Loading