Charterhouse Posted December 23, 2004 Posted December 23, 2004 Hi, We are currently testing the protx direct payment module. All cards are working fine apart from solo cards (UK). The error being display from protx confirms that the card number does not match the card type. Our validation code is as follows: class cc_validation { var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year; function validate($number, $expiry_m, $expiry_y) { $this->cc_number = ereg_replace('[^0-9]', '', $number); if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { $this->cc_type = 'Visa'; } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) { $this->cc_type = 'MC'; } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number)) { $this->cc_type = 'AMEX'; } elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->cc_number)) { $this->cc_type = 'Diners Club'; } elseif (ereg('^6011[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Discover'; } elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_number)) { $this->cc_type = 'JCB'; } elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Australian BankCard'; } elseif (ereg('^49030[2-9]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49033[5-9]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49110[1-2]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49117[4-9]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49118[0-2]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^4936[0-9]{2}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^564182([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^6333[0-4]{1}([0-9]{1})([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^6759[0-9]{2}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^6767[0-9]{2}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } else { return -1; } It would be fantastic if anybody could provide some updated code that works for solo cards. Our solo card starts with 6767 as the first four numbers. Oscommerce is treating this as a switch card. We are not sure what is the correct method of implementing this. Kind Regards, Charterhouse. Quote
Guest Posted January 31, 2005 Posted January 31, 2005 Hi, We are currently testing the protx direct payment module. All cards are working fine apart from solo cards (UK). The error being display from protx confirms that the card number does not match the card type. Our validation code is as follows: class cc_validation { var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year; function validate($number, $expiry_m, $expiry_y) { $this->cc_number = ereg_replace('[^0-9]', '', $number); if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { $this->cc_type = 'Visa'; } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) { $this->cc_type = 'MC'; } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number)) { $this->cc_type = 'AMEX'; } elseif (ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $this->cc_number)) { $this->cc_type = 'Diners Club'; } elseif (ereg('^6011[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Discover'; } elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_number)) { $this->cc_type = 'JCB'; } elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Australian BankCard'; } elseif (ereg('^49030[2-9]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49033[5-9]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49110[1-2]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49117[4-9]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^49118[0-2]{1}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^4936[0-9]{2}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^564182([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^6333[0-4]{1}([0-9]{1})([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^6759[0-9]{2}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^6767[0-9]{2}([0-9]{10,13})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } else { return -1; } It would be fantastic if anybody could provide some updated code that works for solo cards. Our solo card starts with 6767 as the first four numbers. Oscommerce is treating this as a switch card. We are not sure what is the correct method of implementing this. Kind Regards, Charterhouse. <{POST_SNAPBACK}> I've re written the regular expressions, give this a go class cc_validation { var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year; function validate($number, $expiry_m, $expiry_y) { $this->cc_number = ereg_replace('[^0-9]', '', $number); if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) { $this->cc_type = 'Visa'; } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) { $this->cc_type = 'MC'; } elseif (ereg('^3[4|7][0-9]{13}$', $this->cc_number)) { $this->cc_type = 'AMEX'; } elseif (ereg('^3[0|6|8][0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Diners Club'; } elseif (ereg('^6011[0-9]{12}$', $this->cc_number)) { $this->cc_type = 'Discover'; } elseif (ereg('^3[088|096|112|158|337|528][0-9]{12}$', $this->cc_number)) { $this->cc_type = 'JCB'; } elseif (ereg('^4(1373[3-7]|462[0-9]{2}|5397[8|9]|54313|5443[2-5]|54742|567(2[5-9]|3[0-9]|4[0-5])|658[3-7][0-9]|659(0[1-9]|[1-4][0-9]|50)|844[09|10]|909[6-7][0-9]|9218[1|2]|98824)[0-9]{10}$', $this->cc_number)) { $this->cc_type = 'Delta'; } elseif (ereg('^(49030[2-9]|49033[5-9]|49110[1-2]|4911(7[4-9]|8[1-2])|4936[0-9]{2}|564182|6333[0-4][0-9]|6759[0-9]{2})[0-9]{10}([0-9]{2,3})?$', $this->cc_number)) { $this->cc_type = 'Switch'; } elseif (ereg('^(6334[5-9][0-9]|(6767[0-9]{2}))[0-9]{10}([0-9]{2,3})?$', $this->cc_number)) { $this->cc_type = 'Solo'; } else { return -1; } if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) { $this->cc_expiry_month = $expiry_m; } else { return -2; } $current_year = date('Y'); $expiry_y = substr($current_year, 0, 2) . $expiry_y; if (is_numeric($expiry_y) && ($expiry_y >= $current_year) && ($expiry_y <= ($current_year + 10))) { $this->cc_expiry_year = $expiry_y; } else { return -3; } if ($expiry_y == $current_year) { if ($expiry_m < date('n')) { return -4; } } return $this->is_valid(); } function is_valid() { $cardNumber = strrev($this->cc_number); $numSum = 0; for ($i=0; $i<strlen($cardNumber); $i++) { $currentNum = substr($cardNumber, $i, 1); // Double every second digit if ($i % 2 == 1) { $currentNum *= 2; } // Add digits of 2-digit numbers together if ($currentNum > 9) { $firstNum = $currentNum % 10; $secondNum = ($currentNum - $firstNum) / 10; $currentNum = $firstNum + $secondNum; } $numSum += $currentNum; } // If the total has no remainder it's OK return ($numSum % 10 == 0); } } ?> lemme know if there are any probs, ive only had time to test it on a limited number of cards. SOLO works for sure should be good to go though cheers ben Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.