console.log(r.message); //returns "This transaction has been authorized"
if (r.message.match(/approved/).length > 0 || r.message.match(/authorized/).length > 0) {
// ^ throws the error: r.message.match(/approved/) is null
Is this not the correct way to do matching in JavaScript?
success: function (r) {
$('.processing').addClass('hide');
if (r.type == 'success') {
console.log(r.message);
if (r.message.match(/approved/).length > 0 || r.message.match(/authorized/).length > 0) {
triggerNotification('check', 'Payment has been accepted');
//document.location = '/store/order/view?hash='+r.hash;
} else {
triggerNotification('check', r.message);
}
} else {
$('.button').show();
var msg = 'Unable to run credit card: '+r.message;
if (parseInt(r.code) > 0) {
msg = msg+' (Error code: #'+r.code+')';
}
triggerNotification('x', msg);
}
},
Since you are getting authorized message the statement
r.message.match(/approved/)will return null and hence the issue.Rewrite the check as follows: