From d1bf71d252081be2f5e4a53a23e71209de8fa65c Mon Sep 17 00:00:00 2001 From: Richard Burton <burtons@mosquitonet.com> Date: Thu, 22 Jan 2015 19:52:13 -0900 Subject: [PATCH] handle return key; add validateForm hook; better error messages --- CRM/Core/Payment/Stripe.php | 6 ++++-- js/civicrm_stripe.js | 13 ++++++++----- stripe.php | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Payment/Stripe.php b/CRM/Core/Payment/Stripe.php index b69f0643..72a06439 100644 --- a/CRM/Core/Payment/Stripe.php +++ b/CRM/Core/Payment/Stripe.php @@ -181,8 +181,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { else { // Don't have return url - return error object to api $core_err = CRM_Core_Error::singleton(); + $message = 'Oops! Looks like there was an error. Payment Response: <br />' . $error_message; if ($err['code']) { - $core_err->push($err['code'], 0, NULL, $err['message']); + $core_err->push($err['code'], 0, NULL, $message); } else { $core_err->push(9000, 0, NULL, 'Unknown Error'); @@ -223,8 +224,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { else { // Don't have return url - return error object to api $core_err = CRM_Core_Error::singleton(); + $message = 'Oops! Looks like there was an error. Payment Response: <br />' . $error_message; if ($err['code']) { - $core_err->push($err['code'], 0, NULL, $err['message']); + $core_err->push($err['code'], 0, NULL, $message); } else { $core_err->push(9000, 0, NULL, 'Unknown Error'); diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js index d07ec225..3d10bc14 100644 --- a/js/civicrm_stripe.js +++ b/js/civicrm_stripe.js @@ -30,10 +30,8 @@ var token = response['id']; // Update form with the token & submit. $form.find("input#stripe-token").val(token); - if (isWebform) { - $form.find("input#credit_card_number").removeAttr('name'); - $form.find("input#cvv2").removeAttr('name'); - } + $form.find("input#credit_card_number").removeAttr('name'); + $form.find("input#cvv2").removeAttr('name'); $submit.prop('disabled', false); window.onbeforeunload = null; $form.get(0).submit(); @@ -65,7 +63,12 @@ if (!($('#action').length)) { $form.append($('<input type="hidden" name="op" id="action" />')); } - var $actions = $form.find('input[type=submit]'); + $(document).keypress(function(event) { + if (event.which == 13) { + event.preventDefault(); + $submit.click(); + } + }); $(":submit").click(function() { $('#action').val(this.value); }); diff --git a/stripe.php b/stripe.php index 2940cb42..28bd7635 100644 --- a/stripe.php +++ b/stripe.php @@ -111,6 +111,28 @@ function stripe_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { return _stripe_civix_civicrm_upgrade($op, $queue); } +/** + * Implementation of hook_civicrm_validateForm(). + * + * Prevent server validation of cc fields + * + * @param $formName - the name of the form + * @param $fields - Array of name value pairs for all 'POST'ed form values + * @param $files - Array of file properties as sent by PHP POST protocol + * @param $form - reference to the form object + * @param $errors - Reference to the errors array. + */ +function stripe_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) { + if (isset($form->_paymentProcessor['payment_processor_type']) &&$form->_paymentProcessor['payment_processor_type'] == 'Stripe') { + if($form->elementExists('credit_card_number')){ + $form->removeElement('credit_card_number'); + } + if($form->elementExists('cvv2')){ + $form->removeElement('cvv2'); + } + } +} + /** * Implementation of hook_civicrm_buildForm(). * -- GitLab