Skip to content

Commit

Permalink
added a function to check if a transaction is within the EEA
Browse files Browse the repository at this point in the history
  • Loading branch information
AbcAeffchen committed Oct 17, 2016
1 parent af884a4 commit cc791d6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/SepaUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions tests/SepaUtilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit cc791d6

Please sign in to comment.