Skip to content

Commit 5a3a004

Browse files
author
José D. Grieco
committed
Include brazilian cards: "hipercard" and "elo"
1 parent af3bab9 commit 5a3a004

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/CreditCard.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ class CreditCard
4444
'luhn' => true,
4545
),
4646
// Credit cards
47+
'hipercard' => array(
48+
'type' => 'hipercard',
49+
'pattern' => '/^(606282\d{10}(\d{3})?)|(3841\d{15})$/',
50+
'length' => array(13, 16, 19),
51+
'cvcLength' => array(3),
52+
'luhn' => true,
53+
),
54+
'elo' => array(
55+
'type' => 'elo',
56+
'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])/',
57+
'length' => array(16),
58+
'cvcLength' => array(3),
59+
'luhn' => true,
60+
),
4761
'visa' => array(
4862
'type' => 'visa',
4963
'pattern' => '/^4/',
@@ -131,11 +145,11 @@ public static function validDate($year, $month)
131145
{
132146
$month = str_pad($month, 2, '0', STR_PAD_LEFT);
133147

134-
if (! preg_match('/^20\d\d$/', $year)) {
148+
if (!preg_match('/^20\d\d$/', $year)) {
135149
return false;
136150
}
137151

138-
if (! preg_match('/^(0[1-9]|1[0-2])$/', $month)) {
152+
if (!preg_match('/^(0[1-9]|1[0-2])$/', $month)) {
139153
return false;
140154
}
141155

@@ -195,7 +209,7 @@ protected static function validCvcLength($cvc, $type)
195209

196210
protected static function validLuhn($number, $type)
197211
{
198-
if (! self::$cards[$type]['luhn']) {
212+
if (!self::$cards[$type]['luhn']) {
199213
return true;
200214
} else {
201215
return self::luhnCheck($number);
@@ -205,17 +219,17 @@ protected static function validLuhn($number, $type)
205219
protected static function luhnCheck($number)
206220
{
207221
$checksum = 0;
208-
for ($i=(2-(strlen($number) % 2)); $i<=strlen($number); $i+=2) {
209-
$checksum += (int) ($number{$i-1});
222+
for ($i = (2 - (strlen($number) % 2)); $i <= strlen($number); $i += 2) {
223+
$checksum += (int)($number{$i - 1});
210224
}
211225

212226
// Analyze odd digits in even length strings or even digits in odd length strings.
213-
for ($i=(strlen($number)% 2) + 1; $i<strlen($number); $i+=2) {
214-
$digit = (int) ($number{$i-1}) * 2;
227+
for ($i = (strlen($number) % 2) + 1; $i < strlen($number); $i += 2) {
228+
$digit = (int)($number{$i - 1}) * 2;
215229
if ($digit < 10) {
216230
$checksum += $digit;
217231
} else {
218-
$checksum += ($digit-9);
232+
$checksum += ($digit - 9);
219233
}
220234
}
221235

0 commit comments

Comments
 (0)