19
19
*/
20
20
class CreditCard
21
21
{
22
+ const BRAND_VISA = 'visa ' ;
23
+ const BRAND_MASTERCARD = 'mastercard ' ;
24
+ const BRAND_DISCOVER = 'discover ' ;
25
+ const BRAND_AMEX = 'amex ' ;
26
+ const BRAND_DINERS_CLUB = 'diners_club ' ;
27
+ const BRAND_JCB = 'jcb ' ;
28
+ const BRAND_SWITCH = 'switch ' ;
29
+ const BRAND_SOLO = 'solo ' ;
30
+ const BRAND_DANKORT = 'dankort ' ;
31
+ const BRAND_MAESTRO = 'maestro ' ;
32
+ const BRAND_FORBRUGSFORENINGEN = 'forbrugsforeningen ' ;
33
+ const BRAND_LASER = 'laser ' ;
34
+
22
35
/**
23
36
* @var \Symfony\Component\HttpFoundation\ParameterBag
24
37
*/
@@ -34,6 +47,35 @@ public function __construct($parameters = null)
34
47
$ this ->initialize ($ parameters );
35
48
}
36
49
50
+ /**
51
+ * All known/supported card brands, and a regular expression to match them.
52
+ *
53
+ * The order of the card brands is important, as some of the regular expressions overlap.
54
+ *
55
+ * Note: The fact that this class knows about a particular card brand does not imply
56
+ * that your gateway supports it.
57
+ *
58
+ * @return array
59
+ * @link https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb
60
+ */
61
+ public function getSupportedBrands ()
62
+ {
63
+ return array (
64
+ static ::BRAND_VISA => '/^4\d{12}(\d{3})?$/ ' ,
65
+ static ::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$/ ' ,
66
+ static ::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/ ' ,
67
+ static ::BRAND_AMEX => '/^3[47]\d{13}$/ ' ,
68
+ static ::BRAND_DINERS_CLUB => '/^3(0[0-5]|[68]\d)\d{11}$/ ' ,
69
+ static ::BRAND_JCB => '/^35(28|29|[3-8]\d)\d{12}$/ ' ,
70
+ static ::BRAND_SWITCH => '/^6759\d{12}(\d{2,3})?$/ ' ,
71
+ static ::BRAND_SOLO => '/^6767\d{12}(\d{2,3})?$/ ' ,
72
+ static ::BRAND_DANKORT => '/^5019\d{12}$/ ' ,
73
+ static ::BRAND_MAESTRO => '/^(5[06-8]|6\d)\d{10,17}$/ ' ,
74
+ static ::BRAND_FORBRUGSFORENINGEN => '/^600722\d{10}$/ ' ,
75
+ static ::BRAND_LASER => '/^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/ ' ,
76
+ );
77
+ }
78
+
37
79
/**
38
80
* Initialize the object with parameters.
39
81
*
@@ -138,6 +180,22 @@ public function setNumber($value)
138
180
return $ this ->setParameter ('number ' , preg_replace ('/\D/ ' , '' , $ value ));
139
181
}
140
182
183
+ /**
184
+ * Credit Card Brand
185
+ *
186
+ * Iterates through known/supported card brands to determine the brand of this card
187
+ *
188
+ * @return string
189
+ */
190
+ public function getBrand ()
191
+ {
192
+ foreach ($ this ->getSupportedBrands () as $ brand => $ val ) {
193
+ if (preg_match ($ val , $ this ->getNumber ())) {
194
+ return $ brand ;
195
+ }
196
+ }
197
+ }
198
+
141
199
public function getExpiryMonth ()
142
200
{
143
201
return $ this ->getParameter ('expiryMonth ' );
@@ -218,16 +276,6 @@ public function setIssueNumber($value)
218
276
return $ this ->setParameter ('issueNumber ' , $ value );
219
277
}
220
278
221
- public function getType ()
222
- {
223
- return $ this ->getParameter ('type ' );
224
- }
225
-
226
- public function setType ($ value )
227
- {
228
- return $ this ->setParameter ('type ' , $ value );
229
- }
230
-
231
279
public function getBillingAddress1 ()
232
280
{
233
281
return $ this ->getParameter ('billingAddress1 ' );
0 commit comments