Skip to content
Snippets Groups Projects
Commit 3751fe5b authored by Jamie McClelland's avatar Jamie McClelland
Browse files

handle error corner cases

When stripe throws an error, and the original form as an onclick event,
we briefly see the error before the form is submitted according to
the onclick event (i.e. the PreventDefault() and return false
does not have any effect).

This fix removes any onclick attributes at the beginning and only
re-adds them and resubmits the form if we should.
parent 051e0d3c
No related branches found
No related tags found
No related merge requests found
......@@ -37,14 +37,25 @@
// Disable unload event handler
window.onbeforeunload = null;
// Restore any onclickAction that was removed.
$submit.attr('onclick', onclickAction);
// This triggers submit without generating a submit event (so we don't run submit handler again)
$form.get(0).submit();
}
}
// Prepare the form.
var onclickAction = null;
$(document).ready(function() {
loadStripeBillingBlock();
$submit = getBillingSubmit();
// Store and remove any onclick Action currently assigned to the form.
// We will re-add it if the transaction goes through.
onclickAction = $submit.attr('onclick');
$submit.removeAttr('onclick');
});
// Re-prep form when we've loaded a new payproc
......@@ -129,7 +140,19 @@
// Intercept form submission.
$form.on('submit', function(event) {
submit(event);
var ret = submit(event);
if (ret) {
// True means it's not our form. We are bailing and not trying to
// process Stripe.
// Restore any onclickAction that was removed.
$form = getBillingForm();
$submit = getBillingSubmit();
$submit.attr('onclick', onclickAction);
$form.get(0).submit();
return true;
}
// Otherwise, this is a stripe submission - don't handle normally.
return false;
});
function submit(event) {
......@@ -150,7 +173,6 @@
// Bail if we're not using Stripe or are using pay later (option value '0' in payment_processor radio group).
if ((chosenProcessorId !== stripeProcessorId) || (chosenProcessorId === 0)) {
debugging('debug: Not a Stripe transaction, or pay-later');
$form.get(0).submit();
return true;
}
}
......@@ -168,7 +190,6 @@
// Don't handle submits generated by the CiviDiscount button.
if ($form.data('submit-dont-process')) {
debugging('non-payment submit detected - not submitting payment');
$form.get(0).submit();
return true;
}
......@@ -193,11 +214,17 @@
}
}
// If there's no credit card field, no use in continuing (probably wrong
// context anyway)
if (!$form.find('#credit_card_number').length) {
debugging('debug: No credit card field');
return true;
}
// Lock to prevent multiple submissions
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
alert('Form already submitted. Please wait.');
return true;
return false;
} else {
// Mark it so that the next submit can be ignored
// ADDED requirement that form be valid
......@@ -209,13 +236,6 @@
// Disable the submit button to prevent repeated clicks
$submit.prop('disabled', true);
// If there's no credit card field, no use in continuing (probably wrong
// context anyway)
if (!$form.find('#credit_card_number').length) {
debugging('debug: No credit card field');
return true;
}
var cc_month = $form.find('#credit_card_exp_date_M').val();
var cc_year = $form.find('#credit_card_exp_date_Y').val();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment