Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

invalid credit card problem FIX


15 replies to this topic

#1 zamolxe

  • Community Member
  • 20 posts
  • Real Name:Serban
  • Gender:Male
  • Location:Romania

Posted 23 May 2004, 12:09

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########
  ######webmaster@linux-magazin.ro######
  #######################################
  ??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

#2 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 23 May 2004, 13:06

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

#3 zamolxe

  • Community Member
  • 20 posts
  • Real Name:Serban
  • Gender:Male
  • Location:Romania

Posted 24 May 2004, 19:06

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

#4 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 24 May 2004, 19:19

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.

#5 John Doswell

  • Team Member
  • 456 posts
  • Real Name:John Doswell
  • Gender:Male

Posted 24 May 2004, 19:55

post deleted :ph34r:

Edited by RobinsonDixon, 24 May 2004, 19:58.


#6 davis

  • Community Member
  • 2 posts
  • Real Name:davis

Posted 31 May 2004, 23:22

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

#7 zamolxe

  • Community Member
  • 20 posts
  • Real Name:Serban
  • Gender:Male
  • Location:Romania

Posted 01 June 2004, 06:59

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

#8 TomCavendish

  • Community Member
  • 134 posts
  • Real Name:Tom

Posted 07 June 2004, 17:15

How would you add a UK Switch card to that code?

#9 zamolxe

  • Community Member
  • 20 posts
  • Real Name:Serban
  • Gender:Male
  • Location:Romania

Posted 07 June 2004, 18:31

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

#10 TomCavendish

  • Community Member
  • 134 posts
  • Real Name:Tom

Posted 08 June 2004, 14:32

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, 08 June 2004, 14:33.


#11 ScorpionWsM

  • Community Member
  • 38 posts
  • Real Name:Mark

Posted 08 June 2004, 23:18

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

#12 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 09 June 2004, 15:59

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.

#13 TomCavendish

  • Community Member
  • 134 posts
  • Real Name:Tom

Posted 18 June 2004, 15:23

Using the new code, I placed an order with Switch and it was wrongly determined as 'Unknown'. :unsure:

#14 stevel

  • Community Member
  • 2,833 posts
  • Real Name:Steve Lionel
  • Location:New Hampshire, USA

Posted 18 June 2004, 15:42

That's probably because the number was invalid, and the "new code" disables the validation. What were the first six digits?

#15 Darren2509

  • Community Member
  • 29 posts
  • Real Name:Darren Pascoe

Posted 24 June 2004, 08:03

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

#16 webcentres

  • Community Member
  • 20 posts
  • Real Name:paul white

Posted 04 July 2004, 10:46

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