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