10000 bug #49697 [Validator] Update BIC validator IBAN mappings (maxbeckers) · symfony/symfony@f4177aa · GitHub
[go: up one dir, main page]

Skip to content

Commit f4177aa

Browse files
bug #49697 [Validator] Update BIC validator IBAN mappings (maxbeckers)
This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Update BIC validator IBAN mappings | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a With #29755 were added some special cases for BIC validation. The old references have updated and don't include this mapping anymore. But https://www.iban.com/structure describes this special cases. I updated the list with this PR based on the new reference. Commits ------- 436dcba [Validator] Update BIC validator IBAN mappings
2 parents 0874ea8 + 436dcba commit f4177aa

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Symfony/Component/Validator/Constraints/BicValidator.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
*/
3030
class BicValidator extends ConstraintValidator
3131
{
32+
// Reference: https://www.iban.com/structure
3233
private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = [
33-
// Reference: https://www.ecbs.org/iban/france-bank-account-number.html
34+
// FR includes:
3435
'GF' => 'FR', // French Guiana
3536
'PF' => 'FR', // French Polynesia
3637
'TF' => 'FR', // French Southern Territories
@@ -39,13 +40,20 @@ class BicValidator extends ConstraintValidator
3940
'YT' => 'FR', // Mayotte
4041
'NC' => 'FR', // New Caledonia
4142
'RE' => 'FR', // Reunion
43+
'BL' => 'FR', // Saint Barthelemy
44+
'MF' => 'FR', // Saint Martin (French part)
4245
'PM' => 'FR', // Saint Pierre and Miquelon
4346
'WF' => 'FR', // Wallis and Futuna Islands
44-
// Reference: https://www.ecbs.org/iban/united-kingdom-uk-bank-account-number.html
47+
// GB includes:
4548
'JE' => 'GB', // Jersey
4649
'IM' => 'GB', // Isle of Man
4750
'GG' => 'GB', // Guernsey
4851
'VG' => 'GB', // British Virgin Islands
52+
// FI includes:
53+
'AX' => 'FI', // Aland Islands
54+
// ES includes:
55+
'IC' => 'ES', // Canary Islands
56+
'EA' => 'ES', // Ceuta and Melilla
4957
];
5058

5159
private $propertyAccessor;
@@ -104,7 +112,8 @@ public function validate($value, Constraint $constraint)
104112
return;
105113
}
106114

107-
if (!Countries::exists(substr($canonicalize, 4, 2))) {
115+
$bicCountryCode = substr($canonicalize, 4, 2);
116+
if (!isset(self::BIC_COUNTRY_TO_IBAN_COUNTRY_MAP[$bicCountryCode]) && !Countries::exists($bicCountryCode)) {
108117
$this->context->buildViolation($constraint->message)
109118
->setParameter('{{ value }}', $this->formatValue($value))
110119
->setCode(Bic::INVALID_COUNTRY_CODE_ERROR)
@@ -137,7 +146,7 @@ public function validate($value, Constraint $constraint)
137146
return;
138147
}
139148
$ibanCountryCode = substr($iban, 0, 2);
140-
if (ctype_alpha($ibanCountryCode) && !$this->bicAndIbanCountriesMatch(substr($canonicalize, 4, 2), $ibanCountryCode)) {
149+
if (ctype_alpha($ibanCountryCode) && !$this->bicAndIbanCountriesMatch($bicCountryCode, $ibanCountryCode)) {
141150
$this->context->buildViolation($constraint->ibanMessage)
142151
->setParameter('{{ value }}', $this->formatValue($value))
143152
->setParameter('{{ iban }}', $iban)

src/Symfony/Component/Validator/Tests/Constraints/BicValidatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public static function getValidBicSpecialCases()
299299
yield ['BNPAYTGX', 'FR14 2004 1010 0505 0001 3M02 606'];
300300
yield ['BNPANCGX', 'FR14 2004 1010 0505 0001 3M02 606'];
301301
yield ['BNPAREGX', 'FR14 2004 1010 0505 0001 3M02 606'];
302+
yield ['BNPABLGX', 'FR14 2004 1010 0505 0001 3M02 606'];
303+
yield ['BNPAMFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
302304
yield ['BNPAPMGX', 'FR14 2004 1010 0505 0001 3M02 606'];
303305
yield ['BNPAWFGX', 'FR14 2004 1010 0505 0001 3M02 606'];
304306

@@ -307,6 +309,13 @@ public static function getValidBicSpecialCases()
307309
yield ['BARCIMSA', 'GB12 CPBK 0892 9965 0449 911'];
308310
yield ['BARCGGSA', 'GB12 CPBK 0892 9965 0449 911'];
309311
yield ['BARCVGSA', 'GB12 CPBK 0892 9965 0449 911'];
312+
313+
// FI related special cases
314+
yield ['NDEAAXHH', 'FI14 1009 3000 1234 58'];
315+
316+
// ES related special cases
317+
yield ['CAIXICBBXXX', 'ES79 2100 0813 6101 2345 6789'];
318+
yield ['CAIXEABBXXX', 'ES79 2100 0813 6101 2345 6789'];
310319
}
311320
}
312321

0 commit comments

Comments
 (0)
0