Skip to content

Commit 5b4bb12

Browse files
hugofabricioDarkaOnLine
authored andcommitted
Added new card type: Hipercard (#15)
* Added new card type: Hipercard * Update linter * Update * Update tests * Update tests
1 parent dd48253 commit 5b4bb12

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

src/Cards/Hipercard.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace LVR\CreditCard\Cards;
4+
5+
use LVR\CreditCard\Contracts\CreditCard;
6+
7+
class Hipercard extends Card implements CreditCard
8+
{
9+
/**
10+
* Regular expression for card number recognition.
11+
*
12+
* @var string
13+
*/
14+
public static $pattern = '/^(606282\d{10}(\d{3})?)|(3841\d{15})/';
15+
16+
/**
17+
* Credit card type.
18+
*
19+
* @var string
20+
*/
21+
protected $type = 'credit';
22+
23+
/**
24+
* Credit card name.
25+
*
26+
* @var string
27+
*/
28+
protected $name = 'hipercard';
29+
30+
/**
31+
* Brand name.
32+
*
33+
* @var string
34+
*/
35+
protected $brand = 'Hipercard';
36+
37+
/**
38+
* Card number length's.
39+
*
40+
* @var array
41+
*/
42+
protected $number_length = [13, 16, 19];
43+
44+
/**
45+
* CVC code length's.
46+
*
47+
* @var array
48+
*/
49+
protected $cvc_length = [3];
50+
51+
/**
52+
* Test cvc code checksum against Luhn algorithm.
53+
*
54+
* @var bool
55+
*/
56+
protected $checksum_test = true;
57+
}

src/Factory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use LVR\CreditCard\Cards\Maestro;
1010
use LVR\CreditCard\Cards\UnionPay;
1111
use LVR\CreditCard\Cards\Discovery;
12+
use LVR\CreditCard\Cards\Hipercard;
1213
use LVR\CreditCard\Cards\DinersClub;
1314
use LVR\CreditCard\Cards\Mastercard;
1415
use LVR\CreditCard\Cards\VisaElectron;
@@ -29,6 +30,7 @@ class Factory
2930
DinersClub::class,
3031
Discovery::class,
3132
Jcb::class,
33+
Hipercard::class,
3234
Mastercard::class,
3335
UnionPay::class,
3436
Visa::class,

tests/Unit/Cards/BaseCardTests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ abstract class BaseCardTests extends TestCase
2828
DinersClubTest::class,
2929
DiscoveryTest::class,
3030
JcbTest::class,
31+
HipercardTest::class,
3132
MastercardTest::class,
3233
UnionPayTest::class,
3334
VisaTest::class,

tests/Unit/Cards/HipercardTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace LVR\CreditCard\Tests\Unit\Cards;
4+
5+
use Illuminate\Support\Collection;
6+
use LVR\CreditCard\Cards\Hipercard;
7+
8+
class HipercardTest extends BaseCardTests
9+
{
10+
public $instance = Hipercard::class;
11+
12+
/**
13+
* @return \Illuminate\Support\Collection
14+
*/
15+
public function validNumbers(): Collection
16+
{
17+
return collect([
18+
'6062826043427285',
19+
'6062820114738720',
20+
'6062820090765804',
21+
]);
22+
}
23+
24+
/**
25+
* @return \Illuminate\Support\Collection
26+
*/
27+
public function numbersWithInvalidLength(): Collection
28+
{
29+
return collect([
30+
'60628260434272857',
31+
]);
32+
}
33+
34+
/**
35+
* @return \Illuminate\Support\Collection
36+
*/
37+
public function numbersWithInvalidCheckSum(): Collection
38+
{
39+
return collect([
40+
'5121647321685222',
41+
]);
42+
}
43+
}

0 commit comments

Comments
 (0)