Skip to content

Commit

Permalink
Expand IID extraction to IBANs from Liechtenstein
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Jul 26, 2019
1 parent 2b7148f commit 00dbcdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Z38/SwissPayment/IID.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ public function __construct($iid)
*/
public static function fromIBAN(IBAN $iban)
{
if ($iban->getCountry() !== 'CH') {
throw new InvalidArgumentException('IID can only be extracted from Swiss IBANs.');
$supportedCountries = ['CH', 'LI'];

if (!in_array($iban->getCountry(), $supportedCountries)) {
throw new InvalidArgumentException(
'IID can only be extracted from IBANs of these countries: ' . implode(', ', $supportedCountries)
);
}

return new self(substr($iban->normalize(), 4, 5));
Expand Down
3 changes: 3 additions & 0 deletions tests/Z38/SwissPayment/Tests/IIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public function testFromIBAN()
{
$instance = IID::fromIBAN(new IBAN('CH31 8123 9000 0012 4568 9'));
$this->assertSame('81239', $instance->format());

$instance = IID::fromIBAN(new IBAN('LI21 0881 0000 2324 013A A'));
$this->assertSame('08810', $instance->format());
}

/**
Expand Down

0 comments on commit 00dbcdd

Please sign in to comment.