1 | <?php |
||
13 | abstract class Card |
||
14 | { |
||
15 | /** |
||
16 | * Regular expression for card number recognition. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | public static $pattern; |
||
21 | |||
22 | /** |
||
23 | * Credit card type: "debit", "credit". |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $type; |
||
28 | |||
29 | /** |
||
30 | * Credit card name. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $name; |
||
35 | |||
36 | /** |
||
37 | * Brand name. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $brand; |
||
42 | |||
43 | /** |
||
44 | * Card number length's. |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $number_length; |
||
49 | |||
50 | /** |
||
51 | * CVC code length's. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $cvc_length; |
||
56 | |||
57 | /** |
||
58 | * Test cvc code checksum against Luhn algorithm. |
||
59 | * |
||
60 | * @var bool |
||
61 | */ |
||
62 | protected $checksum_test; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private $card_number; |
||
68 | |||
69 | /** |
||
70 | * Card constructor. |
||
71 | * |
||
72 | * @param string $card_number |
||
73 | * |
||
74 | * @throws \LVR\CreditCard\Exceptions\CreditCardException |
||
75 | */ |
||
76 | 95 | public function __construct(string $card_number = '') |
|
84 | |||
85 | /** |
||
86 | * @param string $card_number |
||
87 | * |
||
88 | * @return $this |
||
89 | * @throws \LVR\CreditCard\Exceptions\CreditCardPatternException |
||
90 | */ |
||
91 | 67 | public function setCardNumber(string $card_number) |
|
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | * @throws \LVR\CreditCard\Exceptions\CreditCardChecksumException |
||
109 | * @throws \LVR\CreditCard\Exceptions\CreditCardException |
||
110 | * @throws \LVR\CreditCard\Exceptions\CreditCardLengthException |
||
111 | */ |
||
112 | 55 | public function isValidCardNumber() |
|
132 | |||
133 | /** |
||
134 | * @return string |
||
135 | */ |
||
136 | 11 | public function type() |
|
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | public function name() |
||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | public function brand() |
||
156 | |||
157 | /** |
||
158 | * @param $cvc |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | 1 | public function isValidCvc($cvc) |
|
167 | |||
168 | /** |
||
169 | * Check CVS length against possible lengths. |
||
170 | * |
||
171 | * @param string|int $cvc |
||
172 | * |
||
173 | * @param array $available_lengths |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | 2 | public static function isValidCvcLength($cvc, array $available_lengths = [3, 4]) |
|
183 | |||
184 | /** |
||
185 | * @throws \LVR\CreditCard\Exceptions\CreditCardException |
||
186 | */ |
||
187 | 95 | protected function checkImplementation() |
|
221 | |||
222 | /** |
||
223 | * @return bool |
||
224 | */ |
||
225 | 67 | protected function validPattern() |
|
229 | |||
230 | /** |
||
231 | * @return bool |
||
232 | */ |
||
233 | 44 | protected function validLength() |
|
237 | |||
238 | /** |
||
239 | * @return bool |
||
240 | */ |
||
241 | 33 | protected function validChecksum() |
|
245 | |||
246 | /** |
||
247 | * @return bool |
||
248 | */ |
||
249 | 31 | protected function checksumTest() |
|
268 | } |
||
269 |