function pay_method_gateway::set_cc_number in Pay 6
Same name and namespace in other branches
- 7 includes/handlers/pay_method_gateway.inc \pay_method_gateway::set_cc_number()
File
- includes/
handlers/ pay_method_gateway.inc, line 175 - The base class for credit card payment activities.
Class
- pay_method_gateway
- @file The base class for credit card payment activities.
Code
function set_cc_number($val) {
$this->cc_number = preg_replace('/[^\\d]/', '', $val);
// Set the credit card type rather than relying on user input.
$orig_cc_type = $this->cc_type;
$this->cc_type = NULL;
$prefix1 = substr($this->cc_number, 0, 1);
$prefix2 = substr($this->cc_number, 0, 2);
$prefix3 = substr($this->cc_number, 0, 3);
$prefix4 = substr($this->cc_number, 0, 4);
$prefix5 = substr($this->cc_number, 0, 5);
$prefix6 = substr($this->cc_number, 0, 6);
/**
* References: http://www.beachnet.com/~hstiles/cardtype.html
*/
switch ($prefix1) {
case 1:
// JCB: prefix 1800, length 15
if ($prefix4 == 1800) {
$this->cc_type = 'jcb';
}
break;
case 2:
// JCB: prefix 2131, length 15
if ($prefix4 == 2131) {
$this->cc_type = 'jcb';
}
elseif ($prefix4 == 2014) {
$this->cc_type = 'enroute';
}
elseif ($prefix4 == 2149) {
$this->cc_type = 'enroute';
}
break;
case 3:
// Diners Club: prefix 300-305, length 14
if (in_array($prefix3, array(
300,
301,
302,
303,
304,
305,
))) {
$this->cc_type = 'diners';
}
elseif (in_array($prefix2, array(
34,
37,
))) {
$this->cc_type = 'amex';
}
elseif (in_array($prefix2, array(
36,
38,
))) {
$this->cc_type = 'diners';
}
else {
$this->cc_type = 'jcb';
}
break;
case 4:
// Visa: prefix 4, length 13, 16
$this->cc_type = 'visa';
// Switch: prefix 4903, 4905, 4911, 4936
if (in_array($prefix4, array(
4903,
4905,
4911,
4936,
))) {
$this->cc_type = 'switch';
}
break;
case 5:
// Mastercard: prefix 51-55, length 16
if (in_array($prefix2, array(
51,
52,
53,
54,
55,
))) {
$this->cc_type = 'mc';
}
// Switch: prefix 564182
if ($prefix6 == 564182) {
$this->cc_type = 'switch';
}
// Maestro: prefix 5018, 5020, 5038
if (in_array($prefix4, array(
5018,
5020,
5038,
))) {
$this->cc_type = 'maestro';
}
break;
case 6:
// Discover: prefix 6011, length 16
if ($prefix4 == 6011) {
$this->cc_type = 'discover';
}
// Laser: prefix 6304 or 6706 or 6709 or 6771, length 19
if ($prefix4 == 6304 || $prefix4 == 6706 || $prefix4 == 6709 || $prefix4 == 6771) {
$this->cc_type = 'laser';
}
// Switch: prefix 633110, 6333, 6759,
if ($prefix6 == 633110 || $prefix4 == 6333) {
$this->cc_type = 'switch';
}
// Maestro: prefix 6759, 6761, 6763
if (in_array($prefix4, array(
6759,
6761,
6763,
))) {
$this->cc_type = 'maestro';
}
// Solo: prefix 6334 or 6767
if ($prefix4 == 6334 || $prefix4 == 6767) {
$this->cc_type = 'solo';
}
break;
}
// Only if we still fail to determine card type, reset it to user supplied
// value.
if (empty($this->cc_type)) {
$this->cc_type = $orig_cc_type;
}
}