From 5a3a004707fd3ca928118e0d6b90de8b742ffc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20D=2E=20Grieco?= Date: Sat, 19 Mar 2016 18:58:47 -0300 Subject: [PATCH 1/3] Include brazilian cards: "hipercard" and "elo" --- src/CreditCard.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index ce8f5d6..2964ef1 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -44,6 +44,20 @@ class CreditCard 'luhn' => true, ), // Credit cards + 'hipercard' => array( + 'type' => 'hipercard', + 'pattern' => '/^(606282\d{10}(\d{3})?)|(3841\d{15})$/', + 'length' => array(13, 16, 19), + 'cvcLength' => array(3), + 'luhn' => true, + ), + 'elo' => array( + 'type' => 'elo', + 'pattern' => '/^(4011(7[89])?)|43(1274|8935)|45(1416|7393|76(31|32)?)|50(4175|6699|67[0-7][0-8]|9\d{3})|627780|636(297|368|369)|6500(3([1-3]|[5-9])|4\d{1}|5[01])|650(4(0[5-9]|[1-3]\d{1}|8[5-9]|9\d{1})|5([0-2]\d{1}|3[0-8]|4[1-9]|5\d{1}|[6-8]\d{1}|9[0-8])|7(0\d{1}|1[0-8]|2[0-7])|9(0[1-9]|1\d{1}|20))|6516(5[2-9]|6\d{1}|7[0-9])|6550([01]\d{1}|2[1-9]|[34]\d{1}|5[0-8])/', + 'length' => array(16), + 'cvcLength' => array(3), + 'luhn' => true, + ), 'visa' => array( 'type' => 'visa', 'pattern' => '/^4/', @@ -131,11 +145,11 @@ public static function validDate($year, $month) { $month = str_pad($month, 2, '0', STR_PAD_LEFT); - if (! preg_match('/^20\d\d$/', $year)) { + if (!preg_match('/^20\d\d$/', $year)) { return false; } - if (! preg_match('/^(0[1-9]|1[0-2])$/', $month)) { + if (!preg_match('/^(0[1-9]|1[0-2])$/', $month)) { return false; } @@ -195,7 +209,7 @@ protected static function validCvcLength($cvc, $type) protected static function validLuhn($number, $type) { - if (! self::$cards[$type]['luhn']) { + if (!self::$cards[$type]['luhn']) { return true; } else { return self::luhnCheck($number); @@ -205,17 +219,17 @@ protected static function validLuhn($number, $type) protected static function luhnCheck($number) { $checksum = 0; - for ($i=(2-(strlen($number) % 2)); $i<=strlen($number); $i+=2) { - $checksum += (int) ($number{$i-1}); + for ($i = (2 - (strlen($number) % 2)); $i <= strlen($number); $i += 2) { + $checksum += (int)($number{$i - 1}); } // Analyze odd digits in even length strings or even digits in odd length strings. - for ($i=(strlen($number)% 2) + 1; $i Date: Wed, 23 Aug 2017 13:03:09 -0300 Subject: [PATCH 2/3] Update Hipercard and Elo validation pattern --- .gitignore | 1 + src/CreditCard.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3a6fe9c..391ec7e 100755 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ composer.lock /build /vendor +.idea/ diff --git a/src/CreditCard.php b/src/CreditCard.php index 2964ef1..371525f 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -46,14 +46,14 @@ class CreditCard // Credit cards 'hipercard' => array( 'type' => 'hipercard', - 'pattern' => '/^(606282\d{10}(\d{3})?)|(3841\d{15})$/', + 'pattern' => '/^((606282|637095|637568)[0-9]{10}|38[0-9]{14,17})$$/', 'length' => array(13, 16, 19), 'cvcLength' => array(3), 'luhn' => true, ), 'elo' => array( 'type' => 'elo', - 'pattern' => '/^(4011(7[89])?)|43(1274|8935)|45(1416|7393|76(31|32)?)|50(4175|6699|67[0-7][0-8]|9\d{3})|627780|636(297|368|369)|6500(3([1-3]|[5-9])|4\d{1}|5[01])|650(4(0[5-9]|[1-3]\d{1}|8[5-9]|9\d{1})|5([0-2]\d{1}|3[0-8]|4[1-9]|5\d{1}|[6-8]\d{1}|9[0-8])|7(0\d{1}|1[0-8]|2[0-7])|9(0[1-9]|1\d{1}|20))|6516(5[2-9]|6\d{1}|7[0-9])|6550([01]\d{1}|2[1-9]|[34]\d{1}|5[0-8])/', + 'pattern' => '/^((50670[7-8])|(506715)|(50671[7-9])|(50672[0-1])|(50672[4-9])|(50673[0-3])|(506739)|(50674[0-8])|(50675[0-3])|(50677[4-8])|(50900[0-9])|(50901[3-9])|(50902[0-9])|(50903[1-9])|(50904[0-9])|(50905[0-9])|(50906[0-4])|(50906[6-9])|(50907[0-2])|(50907[4-5])|(636368)|(636297)|(504175)|(438935)|(40117[8-9])|(45763[1-2])|(457393)|(431274)|(50907[6-9])|(50908[0-9])|(627780))/', 'length' => array(16), 'cvcLength' => array(3), 'luhn' => true, From 230ce6a54f03904c5ef28dab2160d5fb4c09b32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Domingos=20Grieco?= Date: Sat, 10 Feb 2018 17:02:32 -0200 Subject: [PATCH 3/3] Remove Hiper BIN --- src/CreditCard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CreditCard.php b/src/CreditCard.php index 371525f..fe8cca0 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -46,7 +46,7 @@ class CreditCard // Credit cards 'hipercard' => array( 'type' => 'hipercard', - 'pattern' => '/^((606282|637095|637568)[0-9]{10}|38[0-9]{14,17})$$/', + 'pattern' => '/^((606282|637568)[0-9]{10}|38[0-9]{14,17})$$/', 'length' => array(13, 16, 19), 'cvcLength' => array(3), 'luhn' => true,