Skip to content

Commit 8ffffbc

Browse files
faytekinDarkaOnLine
authored andcommitted
Add Troy card (#28)
1 parent b09107d commit 8ffffbc

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/Cards/Troy.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 Troy extends Card implements CreditCard
8+
{
9+
/**
10+
* Regular expression for card number recognition.
11+
*
12+
* @var string
13+
*/
14+
public static $pattern = '/^9(?!(79200|79289))/'; // 979200 and 979289 are starts for Troy
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 = 'troy';
29+
30+
/**
31+
* Brand name.
32+
*
33+
* @var string
34+
*/
35+
protected $brand = 'Troy';
36+
37+
/**
38+
* Card number length's.
39+
*
40+
* @var array
41+
*/
42+
protected $number_length = [16];
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
@@ -5,6 +5,7 @@
55
use LVR\CreditCard\Cards\Jcb;
66
use LVR\CreditCard\Cards\Mir;
77
use LVR\CreditCard\Cards\Visa;
8+
use LVR\CreditCard\Cards\Troy;
89
use LVR\CreditCard\Cards\Dankort;
910
use LVR\CreditCard\Cards\Maestro;
1011
use LVR\CreditCard\Cards\UnionPay;
@@ -35,6 +36,7 @@ class Factory
3536
UnionPay::class,
3637
Visa::class,
3738
Mir::class,
39+
Troy::class,
3840
];
3941

4042
/**

tests/Unit/Cards/TroyTest.php

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

0 commit comments

Comments
 (0)