Skip to content

Commit

Permalink
Merge pull request #78 from francescozanoni/master
Browse files Browse the repository at this point in the history
Added San Marino BBAN checksum
  • Loading branch information
globalcitizen authored Aug 14, 2018
2 parents 856c012 + 757829c commit e491848
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,8 @@ Your Help Wanted

* If you know the URL of __national IBAN, BBAN or national checksum documentation__ from official sources, please let us know at [issue #39](https://github.com/globalcitizen/php-iban/issues/39) and [issue #41](https://github.com/globalcitizen/php-iban/issues/41).
* __Faroe Islands__ (FO) banks do not respond, neither does the Danish National Bank who referred me to them.
* __Italy__ (IT) has a custom checksum system we need some help deciphering. Note that it is not the [Italian fiscal code](https://en.wikipedia.org/wiki/Italian_fiscal_code_card).
* __Luxembourg__ (LU) does not seem to conform to any single checksum system. While some IBAN do validate with reasonably common systems, others don't or use others. The suggestion that Luxembourg has a national checksum system may in fact be incorrect. We need some clarification here, hopefully someone can dig up an official statement.
* __Mauritania__ (MR) has a dual character checksum system but our example IBAN does not match MOD97-10 which would be the expected system. Previously the IBAN here was always fixed to '13' checksum digits, however as of registry v66 it is now dynamic, which suggests a changed or at least now nationally relaxed checksum system.
* __San Marino__ (SM) has an alphabetic checksum with an unknown algorithm.

* If you are willing to spend some time searching, we could do with some more test IBANs for most countries, especially smaller ones...

Expand Down
14 changes: 11 additions & 3 deletions php-iban.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,21 +1227,29 @@ function _iban_nationalchecksum_implementation_it($iban,$mode) {
}
}

# Italian checksum
# Implement the national checksum for a San Marino (SM) IBAN
function _iban_nationalchecksum_implementation_sm($iban,$mode) {
// San Marino adheres to Italian rules.
return _iban_nationalchecksum_implementation_it($iban,$mode);
}

# Italian (and San Marino's) checksum
# (Credit: Translated by Francesco Zanoni from http://community.visual-basic.it/lucianob/archive/2004/12/26/2464.aspx)
# (Source: European Commettee of Banking Standards' Register of European Account Numbers (TR201 V3.23 — FEBRUARY 2007),
# available at URL http://www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf)
function _italian($input)
{
$digits = str_split('0123456789');
$letters = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ-. ');
$bbanWithoutChecksumLength = 22;
$lengthOfBbanWithoutChecksum = 22;
$divisor = 26;
$evenList = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
$oddList = array(1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23, 27, 28, 26);

// Character value computation
$sum = 0;

for ($k = 0; $k < $bbanWithoutChecksumLength; $k++) {
for ($k = 0; $k < $lengthOfBbanWithoutChecksum; $k++) {

$i = array_search($input[$k], $digits);
if ($i === false) {
Expand Down

0 comments on commit e491848

Please sign in to comment.