Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

CC_Validation errors after installing CVV module


AvanRaak

Recommended Posts

Posted

Hey guys,

 

I just installed the Credit Card with CVV2 Version v2 module to prompt for the 3 digit cvv number.

I went through all of the steps, and all of the payment functions still work, but when I try to put through my CC to test it, I get this:

 

Parse error: parse error, unexpected '{' in /home/content/m/o/r/morpheusseed/html/monsb/catalog/includes/classes/cc_validation.php on line 57

 

 

My cc_validation.php files is as follows:

 

<?php

/*

$Id: cc_validation.php 1739 2007-12-20 00:52:16Z hpdl $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class cc_validation {

var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year, $cc_cvv2;

 

function validate($number, $expiry_m, $expiry_y, $cvv2) {

$this->cc_number = preg_replace('/[^0-9]/', '', $number);

 

if (preg_match('/^4[0-9]{12}([0-9]{3})?$/', $this->cc_number)) {

$this->cc_type = 'Visa';

} elseif (preg_match('/^5[1-5][0-9]{14}$/', $this->cc_number)) {

$this->cc_type = 'Master Card';

} elseif (preg_match('/^3[47][0-9]{13}$/', $this->cc_number)) {

$this->cc_type = 'American Express';

} 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;

}

}

 

if ((MODULE_PAYMENT_CC_CVV2 == 'True') && in_array($this->cc_type, array('Visa', 'Master Card', 'American Express', 'Diners Club', 'JCB', 'Discover')) { // using CVV and card is known to have CVV

if ((strlen($cvv2) < 3) || (strlen($cvv2) > 4)) return -5; // bad length

if (($this->cc_type == 'American Express') && (strlen($cvv2) != 4)) return -6; // wrong length for AMEX

if (($this->cc_type != 'American Express') && (strlen($cvv2) != 3)) return -7; // wrong length for others

}

 

// list all credit card types accepted in the $accepted_cards array

$accepted_cards = array('Visa', 'Master Card');

if (!in_array($this->cc_type, $accepted_cards) return -8; //card type not in list of accepted cards

 

return $this->is_valid();

return true;

}

 

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);

}

}

?>

 

 

 

Any help would be greatly appreciated, as right now I cannot process any cards on my sites :(

 

Amanda

Posted

Hi Try this

 


<?php
/*
$Id: cc_validation.php 1739 2007-12-20 00:52:16Z hpdl $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright © 2003 osCommerce

Released under the GNU General Public License
*/

class cc_validation {
var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year, $cc_cvv2;

function validate($number, $expiry_m, $expiry_y, $cvv2) {
$this->cc_number = preg_replace('/[^0-9]/', '', $number);

if (preg_match('/^4[0-9]{12}([0-9]{3})?$/', $this->cc_number)) {
$this->cc_type = 'Visa';
} elseif (preg_match('/^5[1-5][0-9]{14}$/', $this->cc_number)) {
$this->cc_type = 'Master Card';
} elseif (preg_match('/^3[47][0-9]{13}$/', $this->cc_number)) {
$this->cc_type = 'American Express';
} 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;
}
}

if ((MODULE_PAYMENT_CC_CVV2 == 'True') && in_array($this->cc_type, array('Visa', 'Master Card', 'American Express', 'Diners Club', 'JCB', 'Discover'))) { // using CVV and card is known to have CVV
if ((strlen($cvv2) < 3) || (strlen($cvv2) > 4)) return -5; // bad length
if (($this->cc_type == 'American Express') && (strlen($cvv2) != 4)) return -6; // wrong length for AMEX
if (($this->cc_type != 'American Express') && (strlen($cvv2) != 3)) return -7; // wrong length for others
}

// list all credit card types accepted in the $accepted_cards array
$accepted_cards = array('Visa', 'Master Card');
if (!in_array($this->cc_type, $accepted_cards)) return -8; //card type not in list of accepted cards

return $this->is_valid();
return true;
}

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);
}
}
?>

 

 

Nic

Sometimes you're the dog and sometimes the lamp post

[/url]

My Contributions

Posted

Thank you so much, that got my CC module working again.

However, the instigator of this whole thing, being the CVV module, does not appear to be working.

There is no prompt for the 3 digit CVV, nor the 'what's this' option.

I've gone over the installation steps again, and made sure that the files that needed to be uploaded are in place, but it doesn't seem to work.

Anyone have any ideas?

 

Amanda

 

 

Hi Try this

 


<?php
/*
$Id: cc_validation.php 1739 2007-12-20 00:52:16Z hpdl $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright © 2003 osCommerce

Released under the GNU General Public License
*/

class cc_validation {
var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year, $cc_cvv2;

function validate($number, $expiry_m, $expiry_y, $cvv2) {
$this->cc_number = preg_replace('/[^0-9]/', '', $number);

if (preg_match('/^4[0-9]{12}([0-9]{3})?$/', $this->cc_number)) {
$this->cc_type = 'Visa';
} elseif (preg_match('/^5[1-5][0-9]{14}$/', $this->cc_number)) {
$this->cc_type = 'Master Card';
} elseif (preg_match('/^3[47][0-9]{13}$/', $this->cc_number)) {
$this->cc_type = 'American Express';
} 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;
}
}

if ((MODULE_PAYMENT_CC_CVV2 == 'True') && in_array($this->cc_type, array('Visa', 'Master Card', 'American Express', 'Diners Club', 'JCB', 'Discover'))) { // using CVV and card is known to have CVV
if ((strlen($cvv2) < 3) || (strlen($cvv2) > 4)) return -5; // bad length
if (($this->cc_type == 'American Express') && (strlen($cvv2) != 4)) return -6; // wrong length for AMEX
if (($this->cc_type != 'American Express') && (strlen($cvv2) != 3)) return -7; // wrong length for others
}

// list all credit card types accepted in the $accepted_cards array
$accepted_cards = array('Visa', 'Master Card');
if (!in_array($this->cc_type, $accepted_cards)) return -8; //card type not in list of accepted cards

return $this->is_valid();
return true;
}

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);
}
}
?>

 

 

Nic

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...