@@ -105,6 +105,32 @@ class CreditCard
105
105
const BRAND_FORBRUGSFORENINGEN = 'forbrugsforeningen ' ;
106
106
const BRAND_LASER = 'laser ' ;
107
107
108
+ /**
109
+ * All known/supported card brands, and a regular expression to match them.
110
+ *
111
+ * The order of the card brands is important, as some of the regular expressions overlap.
112
+ *
113
+ * Note: The fact that a particular card brand has been added to this array does not imply
114
+ * that a selected gateway will support the card.
115
+ *
116
+ * @link https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb
117
+ * @var array
118
+ */
119
+ protected $ supported_cards = array (
120
+ self ::BRAND_VISA => '/^4\d{12}(\d{3})?$/ ' ,
121
+ self ::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$/ ' ,
122
+ self ::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/ ' ,
123
+ self ::BRAND_AMEX => '/^3[47]\d{13}$/ ' ,
124
+ self ::BRAND_DINERS_CLUB => '/^3(0[0-5]|[68]\d)\d{11}$/ ' ,
125
+ self ::BRAND_JCB => '/^35(28|29|[3-8]\d)\d{12}$/ ' ,
126
+ self ::BRAND_SWITCH => '/^6759\d{12}(\d{2,3})?$/ ' ,
127
+ self ::BRAND_SOLO => '/^6767\d{12}(\d{2,3})?$/ ' ,
128
+ self ::BRAND_DANKORT => '/^5019\d{12}$/ ' ,
129
+ self ::BRAND_MAESTRO => '/^(5[06-8]|6\d)\d{10,17}$/ ' ,
130
+ self ::BRAND_FORBRUGSFORENINGEN => '/^600722\d{10}$/ ' ,
131
+ self ::BRAND_LASER => '/^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/ ' ,
132
+ );
133
+
108
134
/**
109
135
* Internal storage of all of the card parameters.
110
136
*
@@ -125,30 +151,39 @@ public function __construct($parameters = null)
125
151
/**
126
152
* All known/supported card brands, and a regular expression to match them.
127
153
*
128
- * The order of the card brands is important, as some of the regular expressions overlap.
129
- *
130
154
* Note: The fact that this class knows about a particular card brand does not imply
131
155
* that your gateway supports it.
132
156
*
157
+ * @see self::$supported_cards
133
158
* @return array
134
- * @link https://github.com/Shopify/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb
135
159
*/
136
160
public function getSupportedBrands ()
137
161
{
138
- return array (
139
- static ::BRAND_VISA => '/^4\d{12}(\d{3})?$/ ' ,
140
- static ::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$/ ' ,
141
- static ::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/ ' ,
142
- static ::BRAND_AMEX => '/^3[47]\d{13}$/ ' ,
143
- static ::BRAND_DINERS_CLUB => '/^3(0[0-5]|[68]\d)\d{11}$/ ' ,
144
- static ::BRAND_JCB => '/^35(28|29|[3-8]\d)\d{12}$/ ' ,
145
- static ::BRAND_SWITCH => '/^6759\d{12}(\d{2,3})?$/ ' ,
146
- static ::BRAND_SOLO => '/^6767\d{12}(\d{2,3})?$/ ' ,
147
- static ::BRAND_DANKORT => '/^5019\d{12}$/ ' ,
148
- static ::BRAND_MAESTRO => '/^(5[06-8]|6\d)\d{10,17}$/ ' ,
149
- static ::BRAND_FORBRUGSFORENINGEN => '/^600722\d{10}$/ ' ,
150
- static ::BRAND_LASER => '/^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/ ' ,
151
- );
162
+ return $ this ->supported_cards ;
163
+ }
164
+
165
+ /**
166
+ * Set a custom supported card brand with a regular expression to match it.
167
+ *
168
+ * Note: The fact that a particular card is known does not imply that your
169
+ * gateway supports it.
170
+ *
171
+ * Set $add_to_front to true if the key should be added to the front of the array
172
+ *
173
+ * @param string $name The name of the new supported brand.
174
+ * @param string $expression The regular expression to check if a card is supported.
175
+ * @return boolean success
176
+ */
177
+ public function addSupportedBrand ($ name , $ expression )
178
+ {
179
+ $ known_brands = array_keys ($ this ->supported_cards );
180
+
181
+ if (in_array ($ name , $ known_brands )) {
182
+ return false ;
183
+ }
184
+
185
+ $ this ->supported_cards [$ name ] = $ expression ;
186
+ return true ;
152
187
}
153
188
154
189
/**
0 commit comments