From cc791d6e191751333b1073a7e8a2f8c5e1d72357 Mon Sep 17 00:00:00 2001 From: AbcAeffchen Date: Tue, 18 Oct 2016 01:32:16 +0200 Subject: [PATCH] added a function to check if a transaction is within the EEA --- CHANGE_LOG.md | 3 +++ src/SepaUtilities.php | 27 +++++++++++++++++++++++++++ tests/SepaUtilitiesTest.php | 8 ++++++++ 3 files changed, 38 insertions(+) diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index 4d49e9e..c37cb8f 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -1,6 +1,9 @@ Sephpa - Change Log =============== +##1.2.1 - Oct 18, '16## +- added function to validate if two IBANs belong to the EEA (European Economic Area). + ##1.2.0 - Oct 16, '16## - dropped PHP 5.5 support - added support for HHVM diff --git a/src/SepaUtilities.php b/src/SepaUtilities.php index d5a5a99..4ef5a00 100644 --- a/src/SepaUtilities.php +++ b/src/SepaUtilities.php @@ -361,6 +361,33 @@ public static function isNationalTransaction($iban1, $iban2) return false; } + /** + * Checks if both IBANs belong to the EEA (European Economic Area) + * This function does not check if the IBANs are valid. + * + * @param string $iban1 + * @param string $iban2 + * @return bool + */ + public static function isEEATransaction($iban1, $iban2) + { + // remove whitespaces + $iban1 = preg_replace('#\s+#','',$iban1); + $iban2 = preg_replace('#\s+#','',$iban2); + + // check if both county codes belong to the EEA + $EEA = array('IS' => 1,'LI' => 1,'NO' => 1,'BE' => 1,'BG' => 1,'DK' => 1,'DE' => 1, + 'EE' => 1,'FI' => 1,'FR' => 1,'GR' => 1,'IE' => 1,'IT' => 1,'HR' => 1, + 'LV' => 1,'LT' => 1,'LU' => 1,'MT' => 1,'NL' => 1,'AT' => 1,'PL' => 1, + 'PT' => 1,'RO' => 1,'SE' => 1,'SK' => 1,'SI' => 1,'ES' => 1,'CZ' => 1, + 'HU' => 1,'GB' => 1,'CY' => 1); + + if(isset($EEA[strtoupper(substr($iban1,0,2))],$EEA[strtoupper(substr($iban2,0,2))])) + return true; + + return false; + } + /** * Checks if IBAN and BIC belong to the same country. If not, they also can not belong to * each other. diff --git a/tests/SepaUtilitiesTest.php b/tests/SepaUtilitiesTest.php index af026bd..3dc7305 100644 --- a/tests/SepaUtilitiesTest.php +++ b/tests/SepaUtilitiesTest.php @@ -405,6 +405,14 @@ public function testIsNationalTransaction() static::assertFalse(SepaUtilities::isNationalTransaction('DE87200500001234567890', 'FR87200500001234567890')); } + public function testIsEEATransaction() + { + static::assertTrue(SepaUtilities::isEEATransaction('DE87200500001234567890', 'DE87200500001234567890')); + static::assertTrue(SepaUtilities::isEEATransaction('DE87200500001234567890', 'FR87200500001234567890')); + static::assertFalse(SepaUtilities::isEEATransaction('DE87200500001234567890', 'DZ87200500001234567890')); + static::assertFalse(SepaUtilities::isEEATransaction('DZ87200500001234567890', 'DZ87200500001234567890')); + } + public function testSanitizeLength() { static::assertSame('1234567', SepaUtilities::sanitizeLength('1234567', 8));