AbstractComparison.php
1 year ago
AbstractComparisonValidator.php
1 year ago
All.php
1 year ago
AllValidator.php
4 years ago
AtLeastOneOf.php
1 year ago
AtLeastOneOfValidator.php
1 year ago
Bic.php
1 year ago
BicValidator.php
1 year ago
Blank.php
1 year ago
BlankValidator.php
4 years ago
Callback.php
1 year ago
CallbackValidator.php
4 years ago
CardScheme.php
1 year ago
CardSchemeValidator.php
1 year ago
Cascade.php
1 year ago
Choice.php
1 year ago
ChoiceValidator.php
1 year ago
Cidr.php
1 year ago
CidrValidator.php
4 years ago
Collection.php
1 year ago
CollectionValidator.php
4 years ago
Composite.php
1 year ago
Compound.php
4 years ago
CompoundValidator.php
4 years ago
Count.php
1 year ago
CountValidator.php
4 years ago
Country.php
1 year ago
CountryValidator.php
4 years ago
CssColor.php
1 year ago
CssColorValidator.php
1 year ago
Currency.php
1 year ago
CurrencyValidator.php
4 years ago
Date.php
1 year ago
DateTime.php
1 year ago
DateTimeValidator.php
2 years ago
DateValidator.php
1 year ago
DisableAutoMapping.php
1 year ago
DivisibleBy.php
4 years ago
DivisibleByValidator.php
4 years ago
Email.php
1 year ago
EmailValidator.php
1 year ago
EnableAutoMapping.php
1 year ago
EqualTo.php
4 years ago
EqualToValidator.php
4 years ago
Existence.php
4 years ago
Expression.php
1 year ago
ExpressionLanguageSyntax.php
1 year ago
ExpressionLanguageSyntaxValidator.php
1 year ago
ExpressionValidator.php
1 year ago
File.php
1 year ago
FileValidator.php
4 years ago
GreaterThan.php
4 years ago
GreaterThanOrEqual.php
4 years ago
GreaterThanOrEqualValidator.php
4 years ago
GreaterThanValidator.php
4 years ago
GroupSequence.php
4 years ago
GroupSequenceProvider.php
4 years ago
Hostname.php
1 year ago
HostnameValidator.php
4 years ago
Iban.php
1 year ago
IbanValidator.php
1 year ago
IdenticalTo.php
4 years ago
IdenticalToValidator.php
4 years ago
Image.php
1 year ago
ImageValidator.php
4 years ago
Ip.php
1 year ago
IpValidator.php
4 years ago
IsFalse.php
1 year ago
IsFalseValidator.php
4 years ago
IsNull.php
1 year ago
IsNullValidator.php
4 years ago
IsTrue.php
1 year ago
IsTrueValidator.php
4 years ago
Isbn.php
1 year ago
IsbnValidator.php
1 year ago
Isin.php
1 year ago
IsinValidator.php
4 years ago
Issn.php
1 year ago
IssnValidator.php
4 years ago
Json.php
1 year ago
JsonValidator.php
1 year ago
Language.php
1 year ago
LanguageValidator.php
4 years ago
Length.php
1 year ago
LengthValidator.php
4 years ago
LessThan.php
4 years ago
LessThanOrEqual.php
4 years ago
LessThanOrEqualValidator.php
4 years ago
LessThanValidator.php
4 years ago
Locale.php
1 year ago
LocaleValidator.php
4 years ago
Luhn.php
1 year ago
LuhnValidator.php
4 years ago
Negative.php
4 years ago
NegativeOrZero.php
4 years ago
NotBlank.php
1 year ago
NotBlankValidator.php
4 years ago
NotCompromisedPassword.php
1 year ago
NotCompromisedPasswordValidator.php
1 year ago
NotEqualTo.php
4 years ago
NotEqualToValidator.php
4 years ago
NotIdenticalTo.php
4 years ago
NotIdenticalToValidator.php
4 years ago
NotNull.php
1 year ago
NotNullValidator.php
4 years ago
NumberConstraintTrait.php
4 years ago
Optional.php
4 years ago
Positive.php
4 years ago
PositiveOrZero.php
4 years ago
Range.php
1 year ago
RangeValidator.php
1 year ago
Regex.php
1 year ago
RegexValidator.php
4 years ago
Required.php
4 years ago
Sequentially.php
1 year ago
SequentiallyValidator.php
4 years ago
Time.php
1 year ago
TimeValidator.php
1 year ago
Timezone.php
1 year ago
TimezoneValidator.php
1 year ago
Traverse.php
4 years ago
Type.php
1 year ago
TypeValidator.php
4 years ago
Ulid.php
1 year ago
UlidValidator.php
2 years ago
Unique.php
1 year ago
UniqueValidator.php
1 year ago
Url.php
1 year ago
UrlValidator.php
1 year ago
Uuid.php
1 year ago
UuidValidator.php
4 years ago
Valid.php
1 year ago
ValidValidator.php
4 years ago
ZeroComparisonConstraintTrait.php
1 year ago
index.php
3 years ago
CardSchemeValidator.php
66 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Constraints; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Constraint; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\ConstraintValidator; |
| 6 | use MailPoetVendor\Symfony\Component\Validator\Exception\UnexpectedTypeException; |
| 7 | class CardSchemeValidator extends ConstraintValidator |
| 8 | { |
| 9 | protected $schemes = [ |
| 10 | // American Express card numbers start with 34 or 37 and have 15 digits. |
| 11 | CardScheme::AMEX => ['/^3[47][0-9]{13}$/D'], |
| 12 | // China UnionPay cards start with 62 and have between 16 and 19 digits. |
| 13 | // Please note that these cards do not follow Luhn Algorithm as a checksum. |
| 14 | CardScheme::CHINA_UNIONPAY => ['/^62[0-9]{14,17}$/D'], |
| 15 | // Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits. |
| 16 | // There are Diners Club cards that begin with 5 and have 16 digits. |
| 17 | // These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard. |
| 18 | CardScheme::DINERS => ['/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/D'], |
| 19 | // Discover card numbers begin with 6011, 622126 through 622925, 644 through 649 or 65. |
| 20 | // All have 16 digits. |
| 21 | CardScheme::DISCOVER => ['/^6011[0-9]{12}$/D', '/^64[4-9][0-9]{13}$/D', '/^65[0-9]{14}$/D', '/^622(12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|91[0-9]|92[0-5])[0-9]{10}$/D'], |
| 22 | // InstaPayment cards begin with 637 through 639 and have 16 digits. |
| 23 | CardScheme::INSTAPAYMENT => ['/^63[7-9][0-9]{13}$/D'], |
| 24 | // JCB cards beginning with 2131 or 1800 have 15 digits. |
| 25 | // JCB cards beginning with 35 have 16 digits. |
| 26 | CardScheme::JCB => ['/^(?:2131|1800|35[0-9]{3})[0-9]{11}$/D'], |
| 27 | // Laser cards begin with either 6304, 6706, 6709 or 6771 and have between 16 and 19 digits. |
| 28 | CardScheme::LASER => ['/^(6304|670[69]|6771)[0-9]{12,15}$/D'], |
| 29 | // Maestro international cards begin with 675900..675999 and have between 12 and 19 digits. |
| 30 | // Maestro UK cards begin with either 500000..509999 or 560000..699999 and have between 12 and 19 digits. |
| 31 | CardScheme::MAESTRO => ['/^(6759[0-9]{2})[0-9]{6,13}$/D', '/^(50[0-9]{4})[0-9]{6,13}$/D', '/^5[6-9][0-9]{10,17}$/D', '/^6[0-9]{11,18}$/D'], |
| 32 | // All MasterCard numbers start with the numbers 51 through 55. All have 16 digits. |
| 33 | // October 2016 MasterCard numbers can also start with 222100 through 272099. |
| 34 | CardScheme::MASTERCARD => ['/^5[1-5][0-9]{14}$/D', '/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/D'], |
| 35 | // Payment system MIR numbers start with 220, then 1 digit from 0 to 4, then between 12 and 15 digits |
| 36 | CardScheme::MIR => ['/^220[0-4][0-9]{12,15}$/D'], |
| 37 | // All UATP card numbers start with a 1 and have a length of 15 digits. |
| 38 | CardScheme::UATP => ['/^1[0-9]{14}$/D'], |
| 39 | // All Visa card numbers start with a 4 and have a length of 13, 16, or 19 digits. |
| 40 | CardScheme::VISA => ['/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/D'], |
| 41 | ]; |
| 42 | public function validate($value, Constraint $constraint) |
| 43 | { |
| 44 | if (!$constraint instanceof CardScheme) { |
| 45 | throw new UnexpectedTypeException($constraint, CardScheme::class); |
| 46 | } |
| 47 | if (null === $value || '' === $value) { |
| 48 | return; |
| 49 | } |
| 50 | if (!\is_numeric($value)) { |
| 51 | $this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->setCode(CardScheme::NOT_NUMERIC_ERROR)->addViolation(); |
| 52 | return; |
| 53 | } |
| 54 | $schemes = \array_flip((array) $constraint->schemes); |
| 55 | $schemeRegexes = \array_intersect_key($this->schemes, $schemes); |
| 56 | foreach ($schemeRegexes as $regexes) { |
| 57 | foreach ($regexes as $regex) { |
| 58 | if (\preg_match($regex, $value)) { |
| 59 | return; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | $this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->setCode(CardScheme::INVALID_FORMAT_ERROR)->addViolation(); |
| 64 | } |
| 65 | } |
| 66 |