Skip to content

Commit eda2509

Browse files
author
Walter Stanish
committed
Poland (PL) national checksum support.
1 parent 967d91f commit eda2509

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Then just add the following to your `composer.json` file:
140140
// composer.json
141141
{
142142
"require": {
143-
"globalcitizen/php-iban": "2.4.5"
143+
"globalcitizen/php-iban": "2.4.6"
144144
}
145145
}
146146
```
@@ -236,7 +236,7 @@ The following table compares __php-iban__ to other PHP projects offering IBAN-re
236236

237237
| Project | Lic. | Proc | OO | Began | Latest | Star | Watch | Fork | Installs | Home culture | Deps |
238238
| ---------------------------------------------------------- | ---- | ---- | --- | ------ | ------ | ---- | ----- | ---- | -------- | ------------ | ------- |
239-
| __php-iban__ | LGPL ||| 2009 | 2.4.5 | 27 | 11 | 13 | 10k+* | Global* | *none* |
239+
| __php-iban__ | LGPL ||| 2009 | 2.4.6 | 27 | 11 | 13 | 10k+* | Global* | *none* |
240240
| [Iban](https://github.com/jschaedl/Iban) | MIT ||| 2013 | 1.1.6 | 38 | 10 | 14 | 52k | German | lots |
241241
| [IsoCodes](https://github.com/ronanguilloux/IsoCodes) | GPL3 ||| 2012 | 2.0.0 | 241 | 14 | 28 | 36k | French | lots |
242242
| [SepaUtil's](https://github.com/AbcAeffchen/SepaUtilities) | GPL3 ||| 2014 | 1.1.2 | 4 | 3 | 3 | 1.4k | German | phpunit |
@@ -273,10 +273,27 @@ In short, while composer users have apparently lept on rival libraries (particul
273273
So, fearless user ... __choose php-iban__: the ethical, functional, forward-looking, low-hassle library of choice for IBAN and IIBAN processing. __Choose to win!__ ;)
274274

275275

276+
Your Help Wanted
277+
----------------
278+
279+
* Work continues on providing a major update to include string internationalization. Translators will shortly be appreciated.
280+
281+
* 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).
282+
** __Italy__ (IT) has a custom checksum system we need some help deciphering.
283+
** __Luxembourg__ (LU) requires more test IBANs (real world LU... IBANs) to determine the checksum system with certainty. A web search could probably turn these up, given time.
284+
** __Mauritania__ (MR) has a dual character checksum system but our example IBAN does not match MOD97-10 which would be the expected system.
285+
** __Monaco__ (MC) has a dual character checksum system but our example IBAN does not match MOD97-10 which would be expected system. A web search for more IBANs (try the casinos and hotels!) would be useful.
286+
** __Netherlands__ (NL) has a checksum system without any digits. We are not sure what this is, tips would be appreciated.
287+
** __San Marino__ (SM) has an alphabetic checksum with an unknown algorithm.
288+
289+
* If you are willing to spend some time searching, we could do with some more test IBANs for most countries, especially smaller ones...
290+
291+
276292
News: February 2016
277293
-------------------
278294

279-
Work continues on providing a major update to include string internationalization. __We are also seeking help from you, the user community, to uncover national BBAN format and checksum documentation from official sources__, or failing that simply a large enough list of known valid BBANs from a given country that we can determine the checksum algorithms by deduction. The goal is to support querying (done!), checking, setting (fixing) national BBAN checksums in those countries who support them. We may later attempt something similar at the bank level, if appropriate. To help with the detective work, see [issue #39](https://github.com/globalcitizen/php-iban/issues/39) and [issue #41](https://github.com/globalcitizen/php-iban/issues/41).
295+
__[Version 2.4.6](https://github.com/globalcitizen/php-iban/releases/tag/v2.4.6)__ has been released.
296+
* Poland (PL) national checksum support has been added.
280297

281298
__[Version 2.4.5](https://github.com/globalcitizen/php-iban/releases/tag/v2.4.5)__ has been released.
282299
* Estonia (EE) national checksum support has been added.

php-iban.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,56 @@ function _iban_nationalchecksum_implementation_no($iban,$mode) {
861861
}
862862
}
863863

864+
# ISO/IEC 7064, MOD 11-2
865+
# @param $input string Must contain only characters ('0123456789').
866+
# @output A 1 character string containing '0123456789X',
867+
# or '' (empty string) on failure due to bad input.
868+
# (Credit: php-iso7064 @ https://github.com/globalcitizen/php-iso7064)
869+
function _iso7064_mod11_2($input) {
870+
$input = strtoupper($input); # normalize
871+
if(!preg_match('/^[0123456789]+$/',$input)) { return ''; } # bad input
872+
$modulus = 11;
873+
$radix = 2;
874+
$output_values = '0123456789X';
875+
$p = 0;
876+
for($i=0; $i<strlen($input); $i++) {
877+
$val = strpos($output_values,substr($input,$i,1));
878+
if($val < 0) { return ''; } # illegal character encountered
879+
$p = (($p + $val) * $radix) % $modulus;
880+
}
881+
$checksum = ($modulus - $p + 1) % $modulus;
882+
return substr($output_values,$checksum,1);
883+
}
884+
885+
# Implement the national checksum systems based on ISO7064 MOD11-2 Algorithm
886+
function _iban_nationalchecksum_implementation_iso7064_mod11_2($iban,$mode,$drop_at_front=0,$drop_at_end=1) {
887+
if($mode != 'set' && $mode != 'find' && $mode != 'verify') { return ''; } # blank value on return to distinguish from correct execution
888+
# first, extract the BBAN
889+
$bban = iban_get_bban_part($iban);
890+
# get the current and computed checksum
891+
$nationalchecksum = iban_get_nationalchecksum_part($iban);
892+
# drop characters from the front and end of the BBAN as requested
893+
$bban_less_checksum = substr($bban,$drop_at_front,strlen($bban)-$drop_at_end);
894+
# calculate expected checksum
895+
$expected_nationalchecksum = _iso7064_mod11_2($bban_less_checksum);
896+
# return
897+
if($mode=='find') {
898+
return $expected_nationalchecksum;
899+
}
900+
elseif($mode=='set') {
901+
return _iban_nationalchecksum_set($iban,$expected_nationalchecksum);
902+
}
903+
elseif($mode=='verify') {
904+
return (iban_get_nationalchecksum_part($iban) == $expected_nationalchecksum);
905+
}
906+
}
907+
908+
# Implement the national checksum for a Poland (PL) IBAN
909+
# (NOTE: Reverse-engineered)
910+
function _iban_nationalchecksum_implementation_pl($iban,$mode) {
911+
return _iban_nationalchecksum_implementation_iso7064_mod11_2($iban,$mode,0,17);
912+
}
913+
864914
# Implement the national checksum for a Sweden (SE) IBAN
865915
# (NOTE: Reverse-engineered)
866916
function _iban_nationalchecksum_implementation_se($iban,$mode) {

0 commit comments

Comments
 (0)