From 43961a6aed010578cf3b4732bf5db6f63c7130fc Mon Sep 17 00:00:00 2001 From: Mykhailo Chekhivskyi Date: Tue, 23 Oct 2018 13:45:12 +0300 Subject: [PATCH 1/9] =?UTF-8?q?Added=20credit=20card=20type=20MIR.=20INN?= =?UTF-8?q?=20range:=202200=E2=80=932204.=20Length:=2016.=20Wiki:=20https:?= =?UTF-8?q?//en.wikipedia.org/wiki/Mir=5F(payment=5Fsystem)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CreditCard.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/CreditCard.php b/src/CreditCard.php index ce8f5d6..4ef8821 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -43,6 +43,13 @@ class CreditCard 'cvcLength' => array(3), 'luhn' => true, ), + 'mir' => array( + 'type' => 'mir', + 'pattern' => '/^220[0-4]/', + 'length' => array(16), + 'cvcLength' => array(3), + 'luhn' => true, + ), // Credit cards 'visa' => array( 'type' => 'visa', From f4a16634a88a0141e683df94aedb5f257951265d Mon Sep 17 00:00:00 2001 From: Mykhailo Chekhivskyi Date: Tue, 6 Nov 2018 15:02:22 +0200 Subject: [PATCH 2/9] Added credit card type MIR Tests --- tests/Test.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Test.php b/tests/Test.php index 00f35c2..fd34200 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -26,6 +26,13 @@ class Test extends PHPUnit_Framework_TestCase 'dankort' => array( '5019717010103742', ), + 'mir' => array( + '2200524572467853', + '2201338708835472', + '2202410737880339', + '2203027541752030', + '2204500360586886', + ), // Credit cards 'visa' => array( From 6f157ad93cba069f0b2e4aca1d1614c1ca2b7da0 Mon Sep 17 00:00:00 2001 From: Mykhailo Chekhivskyi Date: Thu, 15 Nov 2018 11:52:20 +0200 Subject: [PATCH 3/9] Added validation details if not valid and up php version to 5.6 --- .gitignore | 2 ++ composer.json | 2 +- src/CreditCard.php | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3a6fe9c..558daab 100755 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ composer.lock /build /vendor + +/.idea/ \ No newline at end of file diff --git a/composer.json b/composer.json index dec0e6b..6781330 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=5.6.0", "lib-pcre": ">=7.3" }, "require-dev": { diff --git a/src/CreditCard.php b/src/CreditCard.php index 4ef8821..1be1b3c 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -126,6 +126,12 @@ public static function validCreditCard($number, $type = null) ); } + $ret['validation'] = array( + 'pattern' => (bool)self::validPattern($number, $type), + 'length' => self::validLength($number, $type), + 'luhn' => self::validLuhn($number, $type), + ); + return $ret; } From d76fe8a0ee7a1bd00ebf2beffecb8081419edb33 Mon Sep 17 00:00:00 2001 From: Mykhailo Chekhivskyi Date: Thu, 15 Nov 2018 12:05:12 +0200 Subject: [PATCH 4/9] Fixed validation details --- src/CreditCard.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index 1be1b3c..b700865 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -127,9 +127,9 @@ public static function validCreditCard($number, $type = null) } $ret['validation'] = array( - 'pattern' => (bool)self::validPattern($number, $type), - 'length' => self::validLength($number, $type), - 'luhn' => self::validLuhn($number, $type), + 'pattern' => !empty($type) && self::validPattern($number, $type), + 'length' => !empty($type) && self::validLength($number, $type), + 'luhn' => !empty($type) && self::validLuhn($number, $type), ); return $ret; From 6971b02e55ad77e68cce912d8ac7c1193a8ef367 Mon Sep 17 00:00:00 2001 From: Mykhailo Chekhivskyi Date: Tue, 5 Mar 2019 10:15:03 +0200 Subject: [PATCH 5/9] Fixed validation details --- src/CreditCard.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index b700865..500c192 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -127,9 +127,9 @@ public static function validCreditCard($number, $type = null) } $ret['validation'] = array( - 'pattern' => !empty($type) && self::validPattern($number, $type), - 'length' => !empty($type) && self::validLength($number, $type), - 'luhn' => !empty($type) && self::validLuhn($number, $type), + 'pattern' => self::validPattern($number, $type), + 'length' => self::validLength($number, $type), + 'luhn' => self::validLuhn($number, $type), ); return $ret; From 1a4a592f20237ef69b209b64df3d6ed2633f5046 Mon Sep 17 00:00:00 2001 From: Mykhailo Chekhivskyi Date: Mon, 11 Mar 2019 10:12:25 +0200 Subject: [PATCH 6/9] Fixed validation with empty type --- src/CreditCard.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index 500c192..b700865 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -127,9 +127,9 @@ public static function validCreditCard($number, $type = null) } $ret['validation'] = array( - 'pattern' => self::validPattern($number, $type), - 'length' => self::validLength($number, $type), - 'luhn' => self::validLuhn($number, $type), + 'pattern' => !empty($type) && self::validPattern($number, $type), + 'length' => !empty($type) && self::validLength($number, $type), + 'luhn' => !empty($type) && self::validLuhn($number, $type), ); return $ret; From 10d04f4f6728552bc15f239816bb53e2be27ce46 Mon Sep 17 00:00:00 2001 From: arkadiylysenko Date: Fri, 13 Dec 2019 12:38:56 +0200 Subject: [PATCH 7/9] add public method to determine credit card type --- src/CreditCard.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/CreditCard.php b/src/CreditCard.php index b700865..12723b1 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -174,6 +174,17 @@ protected static function creditCardType($number) return ''; } + /** + * @param string $bin + * @return string|null + */ + public static function determineCreditCardType($bin) + { + $type = self::creditCardType($bin); + + return !empty($type) ? $type : null; + } + protected static function validCard($number, $type) { return (self::validPattern($number, $type) && self::validLength($number, $type) && self::validLuhn($number, $type)); From 596c86b84be996d1971dea90d3685ca61798288e Mon Sep 17 00:00:00 2001 From: arkadiylysenko Date: Thu, 19 Dec 2019 12:33:34 +0200 Subject: [PATCH 8/9] add new card networks --- src/CreditCard.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index 12723b1..43abe60 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -89,7 +89,7 @@ class CreditCard ), 'unionpay' => array( 'type' => 'unionpay', - 'pattern' => '/^(62|88)/', + 'pattern' => '/^(62|81)/', 'length' => array(16, 17, 18, 19), 'cvcLength' => array(3), 'luhn' => false, @@ -101,6 +101,20 @@ class CreditCard 'cvcLength' => array(3), 'luhn' => true, ), + 'uatp' => array( + 'type' => 'uatp', + 'pattern' => '/^1/', + 'length' => array(15), + 'cvcLength' => array(3), + 'luhn' => true, + ), + 'rupay' => array( + 'type' => 'rupay', + 'pattern' => '/^(60|6521|6522)/', + 'length' => array(16), + 'cvcLength' => array(3), + 'luhn' => true, + ), ); public static function validCreditCard($number, $type = null) From 75c3965c97712eeb33733f260964354ce0e5159d Mon Sep 17 00:00:00 2001 From: vskuba Date: Wed, 23 Nov 2022 12:00:03 +0200 Subject: [PATCH 9/9] CAS-287: add_prefer_brand --- src/CreditCard.php | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index 43abe60..8f8673b 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -174,31 +174,48 @@ public static function validDate($year, $month) return true; } - // PROTECTED - // --------------------------------------------------------- - - protected static function creditCardType($number) + /** + * @param string $number + * @param string|null $preferBrand + * + * @return string + */ + protected static function creditCardType($number, $preferBrand = null) { + $matched = []; + foreach (self::$cards as $type => $card) { if (preg_match($card['pattern'], $number)) { - return $type; + $matched[] = $type; } } - return ''; + if (!empty($preferBrand) && in_array($preferBrand, $matched)) { + return $preferBrand; + } + + return isset($matched[0]) ? $matched[0] : ''; } /** - * @param string $bin - * @return string|null + * @param string $bin + * @param string|null $preferBrand + * + * @return null|string */ - public static function determineCreditCardType($bin) + public static function determineCreditCardType($bin, $preferBrand = null) { - $type = self::creditCardType($bin); + $type = self::creditCardType($bin, $preferBrand); return !empty($type) ? $type : null; } + /** + * @param $number + * @param $type + * + * @return bool + */ protected static function validCard($number, $type) { return (self::validPattern($number, $type) && self::validLength($number, $type) && self::validLuhn($number, $type));