Skip to content
Snippets Groups Projects
Commit a239e3d1 authored by Joshua Walker's avatar Joshua Walker
Browse files

Merge pull request #64 from kurund/js-fixes

more js fixes and code cleanup
parents 032970f0 60a5dc10
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
(function ($) {
// Response from Stripe.createToken.
function stripeResponseHandler(status, response) {
var submitButton = $("form.stripe-payment-form input[type='submit']:last");
if (response.error) {
$('html, body').animate({scrollTop: 0}, 300);
// Show the errors on the form.
......@@ -19,21 +20,15 @@
+ '</ul>'
+ '</div>');
$('form.stripe-payment-form input.form-submit').removeAttr("disabled");
submitButton.prop('disabled', false);
}
else {
var token = response['id'];
// Update form with the token & submit.
$("input#stripe-token").val(token);
// clear actual credit card information and set dummy cc details
// we are setting dummy cc details to prevent validation errors
// this is a work around so that we don't transmit sensitive data
$('#credit_card_number').val('4111111111111111');
$('#cvv2').val('111');
$('form.stripe-payment-form input.form-submit').removeAttr("disabled");
$("input[type='submit']:last").click();
submitButton.prop('disabled', false);
$("form.stripe-payment-form").get(0).submit();
}
}
......@@ -55,11 +50,16 @@
$('#crm-ajax-dialog-1 form').addClass('stripe-payment-form');
}
$("form.stripe-payment-form").unbind('submit');
// Intercept form submission.
$("form.stripe-payment-form").submit(function (event) {
event.preventDefault();
event.stopPropagation();
var $form = $(this);
// Disable the submit button to prevent repeated clicks.
$("input[type='submit']:last").attr('disabled', true);
$form.find("input[type='submit']:last").prop('disabled', true);
if ($form.find("#priceset input[type='radio']:checked").data('amount') == 0) {
return true;
......@@ -95,9 +95,7 @@
exp_year: cc_year
}, stripeResponseHandler);
// Prevent the form from submitting with the default action.
return false;
});
});
}(jQuery));
}(CRM.$));
......@@ -129,7 +129,12 @@ function stripe_civicrm_buildForm($formName, &$form) {
}
// For the 'Record Contribution' backend page.
if (($formName == 'CRM_Contribute_Form_Contribution' || $formName == 'CRM_Event_Form_Participant' || $formName == 'CRM_Member_Form_Membership' && !empty($form->_processors)) || stristr($formName, '_Main')) {
$backendForms = array(
'CRM_Contribute_Form_Contribution',
'CRM_Event_Form_Participant',
'CRM_Member_Form_Membership'
);
if (in_array($formName, $backendForms) && !empty($form->_processors)) {
if (!isset($form->_elementIndex['stripe_token'])) {
$form->addElement('hidden', 'stripe_token', NULL, array('id' => 'stripe-token'));
stripe_add_stripe_js($form);
......
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