Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

UK Debit Cards & cc_Validate


bettyj

Recommended Posts

Hiya -

 

This seems to be a continual problem with UK debit cards - my cc_validate file will not allow debit cards to be processed, and well frankly I just have no idea how to amend the file to add the debit card bin number ranges in.

 

The key part of cc_validate.php is currently:

 

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(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';

} else {

return -1;

 

Does anyone have the relevant range codes for Delta/Electron/Maestro/Switch & Solo?

 

I have up to date bin ranges for the cards, but as I don't even understand the format of the coding (Barely a basic php newbie!) I just don't know how to start adding them in...

 

Can anyone help with the code or decipher the above card number format info so I could have a stab at it myself?

 

Thanks everso...!

Link to comment
Share on other sites

Hi,

 

This is the code I use for one of my customers. I ripped it from a Zencart module and commented out the lines for the cards my customer didn't accept. Simply comment out the Return -1 and uncomment the card name. Just remember to backup first.

 

Hope it's ok for you.

 

Mark.

 

<?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 © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

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

 

// start of UK cards

if (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('^450875|48440[6-9]{1}|4844[1-4]{1}[0-9]{1}|48445[0-5]{1}|4917[3-5]{1}[0-9]{1}|491880([0-9]{10})?$', $this->cc_number)) {

// $this->cc_type = 'UK Electron';

Return -1;

} 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 = 'UK Switch/Maestro';

} elseif (ereg('^(6334[5-9][0-9]|(6767[0-9]{2}))[0-9]{10}([0-9]{2,3})?$', $this->cc_number)) {

// $this->cc_type = 'UK Solo';

Return -1;

// end of additional cards

} elseif (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';

Return -1;

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

// $this->cc_type = 'Diners Club';

Return -1;

} elseif (ereg('^6011[0-9]{12}$', $this->cc_number)) {

// $this->cc_type = 'Discover';

Return -1;

} elseif (ereg('^(3[0-9]{4}|2131|1800)[0-9]{11}$', $this->cc_number)) {

// $this->cc_type = 'JCB';

Return -1;

} elseif (ereg('^5610[0-9]{12}$', $this->cc_number)) {

// $this->cc_type = 'Australian BankCard';

Return -1;

} else {

$this->cc_type = 'Debit Card';

}

 

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 (strlen($this->cc_number) <= 12) {return false; }

 

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

}

}

?>

skype: mark.and.julie.edwards

Link to comment
Share on other sites

((hugs!))

 

I think this has sorted it - THANKYOU! You have no idea how long I have been battling at this .... and how releaved I now am!

 

God bless the open forum!

 

Thanks again!

Link to comment
Share on other sites

  • 2 weeks later...

:blink: Still having problems with debit payment cards using optimal payments .... but different ones!

 

I think the problem is because the Optimal Payment module I am using does not collect an issue number which is found on some debit cards.

 

The relevant code in the optimal/firepay module is:

 

<?php

#

# Payment Module SureFire Commerce via FirePay for osCommerce (
)

# Developed by mike wOZniewski,

# If you find bugs, have questions, please email mike@OZmediaSolutions.com

#

# API information, white papers, protocol info can be found at

#

# IMPORTANT NOTES FOR THIS VERSION:

# - Since FirePay does not return a message in the header, this module uses CURL to post and receive a response. This MUST be installed on your server if this module is to work (found at
.

# - You cannot use your regular account, username, and password if you are using the TEST mode; you must contact SureFire and request a test account.

# - Currencies are NOT sent to SureFire. Your SureFire account has a specific default currency, and any order totals should be in that currency.

#

# THINGS STILL TO DO:

# - Add currency conversion for order total to convert it to your SureFire default currency.

# - Modify the cc_validation.php class to accept FirePay Payments

#

