16Jul/1020

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&lt;k; i++) {
a = w.charAt(i*2+m) * 2;
c += a &gt; 9 ? Math.floor(a/10 + a%10) : a;
}
for (i=0; i&lt;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.

About Jason Detamore

Jason is a talented and experienced website developer specializing in frontend development and usability. Jason oversees MagThemes' theme development and customer service and has been working with Magento since version 0.9.
Comments (20) Trackbacks (0)
  1. Thank you very much! this article really saved me

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

  3. This didn’t seem to work for me : (

  4. its not working on me…

  5. by the way the validation of javascript seems to work… the problem is its not continuing to order review….

  6. In some site this one working but the site im currently facing isn’t any idea? :(

  7. I did all of the above but still nothing happens when I click continue. Can you help any further??

  8. You are a savior! That works for me.

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

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

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

  12. GREAT!! :D WOrkeddd magically for mee.. tho make sure you FLUSH urr JavaScript and Magento Cache and REFRESH from the admin panel..den everything works perfectly!! :D

    THANK A WHOLE WORLD!! :)

  13. A great Idea!
    You must FLUSH urr JavaScript and Magento Cache and REFRESH from the admin panel..den everything works perfectly!!

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

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

  16. Genius. Worked perfectly!

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


Leave a comment


No trackbacks yet.