Skip to content

[Validator] Update BIC validator IBAN mappings #49697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Symfony/Component/Validator/Constraints/BicValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
*/
class BicValidator extends ConstraintValidator
{
// Reference: https://www.iban.com/structure
private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = [
// Reference: https://www.ecbs.org/iban/france-bank-account-number.html
// FR includes:
'GF' => 'FR', // French Guiana
'PF' => 'FR', // French Polynesia
'TF' => 'FR', // French Southern Territories
Expand All @@ -39,13 +40,20 @@ class BicValidator extends ConstraintValidator
'YT' => 'FR', // Mayotte
'NC' => 'FR', // New Caledonia
'RE' => 'FR', // Reunion
'BL' => 'FR', // Saint Barthelemy
'MF' => 'FR', // Saint Martin (French part)
'PM' => 'FR', // Saint Pierre and Miquelon
'WF' => 'FR', // Wallis and Futuna Islands
// Reference: https://www.ecbs.org/iban/united-kingdom-uk-bank-account-number.html
// GB includes:
'JE' => 'GB', // Jersey
'IM' => 'GB', // Isle of Man
'GG' => 'GB', // Guernsey
'VG' => 'GB', // British Virgin Islands
// FI includes:
'AX' => 'FI', // Aland Islands
// ES includes:
'IC' => 'ES', // Canary Islands
'EA' => 'ES', // Ceuta and Melilla
];

private $propertyAccessor;
Expand Down Expand Up @@ -104,7 +112,8 @@ public function validate($value, Constraint $constraint)
return;
}

if (!Countries::exists(substr($canonicalize, 4, 2))) {
$bicCountryCode = substr($canonicalize, 4, 2);
if (!isset(self::BIC_COUNTRY_TO_IBAN_COUNTRY_MAP[$bicCountryCode]) && !Countries::exists($bicCountryCode)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
Expand Down Expand Up @@ -137,7 +146,7 @@ public function validate($value, Constraint $constraint)
return;
}
$ibanCountryCode = substr($iban, 0, 2);
if (ctype_alpha($ibanCountryCode) && !$this->bicAndIbanCountriesMatch(substr($canonicalize, 4, 2), $ibanCountryCode)) {
if (ctype_alpha($ibanCountryCode) && !$this->bicAndIbanCountriesMatch($bicCountryCode, $ibanCountryCode)) {
$this->context->buildViolation($constraint->ibanMessage)
->setParameter('{{ value }}', $this->formatValue($value))
->setParameter('{{ iban }}', $iban)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ public static function getValidBicSpecialCases()
yield ['BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606'];
yield ['BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606'];
yield ['BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606'];
yield ['BNPABLGX', 'FR14 2004 1010 0505 0001 3M02 606'];
yield ['BNPAMFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
yield ['BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606'];
yield ['BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606'];

Expand All @@ -307,6 +309,13 @@ public static function getValidBicSpecialCases()
yield ['BARCIMSA', 'GB12 CPBK 0892 9965 0449 911'];
yield ['BARCGGSA', 'GB12 CPBK 0892 9965 0449 911'];
yield ['BARCVGSA', 'GB12 CPBK 0892 9965 0449 911'];

// FI related special cases
yield ['NDEAAXHH', 'FI14 1009 3000 1234 58'];

// ES related special cases
yield ['CAIXICBBXXX', 'ES79 2100 0813 6101 2345 6789'];
yield ['CAIXEABBXXX', 'ES79 2100 0813 6101 2345 6789'];
}
}

Expand Down