X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   User Friendly Credit Card Field Mod (https://forum.x-cart.com/showthread.php?t=26982)

sstillwell@aerostich.com 11-29-2006 11:09 AM

User Friendly Credit Card Field Mod
 
In his book "Don't Make Me Think" by Steve Krug (go read it), he states things that Diminish the Good Will of our customers.

"Punishing me for not doing things your way. I should never have to think about formatting data: whether or not to put dashes in my Social Security number, spaces in my credit card number, or parentheses in my phone number. Many sites perversely insist on no spaces in credit card numbers, when the spaces actually make it much easier to get the number right. Don't make me jump through hoops just because you don't want to write a little bit of code."

So, in the default Xcart install, the credit card field has these words.

Credit card number (no spaces or dashes)

Why don't we just implement some Javascript that strips out the none numbers when they try to submit. EASY.

Obligatory Disclaimers
1. I am using Credit Card verification, I don't think this will work without enabling that.
2. I use 4.0.12, it may be fixed in a new version.
3. This could completely destroy your Xcart store (but probably not).

Ready?

Open skin1/check_cc_number_script.tpl

Change this code
Code:

function checkCCNumber(field_cc,field_accepted) {
        var cc=field_cc.value;
        var accepted=null;
        if(field_accepted!=null)
            accepted=new Array(card_types[field_accepted.value]);
        if (isCreditCard(cc,accepted))
            return true;
          else {
                alert(txt_cc_number_invalid);
                field_cc.focus();
                field_cc.select();
                return false;
        }
}


To this code
Code:

function checkCCNumber(field_cc,field_accepted) {
        var original_cc=field_cc.value;
        var cc=field_cc.value.replace(/[^\d]/g, '');
        var accepted=null;
        if(field_accepted!=null)
            accepted=new Array(card_types[field_accepted.value]);
        if (isCreditCard(cc,accepted)){
                field_cc.value = cc;
                    return true;
          }else {
                alert(txt_cc_number_invalid);
                field_cc.focus();
                field_cc.select();
                return false;
        }
}


Basically, this just strips out the none numbers from the Credit card number and then if it passes the check, writes it back to the Credit Card input field before proceeding to submit the form.

Man that was easy.

ryan c. 11-29-2006 06:38 PM

Re: User Friendly Credit Card Field Mod
 
WOW That was easy! and works like a charm.

Thanks!@

ryan c. 08-14-2007 10:10 AM

Re: User Friendly Credit Card Field Mod
 
can this work in 4.1 seems the Open skin1/check_cc_number_script.tpl has changed

Sisom 08-18-2007 01:24 PM

Re: User Friendly Credit Card Field Mod
 
I'd like to use this too, I have 4.1.0.
The code is now in /check_cc_number_script.js
not/check_cc_number_script.tpl

The code is as follows:

/*
Check CC number
*/
function checkCCNumber(field_cc, field_accepted) {
var cc = field_cc.value;
var accepted = (field_accepted != null) ? [card_types[field_accepted.value]] : null;

if (isCreditCard(cc, accepted))
return true;

alert(txt_cc_number_invalid);
field_cc.focus();
field_cc.select();
return false;
}



I tried this, but it didn't work:

/*
Check CC number
*/
function checkCCNumber(field_cc, field_accepted) {
var original_cc=field_cc.value;
var cc=field_cc.value.replace(/[^\d]/g, '');
var accepted = (field_accepted != null) ? [card_types[field_accepted.value]] : null;

if (isCreditCard(cc, accepted)){
field_cc.value = cc;
return true;
}else {
alert(txt_cc_number_invalid);
field_cc.focus();
field_cc.select();
return false;
}
}

If anybody could fix this it would be very useful, can anybody help?

jeanne 01-09-2008 01:07 PM

Re: User Friendly Credit Card Field Mod
 
Works as posted previously in 4.1 using cc verification.
File is different - you need to change the function in

skin1/check_cc_number_script.js

sk8conz 01-09-2008 02:30 PM

Re: User Friendly Credit Card Field Mod
 
Works fine in 4.1.9

rhu 02-23-2008 03:49 PM

Re: User Friendly Credit Card Field Mod
 
This looks like a very useful mod, but how do you enable credit card verification?

bullfrog 02-24-2008 10:28 AM

Re: User Friendly Credit Card Field Mod
 
When (if?) you get a merchant account and gateway, and the gateway is properly set up in X-cart, the credit card verification will happen automatically. In Admin, go to 'Payment methods'. Look at the pulldown menu at the bottom where you select a payment gateway.

The merchant account is who charges your customers and sends the money to you. The gateway account is who verifies that the card is good and sends the authorization to charge to the merchant account. For some accounts, the merchant and gateway are the same.

If you don't have card verification, and customer can type in anything for a card number, including text and spaces, and X-cart will accept it.

rhu 02-24-2008 03:13 PM

Re: User Friendly Credit Card Field Mod
 
Thank You bullfrog!

EN4U 02-24-2008 09:35 PM

Re: User Friendly Credit Card Field Mod
 
Nice..I was looking to do this to mine, yet the code you say to change, doesnt match up to what mine is now......So im unsure what to do

This what mine shows

{* $Id: check_cc_number_script.tpl,v 1.21.2.1 2007/09/12 12:21:17 ferz Exp $ *}
<script type="text/javascript" language="JavaScript 1.2">
<!--
var card_types = new Array();
var card_cvv2 = new Array();
{foreach from=$card_types item=c}
card_types["{$c.code}"] = "{$c.type}";
card_cvv2["{$c.code}"] = "{$c.cvv2}";
{/foreach}
var force_cvv2 = {if $payment_cc_data.disable_ccinfo eq "N" && ($config.General.check_cc_number eq "Y" || $smarty.get.mode eq 'checkout')}true{else}false{/if};
var txt_cc_number_invalid = "{$lng.txt_cc_number_invalid|strip_tags|escape:jav ascript}";
var current_year = parseInt(('{$smarty.now|date_format:"%Y"}').replac e(/^0/gi, ""));
var current_month = parseInt(('{$smarty.now|date_format:"%m"}').replac e(/^0/gi, ""));
var lbl_is_this_card_expired = "{$lng.lbl_is_this_card_expired|strip_tags|escape: javascript}";
var lbl_cvv2_is_empty = "{$lng.lbl_cvv2_is_empty|escape:javascript}";
var lbl_cvv2_isnt_correct = "{$lng.lbl_cvv2_isnt_correct|escape:javascript }";
var lbl_cvv2_must_be_number = "{$lng.lbl_cvv2_must_be_number|escape:javascript}" ;
-->
</script>
{include file="main/include_js.tpl" src="check_cc_number_script.js"}

jeanne 02-25-2008 06:21 PM

Re: User Friendly Credit Card Field Mod
 
Look in

skin1/check_cc_number_script.js

instead

hebs 05-04-2008 02:58 AM

Re: User Friendly Credit Card Field Mod
 
for 4.1.9

in skin1/check_cc_number_script.js

Replace:
HTML Code:


function checkCCNumber(field_cc, field_accepted) {
    var cc = field_cc.value;
    var accepted = (field_accepted != null) ? [card_types[field_accepted.value]] : null;

    if (isCreditCard(cc, accepted))
        return true;

    alert(txt_cc_number_invalid);
    field_cc.focus();
    field_cc.select();
    return false;
}


with this (as per 1st post):

HTML Code:


function checkCCNumber(field_cc,field_accepted) {
    var original_cc=field_cc.value;
    var cc=field_cc.value.replace(/[^\d]/g, '');
    var accepted=null;
    if(field_accepted!=null)
        accepted=new Array(card_types[field_accepted.value]);
    if (isCreditCard(cc,accepted)){
        field_cc.value = cc;
            return true;
      }else {
        alert(txt_cc_number_invalid);
        field_cc.focus();
        field_cc.select();
        return false;
    }
}


works great! :D/

EN4U 05-04-2008 07:11 AM

Re: User Friendly Credit Card Field Mod
 
Quote:

Originally Posted by hebs
for 4.1.9

in skin1/check_cc_number_script.js

Replace:
HTML Code:


function checkCCNumber(field_cc, field_accepted) {
    var cc = field_cc.value;
    var accepted = (field_accepted != null) ? [card_types[field_accepted.value]] : null;

    if (isCreditCard(cc, accepted))
        return true;

    alert(txt_cc_number_invalid);
    field_cc.focus();
    field_cc.select();
    return false;
}


with this (as per 1st post):

HTML Code:


function checkCCNumber(field_cc,field_accepted) {
    var original_cc=field_cc.value;
    var cc=field_cc.value.replace(/[^\d]/g, '');
    var accepted=null;
    if(field_accepted!=null)
        accepted=new Array(card_types[field_accepted.value]);
    if (isCreditCard(cc,accepted)){
        field_cc.value = cc;
            return true;
      }else {
        alert(txt_cc_number_invalid);
        field_cc.focus();
        field_cc.select();
        return false;
    }
}


works great! :D/


would this still be viable to use if you have the mod "one page checkout" ?


All times are GMT -8. The time now is 03:36 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.