Everytime I try to check out I get an error that the credit card has expired even tho I know its a good credit card...
I have looked this over but cannot find the mistake. Here is the routine I am using below. Any help would be great! Thanks in advance!
---------------Start of File--------------
<?php
class ccCheck
{
var $ccType = '';
var $ccNum = '';
var $ccExpM = 0;
var $ccExpY = 0;
/* intial check for cc validity */
function intCheck($var)
{
$lang['cc']['ccType_err'] = "<font color='#FF0000'><b>Invalid credit card type!</b></font>";
$lang['cc']['ccNum_err'] = "<font color='#FF0000'><b>Invalid credit card number!</b></font>";
$lang['cc']['ccExp_err'] = "<font color='#FF0000'><b>credit card has expired!</b></font>";
switch ($var['ccType'])
{
case mc:
$this->ccType = MASTERCARD;
break;
case vs:
$this->ccType = VISA;
break;
case ax:
$this->ccType = AMEX;
break;
case dc:
$this->ccType = DINERS_CLUB;
break;
default:
return $lang['cc']['ccType_err'];
break;
}
$cardNum = str_replace(" ", "", $var['ccNum']);
if(is_numeric($cardNum))
{
$this->ccNum = $cardNum;
} else {
return $lang['cc']['ccNum_err'];
}
if($var['ccMonth'] >= date("m") && $var['ccYear'] >= date("Y"))
{
$this->ccExpM = $var['ccMonth'];
$this->ccExpY = $var['ccYear'];
} else {
return $lang['cc']['ccExp_err'];
}
return $this->validateCard();
}
/* validate cc number */
function validateCard()
{
$lang['cc']['ccSel_err'] = "<font color='#FF0000'><b>Please select appropriate credit card type!</b></font>";
$lang['cc']['ccInv_err'] = "<font color='#FF0000'><b>Credit card not valid!</b></font>";
switch($this->ccType)
{
case MASTERCARD:
$ccValid = ereg("^5[1-5][0-9]{14}$", $this->ccNum);
break;
case VISA:
$ccValid = ereg("^4[0-9]{12}([0-9]{3})?$", $this->ccNum);
break;
case AMEX:
$ccValid = ereg("^3[47][0-9]{13}$", $this->ccNum);
break;
case DINERS_CLUB:
$ccValid = ereg("^3(0[0-5]|[68][0-9])[0-9]{11}$", $this->ccNum);
break;
default:
$ccValid = false;
break;
}
if($ccValid=true)
{
$newCC_Num = strrev($this->ccNum);
$str_len = strlen($newCC_Num);
for($i = 0; $str_len > $i; $i++) {
$cc_Num = substr($newCC_Num, $i, 1);
//double every second number by 2
if($i % 2 hahahaha 1) {
$cc_Num *= 2;
}
//if strlen 1 add first and second numbers
if(strlen($cc_Num)>1) {
$cc_Num = substr($cc_Num, 0, 1) + substr($cc_Num, 1, 1);
}
$ccNum += $cc_Num;
}
if(($ccNum % 10)hahahaha0)
return 'cc_valid';
else
return $lang['cc']['ccInv_err'];
} else {
return $lang['cc']['ccSel_err'];
}
}
function menuSel()
{
$types_array = array('ax' => 'American Express', 'mc' => 'MasterCard', 'vs' =>'Visa');
foreach($types_array as $var => $ref) {
$return['ccTypes'] .= "<option value='".$var."'>".$ref."</option>";
}
for($i = 1; $i <= 12; $i++) {
strlen($i)hahahaha1 ? $i = '0'.$i : $i = $i;
$return['expMth'] .= "<option value='".$i."'>".$i."</option>";
}
$yr = date('Y');
for($i = 0; $i <= 10; $i++) {
$exp_yr = $yr + $i;
$return['expYR'] .= "<option value='".$exp_yr."'>".$exp_yr."</option>";
}
return $return;
}
}
?>
I have looked this over but cannot find the mistake. Here is the routine I am using below. Any help would be great! Thanks in advance!
---------------Start of File--------------
<?php
class ccCheck
{
var $ccType = '';
var $ccNum = '';
var $ccExpM = 0;
var $ccExpY = 0;
/* intial check for cc validity */
function intCheck($var)
{
$lang['cc']['ccType_err'] = "<font color='#FF0000'><b>Invalid credit card type!</b></font>";
$lang['cc']['ccNum_err'] = "<font color='#FF0000'><b>Invalid credit card number!</b></font>";
$lang['cc']['ccExp_err'] = "<font color='#FF0000'><b>credit card has expired!</b></font>";
switch ($var['ccType'])
{
case mc:
$this->ccType = MASTERCARD;
break;
case vs:
$this->ccType = VISA;
break;
case ax:
$this->ccType = AMEX;
break;
case dc:
$this->ccType = DINERS_CLUB;
break;
default:
return $lang['cc']['ccType_err'];
break;
}
$cardNum = str_replace(" ", "", $var['ccNum']);
if(is_numeric($cardNum))
{
$this->ccNum = $cardNum;
} else {
return $lang['cc']['ccNum_err'];
}
if($var['ccMonth'] >= date("m") && $var['ccYear'] >= date("Y"))
{
$this->ccExpM = $var['ccMonth'];
$this->ccExpY = $var['ccYear'];
} else {
return $lang['cc']['ccExp_err'];
}
return $this->validateCard();
}
/* validate cc number */
function validateCard()
{
$lang['cc']['ccSel_err'] = "<font color='#FF0000'><b>Please select appropriate credit card type!</b></font>";
$lang['cc']['ccInv_err'] = "<font color='#FF0000'><b>Credit card not valid!</b></font>";
switch($this->ccType)
{
case MASTERCARD:
$ccValid = ereg("^5[1-5][0-9]{14}$", $this->ccNum);
break;
case VISA:
$ccValid = ereg("^4[0-9]{12}([0-9]{3})?$", $this->ccNum);
break;
case AMEX:
$ccValid = ereg("^3[47][0-9]{13}$", $this->ccNum);
break;
case DINERS_CLUB:
$ccValid = ereg("^3(0[0-5]|[68][0-9])[0-9]{11}$", $this->ccNum);
break;
default:
$ccValid = false;
break;
}
if($ccValid=true)
{
$newCC_Num = strrev($this->ccNum);
$str_len = strlen($newCC_Num);
for($i = 0; $str_len > $i; $i++) {
$cc_Num = substr($newCC_Num, $i, 1);
//double every second number by 2
if($i % 2 hahahaha 1) {
$cc_Num *= 2;
}
//if strlen 1 add first and second numbers
if(strlen($cc_Num)>1) {
$cc_Num = substr($cc_Num, 0, 1) + substr($cc_Num, 1, 1);
}
$ccNum += $cc_Num;
}
if(($ccNum % 10)hahahaha0)
return 'cc_valid';
else
return $lang['cc']['ccInv_err'];
} else {
return $lang['cc']['ccSel_err'];
}
}
function menuSel()
{
$types_array = array('ax' => 'American Express', 'mc' => 'MasterCard', 'vs' =>'Visa');
foreach($types_array as $var => $ref) {
$return['ccTypes'] .= "<option value='".$var."'>".$ref."</option>";
}
for($i = 1; $i <= 12; $i++) {
strlen($i)hahahaha1 ? $i = '0'.$i : $i = $i;
$return['expMth'] .= "<option value='".$i."'>".$i."</option>";
}
$yr = date('Y');
for($i = 0; $i <= 10; $i++) {
$exp_yr = $yr + $i;
$return['expYR'] .= "<option value='".$exp_yr."'>".$exp_yr."</option>";
}
return $return;
}
}
?>

Comment