PDA

View Full Version : authorizenet aim module: missing javascript_validation function?



earth-friendly
08-05-2009, 05:00 PM
When I checkout using the authorize.net aim module, I noticed that if I leave out the credit card number, it doesn't give me a popup window with an error message, it just appears to try to process the credit card, and then it gives me a generic error message:
"Please try again and if problems persist, please try another payment method."
In the authorize.net aim module I was using in an older version of oscmax, it would give a popup message:
Please fix the following errors:
* The credit card number must be at least 10 characters.

So I looked a little deeper, and I see that in the older module, in
includes/modules/payment/authorizenet.php, there was a function javascript_validation, which did some error checking and presumably generated a javascript function to check for these types of errors.

In the newer module, in includes/modules/payment/authorizenet_cc_aim.php, the function javascript_validation just returns false. In fact, it looks like in most or all of the payment module files, the function javascript_validation just returns false.

Is there a reason that this javascript validation was taken out? Can I easily put it back in? I realize that this authorize.net module is a different one, so it would need some tweaking. But it just seems much more useful to give the user a descriptive popup message describing the information that they forgot to enter.

Thanks very much!
Regards,
-Lori-

earth-friendly
08-05-2009, 05:36 PM
Looking into things a little more, perhaps because the checkout process has changed, and the cc info is entered on the checkout_confirmation page, javascript_validation is no longer used in the same way? I think the javascript checking here would be nice, but if that is not do-able, then at least, it would be nice if the error message that showed up was more specific.

In the current payment module cc.php, I see that in the function before_process, it uses the class cc_validation, and checks for valid credit card number and expiration date. Perhaps I could just add that into the before_process function in authorizenet_cc_aim.php? Is there a reason that cc_validation is not used here? It was used in the older authorize.net module.

Thanks in advance for your help! I'm just trying to get a good user experience for my customers.

Regards,
-Lori-

earth-friendly
08-05-2009, 08:14 PM
Sorry for bugging everyone with my questions. I've gotten this to work for me, so I thought I'd share it, in case it can help anyone else. I don't guarantee that this will work for everyone, but it does work for me. Be sure to back up your files before making any changes.
Please note: the credit goes to the people who designed the original authorize.net modules and cc.php module. I just pulled out the pieces and put things together.

1) In includes/languages/english/modules/payment/authorizenet_cc_aim.php:
Right before the line:
define('MODULE_PAYMENT_AUTHORIZENET_CC_AIM_ERROR_E XPIRED', 'The credit card has expired. Please try again with another card or payment method.');
add:
// BOF: LEFP
define('MODULE_PAYMENT_AUTHORIZENET_CC_AIM_ERROR_I NVALID_NUMBER', 'The credit card number is invalid. Please check the card information and try again.');
define('MODULE_PAYMENT_AUTHORIZENET_CC_AIM_ERROR_C ARD_TYPE_MISMATCH', 'The credit card type you\'ve chosen does not match the credit card number entered. Please check the card information and try again.');
// EOF: LEFP

2) in includes/modules/payment/authorizenet_cc_aim.php
a)
In the function before_process, right after the global declaration at the top:
global $HTTP_POST_VARS, $customer_id, $order, $sendto, $currency;
Add the following code:
// BOF: LEFP
// Add in credit card validation check from cc.php,
// but modify it to include a symbol for the error,
// rather than a long string,
// in the error url.
include(DIR_WS_CLASSES . 'cc_validation.php');

$cc_validation = new cc_validation();
$result = $cc_validation->validate($HTTP_POST_VARS['cc_number_nh-dns'], $HTTP_POST_VARS['cc_expires_month'], $HTTP_POST_VARS['cc_expires_year'], $HTTP_POST_VARS['cc_cvc_nh-dns'], $HTTP_POST_VARS['credit_card_type']);
$error = '';
switch ($result) {
case -1:
$error = 'invalid_cc_number';
break;
case -2:
case -3:
case -4:
$error = 'invalid_expiration_date';
break;
case -5:
$error = 'type_mismatch';
break;
case -6:
$error = 'cvc';
break;
case false:
$error = 'invalid_cc_number';
break;
}

if ( ($result == false) || ($result < 1) ) {
$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&cc_owner=' . urlencode($HTTP_POST_VARS['cc_owner']) . '&cc_expires_month=' . $HTTP_POST_VARS['cc_expires_month'] . '&cc_expires_year=' . $HTTP_POST_VARS['cc_expires_year'];

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYME NT, $payment_error_return, 'SSL', true, false));
}
// EOF: LEFP

b)
In the function get_error:
Right after:
case 'invalid_expiration_date':
$error_message = MODULE_PAYMENT_AUTHORIZENET_CC_AIM_ERROR_INVALID_E XP_DATE;
break;
Add:
// BOF: LEFP
case 'invalid_cc_number':
$error_message = MODULE_PAYMENT_AUTHORIZENET_CC_AIM_ERROR_INVALID_N UMBER;
break;
case 'type_mismatch':
$error_message = MODULE_PAYMENT_AUTHORIZENET_CC_AIM_ERROR_CARD_TYPE _MISMATCH;
break;
// EOF: LEFP

Please let me know if you find this helpful, and if it works for you.
Regards,
-Lori-