Remember me? forgot password | register

SilverStripe Forum

4559 Posts in 1020 Topics by 651 members

Jump to:

Extending and hacking

If this is your first visit, you will need to register before you can post. However, you can browse all messages below.

Community » SilverStripe Forum » Extending and hacking » Credit Card Validation
Page: 1 go to end Reply
Author Topic: Credit Card Validation 711 views
  • Dig
    Dig's avatar
    Community Member
    15 posts

    Credit Card Validation Link to this post

    I have just made a working SecurePayTech module for ecommerce based of the DPS module. I have some javascript for client-side credit card validation, something that securepaytech prefers people to do.

    Where do I put this in order to have is triggered either:
    1. On leaving the creditcard field, like it currently shows a 'this field is required' message.
    or
    2. Prior to submit, again triggering a warning message.

    I've looked through the existing javascript, but don't think I'm up to speed with Behaviours etc., to pinpoint where it does what.

    Cheers,
    Nick

  • Double-A-Ron
    avatar
    Community Member
    149 posts
    1 SilverStripe Site

    Re: Credit Card Validation Link to this post

    This thread will probably help you: http://www.silverstripe.com/site-builders-forum/flat/1369

  • kez
    kez's avatar
    Community Member
    2 posts

    Re: Credit Card Validation Link to this post

    hi there

    I am also very interested in this....

    Have you managed to get it working well?

    From SilverStripe to SecurePayTech and back again?

    Is there a chance of forwarding your code?

    Many thanks!

    Last edited: 8 July 2008 at 10:50pm

  • Dig
    Dig's avatar
    Community Member
    15 posts

    Re: Credit Card Validation Link to this post

    I'm still in the process of testing and integrating, if I have a suitable version working (hopefully this week, securepaytech are testing it at the moment) I'll post it.

    Can't guarantee it meets silverstripe's code guidelines, but if it works I'll let you all know :)

    Nick

  • kez
    kez's avatar
    Community Member
    2 posts

    Re: Credit Card Validation Link to this post

    brilliant - Thanks!

    I will hold off reinventing the wheel.... Still looking around for another lightweight ecommerce gpl system that will easily integrate with securepaytech without too much effort....

    Need to get a ecommerce site up fast with minimal product and minimal effort....

    Any ideas welcome!

  • Dig
    Dig's avatar
    Community Member
    15 posts

    Re: Credit Card Validation Link to this post

    Attached is the securepaytech payment file I've managed to get working. I've merged my ecommerce code with the svn version so I'm not 100% sure it'll work for everyone but should at least give you a good place to start.

    Add the following line to mysite/_config.php with the correct details

    SecurePayTechPayment::set_account('merchantID', 'password');

    I ended up using Director::forceSSL() in order to get SSL working, which is across the whole site, not just the payment pages.

    Two additional javascript functions I've added (to Checkout.js) and use in this file:

    paymarkVerify();

    Is the same as the implementation in the SecurePayTech integration guide, just pops up a window with the right merchantID for verification purposes.

    requireValidCC(fieldName);

    this is a new validation function that works just the same as require() in /sapphire/javascript/Validator.js except it checks for a valid credit card number. Listing for this is below, add it to Checkout.js or anywhere that suits/works :):


    function requireValidCC(fieldName) {
             el = _CURRENT_FORM.elements[fieldName];
             
             if (!checkCC(el.value)) {
                validationError(el,"Please enter a valid credit card number","required",false);
                return false;
             } else {
             if(!hasHadFormError()) {
                clearErrorMessage(el.parentNode);
             }
             return true;         
             }
    }

    function checkCC(s) {

    var i, n, c, r, t;

    r = "";
    for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
    r = c + r;
    }

    if (r.length <= 1)
    return false;

    t = "";
    for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
    c *= 2;
    t = t + c;
    }

    n = 0;
    for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
    }

    if (n != 0 && n % 10 == 0)
    return true;
    else
    return false;
    }

    I'm using a Modified version of the latest release of silverstripe along with a modified version of the svn version of ecommerce so results may vary widely!

    Enjoy.

    Last edited: 9 July 2008 at 11:39am

    Attached Files
    711 views
go to top Reply

Currently Online:

Cyl, Luca, Harl, mhull, Singh, vivianurvi

Welcome to our latest member: vivianurvi