Checkout does not work with Credit Card payment method in Magento 1.4.1.0
The Magento team has changed the way credit card numbers are validated in Magento version 1.4.1.0. The new method requires an additional JS include in your page.xml.
<action method="addJs"><script>lib/ccard.js</script></action>
The new file is located at /js/lib/ccard.js. The contents are pretty simple:
// Credit Card Validation Javascript
// copyright 12th May 2003, by Stephen Chapman, Felgall Pty Ltd
// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.
function validateCreditCard(s) {
// remove non-numerics
var v = "0123456789";
var w = "";
for (i=0; i < s.length; i++) {
x = s.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
// validate number
j = w.length / 2;
k = Math.floor(j);
m = Math.ceil(j) - k;
c = 0;
for (i=0; i<k; i++) {
a = w.charAt(i*2+m) * 2;
c += a > 9 ? Math.floor(a/10 + a%10) : a;
}
for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
return (c%10 == 0);
}
If you update to Magento 1.4.1.0 and your theme does not include this file, your checkout will not work for credit card payment methods. When a Credit Card payment method is selected, the one page checkout will not proceed past the payment section. The continue button will not be clickable, rendering your Credit Card payment method completely unusable.
The solution is to add this new JS include in two places in your /app/design/frontend/default/[YourThemeName]/layout/page.xml
The first is in the default layout <block type="page/html_head" name="head" as="head"> section around line 37.
<block type="page/html_head" name="head" as="head"> <action method="addJs"><script>prototype/prototype.js</script></action> <action method="addJs" ifconfig="dev/js/deprecation"><script>prototype/deprecation.js</script></action> <action method="addJs"><script>lib/ccard.js</script></action> <action method="addJs"><script>prototype/validation.js</script></action> <action method="addJs"><script>scriptaculous/builder.js</script></action> <action method="addJs"><script>scriptaculous/effects.js</script></action> <action method="addJs"><script>scriptaculous/dragdrop.js</script></action> <action method="addJs"><script>scriptaculous/controls.js</script></action> <action method="addJs"><script>scriptaculous/slider.js</script></action> <action method="addJs"><script>varien/js.js</script></action> <action method="addJs"><script>varien/form.js</script></action> <action method="addJs"><script>varien/menu.js</script></action> <action method="addJs"><script>mage/translate.js</script></action> <action method="addJs"><script>mage/cookies.js</script></action> <action method="addCss"><stylesheet>css/styles.css</stylesheet></action> <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action> <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action> <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action> <action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action> <action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action> </block>
The second place you need to add this JS file is in the print section <block type="page/html_head" name="head" as="head"> around line 113.
<block type="page/html_head" name="head" as="head"> <action method="addJs"><script>prototype/prototype.js</script></action> <action method="addJs"><script>mage/translate.js</script></action> <action method="addJs"><script>lib/ccard.js</script></action> <action method="addJs"><script>prototype/validation.js</script></action> <action method="addJs"><script>varien/js.js</script></action> <action method="addCss"><stylesheet>css/styles.css</stylesheet></action> <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action> <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action> <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action> <action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action> <action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action> </block>
Adding the new JS include in these two places should fix the checkout problem.
We have updated all of our themes and plugins with this new method to ensure proper checkout functionality on Magento 1.4.1.0.
If you need assistance updating your theme, please contact us.



August 10th, 2010 - 07:38
Thank you very much! this article really saved me
September 12th, 2010 - 19:56
Thank you for your article. Th E article references the card.js located in it’s default file. When custom templates are installed what directory should this file be moved to? Or in other words, what is the path of the file directory for this file, when using a custom template?
September 13th, 2010 - 08:43
The path for the ccard.js file stays the same no matter what custom theme you may be using.
[Magento root directory]/js/lib/ccard.js
September 21st, 2010 - 16:01
This didn’t seem to work for me : (
October 4th, 2010 - 00:55
its not working on me…
October 4th, 2010 - 00:56
by the way the validation of javascript seems to work… the problem is its not continuing to order review….
October 4th, 2010 - 00:57
In some site this one working but the site im currently facing isn’t any idea?
October 13th, 2010 - 04:23
Very helpful info. Thank you.
November 12th, 2010 - 10:07
I did all of the above but still nothing happens when I click continue. Can you help any further??
November 16th, 2010 - 19:17
You are a savior! That works for me.
December 21st, 2010 - 17:38
I’m having this same issue with Magento 1.4.0.1
I added the line of code in page.xml for both my custom theme and the default theme (it was not there)
but it is still not working. My question is, if the path to the file is /js/li/… then why does the include not include the /js/ ?
Should it maybe be js/lib/ccard.js ?
December 21st, 2010 - 20:08
Disregard the previous comment. I was able to solve this finally. I guess Magento 1.4.0.1 did not have the ccard.js file in the js/lib/ folder. So if that is the version you are running check to see if you have the file. I was able to grab it by downloading the latest stable version of Magento and then I just uploaded it via ftp. Worked like a charm. I’m not ready to upgrad to 1.4.2 yet though. I’m afraid it will break 10 other things.
December 24th, 2010 - 01:53
if above code is not working for you than you can add validateCreditCard(s) function at the last of your prototype/validation.js file.
if it work let me know..
December 27th, 2010 - 19:21
GREAT!!
WOrkeddd magically for mee.. tho make sure you FLUSH urr JavaScript and Magento Cache and REFRESH from the admin panel..den everything works perfectly!!
THANK A WHOLE WORLD!!
February 3rd, 2011 - 17:56
Thank you!
February 4th, 2011 - 05:22
A great Idea!
You must FLUSH urr JavaScript and Magento Cache and REFRESH from the admin panel..den everything works perfectly!!
February 9th, 2011 - 20:52
hey, seriously..
thanks for this info! i have my magento upgrade working thanks to you!
i upgraded from 1.4.0.1 to 1.4.2 with a manual upgrade.
you saved me a ton of time.
thanks!
March 21st, 2011 - 15:03
I was screaming like a crazy idiot and running around my office because I couldn’t figure this out until I found this article. OMG Thank you!
March 22nd, 2011 - 10:29
Genius. Worked perfectly!
March 28th, 2011 - 14:06
hey I can use some help, every time i past in the CC validation code into the validation.js my “state” field on my check out page disappears and from there doesn’t allow me to proceed with out entering a state. Any suggestions / answers? I’m loosing my mind any help will be greatly appreciated!