Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

invalid credit card problem FIX


SerbanG

Recommended Posts

hello

 

i have noticed that were a lot of discussions on the past about problems of validating visa and mastercard cards using the simple cc module of payment in oscommerce.

for those who seek the answer, i pasted the entire code modified, of cc_validation.php:

 

<?php
/*
 $Id: cc_validation.php,v 1.3 2003/02/12 20:43:41 hpdl Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
 ######################################
 ######################################
 #########Serban Gheorghe Ghita########
 ######[email protected]######
 #######################################
 ??FIX?? - for validation of mastercard and visa cards
*/



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(.{12}|.{15})$', $this->cc_number)) {

     $this->cc_type = 'Visa';

   } elseif (ereg('^5[1-5].{14}$', $this->cc_number)) {

     $this->cc_type = 'Master Card';

   } elseif (ereg('^3[47].{13}$', $this->cc_number)) {

     $this->cc_type = 'American Express';

   } elseif (ereg('^3(0[0-5].{11}|[68].{12})$', $this->cc_number)) {

     $this->cc_type = 'Diners Club';

   } elseif (ereg('^6011.{12}$', $this->cc_number)) {

     $this->cc_type = 'Discover';

   } elseif (ereg('^(3.{15}|(2131|1800).{11})$', $this->cc_number)) {

     $this->cc_type = 'JCB';

   } elseif (ereg('^5610.{12}$', $this->cc_number)) { 

     $this->cc_type = 'Australian BankCard';

   } else {

     $this->cc_type = 'Unknown';

   }   


/* 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);
$this->cc_number = ereg_replace('[^[:digit:]]', '', $number);
     //if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) {
  if (ereg('^4.{15}$|^4.{12}$', $this->cc_number)) {
  //^5[1-5].{14}$
  //^4.{15}$|^4.{12}$
  //[^[:digit:]]
       $this->cc_type = 'Visa';
    // } elseif (ereg('^5[1-5][0-9]{14}$', $this->cc_number)) {
 } elseif (ereg('^5[1-5].{14}$', $this->cc_number)) {
  //} elseif (ereg("^5[0-9]{16}$", $this->cc_number) || eregi("^[0-9{2}/+[0-9]{2}", $this->cc_number)) {
       $this->cc_type = 'Master Card';
     /* } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number)) {
       $this->cc_type = 'American Express';
     } 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';
 
     } 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();
  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);
   } */
 }
?>

 

 

i have test it with numerous cc-s, valids and it works, and it doesn;t create any problems that i had in the past.

i really hope this helps for some of you.

 

serban

Serban Ghita - my blog
Link to comment
Share on other sites

Um, so your "fix" is to disable the checksum validation? That doesn't sound like much of a fix to me. (Your fix also removes several card types from recognition - while that may be fine for some, it isn't relevant to the problem you claim to be solving.)

Link to comment
Share on other sites

nope, my 'fix' is ONLY for that users that seemed to have problems with validating visa and mastercard on their site, i happen to do a lot of tests and it worked for me.

 

IGNORE THIS FIX IF YOU DIDN't HAVE ANY PROBLEMS WITH CC VALIDATION

Serban Ghita - my blog
Link to comment
Share on other sites

I'm sure it did work - you disabled all the validation. The only thing you left in was determinining the card type.

 

Are there really valid Visa/MC cards out there with numbers that fail the checksum test? Seems highly implausible to me.

Link to comment
Share on other sites

hi- thank you for the fix, even if overrides the validation. for some reason one of my clients sites has been failing to validate visa and mastercard numbers for the past couple weeks more and more often though it works for me every time i run a test order with both real and random account numbers.

 

i'm guessing it's a browser issue with some clients.

 

anyway, thanks again for posting the scripting adjustment, it's a great solution for those people who proccess the charge at a later point in time anyway, if the card is bogus it will be declined then anyway:)

Link to comment
Share on other sites

thanks davis, my clients validate their customers credit cards by telephone or manual methods, si FOR THAT kind of shops is the code above.

please leave this post undeleted because some may find it usefull.

 

serban

Serban Ghita - my blog
Link to comment
Share on other sites

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 = 'Master Card';
    } elseif (ereg('^3[47][0-9]{13}$', $this->cc_number)) {
      $this->cc_type = 'American Express';
    } 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('^6759[0-9]{14}$',$this->cc_number)) { 
      $this->cc_type = 'Switch';
    } else {
      $this->cc_type = 'Unknown';
    }

 

for all major used cards, hope this helps, if not TomCavendish please show me an example of UK Switch card.

 

serban

Serban Ghita - my blog
Link to comment
Share on other sites

Many thanks serban.

 

I had a customer who couldn't make an order with a valid Mastercard. I used the code above, he tried again, and it worked!

 

Also, I had a past order which wrongly identified a VISA card as JCB. I did a test order with the number, and it worked correctly as a VISA.

 

Hopefully, Switch will work too.

 

This code needs to be included in OSC.

 

Thanks again.

 

TC.

Edited by TomCavendish
Link to comment
Share on other sites

Tom,

 

Not sure if you`ve tried it yet, but the Nochex option does every card I think now even credit cards. Your customers dont have to sign up either, they can just pay via it.

 

Another good thing is that there is 0% chargebacks which from anyones point of view is well worth using the system.

 

Worldpay is too expensive and risky as well if you have chargebacks, especially if your just starting off.

 

Right I`m going to stop babbling and goto bed, already on 5 posts in 30 mins ;)

Link to comment
Share on other sites

The code that detects card type is not magic, and it doesn't change its behavior if you try again. If it is incorrectly determining the card type, then the customer is incorrectly entering the card number. This should be obvious if it works when retried.

Link to comment
Share on other sites

  • 2 weeks later...

Has anyone found a solution for adding Maestro, Delta, Solo and Switch?

The fix is great but I am getting these cards as unknown.

I am using the first 6 digits 564182 for Switch

 

any help would be greatly appreciated

Link to comment
Share on other sites

  • 2 weeks later...

Hi all on this thread,

 

Slightly off topic, however, as a complete twit when it comes to messing with the coding on OS, rather than validating cards and having a clever module as this is.

 

Is it possible to just add a few fields to this module and remove the validation? For example, how would i add card type drop down, start date, issue number and security code etc as i have to manually perform my credit card payments anyway.

 

Even better still, has anyone any ideas on how to integrate optimal payments (firepay in disguise i think).

 

Sorry if this is a dumb question and i have ruined the thread but i am goosed at the moment with this.

 

I need a shopping cart mechanic part time, any offers?

 

Best Regards and thanks in advance

 

Paul

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...