Skip to content
Snippets Groups Projects
Unverified Commit 8928a489 authored by mattwire's avatar mattwire Committed by GitHub
Browse files

Merge pull request #3 from progressivetech/handle-corner-errors

handle error corner cases
parents 9df3cf70 3751fe5b
No related branches found
No related tags found
No related merge requests found
...@@ -37,14 +37,25 @@ ...@@ -37,14 +37,25 @@
// Disable unload event handler // Disable unload event handler
window.onbeforeunload = null; 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) // This triggers submit without generating a submit event (so we don't run submit handler again)
$form.get(0).submit(); $form.get(0).submit();
} }
} }
// Prepare the form. // Prepare the form.
var onclickAction = null;
$(document).ready(function() { $(document).ready(function() {
loadStripeBillingBlock(); 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 // Re-prep form when we've loaded a new payproc
...@@ -129,7 +140,19 @@ ...@@ -129,7 +140,19 @@
// Intercept form submission. // Intercept form submission.
$form.on('submit', function(event) { $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) { function submit(event) {
...@@ -150,7 +173,6 @@ ...@@ -150,7 +173,6 @@
// Bail if we're not using Stripe or are using pay later (option value '0' in payment_processor radio group). // 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)) { if ((chosenProcessorId !== stripeProcessorId) || (chosenProcessorId === 0)) {
debugging('debug: Not a Stripe transaction, or pay-later'); debugging('debug: Not a Stripe transaction, or pay-later');
$form.get(0).submit();
return true; return true;
} }
} }
...@@ -168,7 +190,6 @@ ...@@ -168,7 +190,6 @@
// Don't handle submits generated by the CiviDiscount button. // Don't handle submits generated by the CiviDiscount button.
if ($form.data('submit-dont-process')) { if ($form.data('submit-dont-process')) {
debugging('non-payment submit detected - not submitting payment'); debugging('non-payment submit detected - not submitting payment');
$form.get(0).submit();
return true; return true;
} }
...@@ -196,11 +217,17 @@ ...@@ -196,11 +217,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 // Lock to prevent multiple submissions
if ($form.data('submitted') === true) { if ($form.data('submitted') === true) {
// Previously submitted - don't submit again // Previously submitted - don't submit again
alert('Form already submitted. Please wait.'); alert('Form already submitted. Please wait.');
return true; return false;
} else { } else {
// Mark it so that the next submit can be ignored // Mark it so that the next submit can be ignored
// ADDED requirement that form be valid // ADDED requirement that form be valid
...@@ -212,13 +239,6 @@ ...@@ -212,13 +239,6 @@
// Disable the submit button to prevent repeated clicks // Disable the submit button to prevent repeated clicks
$submit.prop('disabled', true); $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_month = $form.find('#credit_card_exp_date_M').val();
var cc_year = $form.find('#credit_card_exp_date_Y').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