class firepay {

var $code, $title, $description, $enabled;

 

// class constructor

function firepay() {

global $order;

 

$this->code = 'firepay';

$this->title = MODULE_PAYMENT_FIREPAY_TEXT_TITLE;

$this->description = MODULE_PAYMENT_FIREPAY_TEXT_DESCRIPTION;

$this->enabled = ((MODULE_PAYMENT_FIREPAY_STATUS == 'True') ? true : false);

$this->sort_order = MODULE_PAYMENT_FIREPAY_SORT_ORDER;

 

if ((int)MODULE_PAYMENT_FIREPAY_ORDER_STATUS_ID > 0) {

$this->order_status = MODULE_PAYMENT_FIREPAY_ORDER_STATUS_ID;

}

 

if (is_object($order)) $this->update_status();

 

$this->form_action_url = FILENAME_CHECKOUT_PROCESS;

}

 

// start custom firepay methods

function dp($call,$cname) {

// debug display for test mode

echo "<br/>".$cname.":<pre>";

if (!is_array($call)) $call=htmlspecialchars($call);

print_r($call);

if (is_array($call)) reset($call);

echo "</pre><hr/>\n";

}

function firepay_cardType() {

switch ($this->cc_card_type) {

case "Visa":

return "VI";

case "Master Card":

return "MC";

case "UK Electron":

return "VE";

case "UK Switch/Maestro":

return "SW";

case "UK Solo":

return "SO";

case "Delta":

return "VD";

 

}

return false;

}

// end custom firepay methods

 

// class methods

function update_status() {

global $order;

 

if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_FIREPAY_ZONE > 0) ) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_FIREPAY_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->billing['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

}

 

function javascript_validation() {

$js = ' if (payment_value == "' . $this->code . '") {' . "\n" .

' var cc_owner = document.checkout_payment.firepay_cc_owner.value;' . "\n" .

' var cc_number = document.checkout_payment.firepay_cc_number.value;' . "\n" .

////evan added on August 27 2003

' var cc_cvd = document.checkout_payment.firepay_cvd_number.value;'. "\n".

/////evan added ends

' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .

' error_message = error_message + "' . MODULE_PAYMENT_FIREPAY_TEXT_JS_CC_OWNER . '";' . "\n" .

' error = 1;' . "\n" .

' }' . "\n" .

' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .

' error_message = error_message + "' . MODULE_PAYMENT_FIREPAY_TEXT_JS_CC_NUMBER . '";' . "\n" .

' error = 1;' . "\n" .

' }' . "\n" .

////evan added on August 27 2003

' if (cc_cvd == "" || cc_cvd.length < 3 || cc_cvd.length > 4) {'."\n".

' error_message = error_message + "CVD Number not input or number of digits incorrect";'."\n".

' error = 1;'. "\n".

' }' . "\n".

///evan added ends

' }' . "\n";

 

return $js;

}

 

function selection() {

global $order;

 

for ($i=1; $i<13; $i++) {

$expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));

}

 

$today = getdate();

for ($i=$today['year']; $i < $today['year']+10; $i++) {

$expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));

}

$selection = array('id' => $this->code,

'module' => $this->title,

'fields' => array(array('title' => MODULE_PAYMENT_FIREPAY_TEXT_CREDIT_CARD_OWNER,

'field' => tep_draw_input_field('firepay_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),

array('title' => MODULE_PAYMENT_FIREPAY_TEXT_CREDIT_CARD_NUMBER,

'field' => tep_draw_input_field('firepay_cc_number')),

///evan added thte following on August 26 2003

array('title' => 'CVD <span style="font-size:10">(last 3 or 4 digits of the security number <br> on the back of your card-usually on the signature line)</span>',

'field'=> tep_draw_input_field('firepay_cvd_number')),

///evan added ends

array('title' => MODULE_PAYMENT_FIREPAY_TEXT_CREDIT_CARD_EXPIRES,

'field' => tep_draw_pull_down_menu('firepay_cc_expires_month', $expires_month) . ' ' . tep_draw_pull_down_menu('firepay_cc_expires_year', $expires_year))));

 

return $selection;

}

 

function pre_confirmation_check() {

global $HTTP_POST_VARS;

 

include(DIR_WS_CLASSES . 'cc_validation.php');

 

$cc_validation = new cc_validation();

$result = $cc_validation->validate($HTTP_POST_VARS['firepay_cc_number'], $HTTP_POST_VARS['firepay_cc_expires_month'], $HTTP_POST_VARS['firepay_cc_expires_year']);

$error = '';

switch ($result) {

case -1:

$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));

break;

case -2:

case -3:

case -4:

$error = TEXT_CCVAL_ERROR_INVALID_DATE;

break;

case false:

$error = TEXT_CCVAL_ERROR_INVALID_NUMBER;

break;

}

 

if ( ($result == false) || ($result < 1) ) {

$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&firepay_cc_owner=' . urlencode($HTTP_POST_VARS['firepay_cc_owner']) . '&firepay_cc_expires_month=' . $HTTP_POST_VARS['firepay_cc_expires_month'] . '&firepay_cc_expires_year=' . $HTTP_POST_VARS['firepay_cc_expires_year'];

 

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));

}

 

$this->cc_card_type = $cc_validation->cc_type;

$this->cc_card_number = $cc_validation->cc_number;

$this->cc_expiry_month = $cc_validation->cc_expiry_month;

$this->cc_expiry_year = $cc_validation->cc_expiry_year;

}

 

function confirmation() {

global $HTTP_POST_VARS;

 

$confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,

'fields' => array(array('title' => MODULE_PAYMENT_FIREPAY_TEXT_CREDIT_CARD_OWNER,

'field' => $HTTP_POST_VARS['firepay_cc_owner']),

array('title' => MODULE_PAYMENT_FIREPAY_TEXT_CREDIT_CARD_NUMBER,

'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),

///evan added on August 23 2003

array('title' => 'CVD Number',

'field' => $HTTP_POST_VARS['firepay_cvd_number']),

///evan added ends

array('title' => MODULE_PAYMENT_FIREPAY_TEXT_CREDIT_CARD_EXPIRES,

'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['firepay_cc_expires_month'], 1, '20' . $HTTP_POST_VARS['firepay_cc_expires_year'])))));

 

return $confirmation;

}

 

function process_button() {

global $HTTP_SERVER_VARS, $HTTP_POST_VARS, $order, $customer_id;////evan added on August 27 2003, the $HTTP_POST_VARS

 

$process_button_string = // unique transaction id number:

tep_draw_hidden_field('firepay[merchantTxn]', $customer_id . '-' . date('Ymdhis')) .

// cc info:

tep_draw_hidden_field('firepay[cardNumber]', $this->cc_card_number) .

tep_draw_hidden_field('firepay[cardType]', $this->firepay_cardType()) .

///evan added on August 27 2003

tep_draw_hidden_field('firepay[cvdValue]', $HTTP_POST_VARS['firepay_cvd_number']).

///evan added ends

tep_draw_hidden_field('firepay[cardExp]', $this->cc_expiry_month . '/' . substr($this->cc_expiry_year, -2)) .

///tep_draw_hidden_field('firepay[cvdIndicator]', '0') . // indicates that no cc security number was provided

////evan commented above line and changed it to below on August 27 2003

tep_draw_hidden_field('firepay[cvdIndicator]', '1'). //indicates cvd is provided

///evan added ends

// amount owed (in cents):

tep_draw_hidden_field('firepay[amount]', round($order->info['total'],2)*100) .

// billing info:

tep_draw_hidden_field('firepay[custName1]', $order->billing['lastname'] . ', ' . $order->customer['firstname']) .

tep_draw_hidden_field('firepay[streetAddr]', $order->billing['street_address']) .

tep_draw_hidden_field('firepay[city]', $order->billing['city']) .

tep_draw_hidden_field('firepay[province]', $order->billing['state']) .

tep_draw_hidden_field('firepay[zip]', $order->billing['postcode']) .

tep_draw_hidden_field('firepay[country]', $order->billing['country']['title']) .

tep_draw_hidden_field('firepay[phone]', $order->customer['telephone']) .

tep_draw_hidden_field('firepay

 

 

So what I ned to do is add an extra field to capture an issue number and start date if present (so not required fields).... I think!

 

Does anyone have any idea where to start? I have discussed this with the payment processor who told me it would be a simple thing for anyone with php knowledge... thanks... helpful... not!

 

...thank you ....

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.

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