From 1ba4a3aa97788de5eabc650e320e0ee251c9d7fe Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 25 May 2015 08:58:10 +1200 Subject: [PATCH] CRM-16555 rationalise paypal express behaviour into a generic behaviour (suppress submit button) --- CRM/Contribute/Form/Contribution/Main.php | 9 -------- CRM/Core/Payment.php | 11 +++++++++ CRM/Core/Payment/PayPalImpl.php | 13 +++++++++++ CRM/Core/Payment/ProcessorForm.php | 6 ++--- CRM/Financial/Form/Payment.php | 5 ---- .../CRM/Contribute/Form/Contribution/Main.tpl | 22 ------------------ templates/CRM/Core/BillingBlock.tpl | 23 +++++++++++++++++++ .../CRM/Event/Form/Registration/Register.tpl | 21 ----------------- 8 files changed, 50 insertions(+), 60 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 143b54cd37..08f9e23388 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -1406,15 +1406,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu else { $form->_paymentProcessor = array(); } - - //get payPal express id and make it available to template - foreach ($form->_paymentProcessors as $ppId => $values) { - $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0; - $form->assign('payPalExpressId', $payPalExpressId); - if ($payPalExpressId) { - break; - } - } CRM_Financial_Form_Payment::addCreditCardJs(); } $form->assign('paymentProcessorID', $form->_paymentProcessorID); diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 6e9c301c16..03f43009dd 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -712,6 +712,17 @@ abstract class CRM_Core_Payment { return method_exists(CRM_Utils_System::getClassName($this), $method); } + /** + * Some processors replace the form submit button with their own. + * + * Returning false here will leave the button off front end forms. + * + * At this stage there is zero cross-over between back-office processors and processors that suppress the submit. + */ + public function isSuppressSubmitButtons() { + return FALSE; + } + /** * Get url for users to manage this recurring contribution for this processor. * diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 6e121f658c..3c0443e4b4 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -444,6 +444,19 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { return parent::isSupported($method); } + /** + * Paypal express replaces the submit button with it's own. + * + * @return bool + * Should the form button by suppressed? + */ + public function isSuppressSubmitButtons() { + if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express') { + return TRUE; + } + return FALSE; + } + /** * @param string $message * @param array $params diff --git a/CRM/Core/Payment/ProcessorForm.php b/CRM/Core/Payment/ProcessorForm.php index 560d95af4f..1fc9db762d 100644 --- a/CRM/Core/Payment/ProcessorForm.php +++ b/CRM/Core/Payment/ProcessorForm.php @@ -29,8 +29,6 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * */ /** @@ -58,10 +56,12 @@ class CRM_Core_Payment_ProcessorForm { } $form->set('paymentProcessor', $form->_paymentProcessor); + $form->_paymentObject = CRM_Core_Payment::singleton($mode, $form->_paymentProcessor, $form); + + $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons()); // also set cancel subscription url if (!empty($form->_paymentProcessor['is_recur']) && !empty($form->_values['is_recur'])) { - $form->_paymentObject = CRM_Core_Payment::singleton($mode, $form->_paymentProcessor, $form); $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(); } diff --git a/CRM/Financial/Form/Payment.php b/CRM/Financial/Form/Payment.php index 56ad9e158a..dbfdf3ff02 100644 --- a/CRM/Financial/Form/Payment.php +++ b/CRM/Financial/Form/Payment.php @@ -49,11 +49,6 @@ class CRM_Financial_Form_Payment extends CRM_Core_Form { $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_paymentProcessorID, 'unused'); CRM_Core_Payment_ProcessorForm::preProcess($this); - //@todo - figure out how to deal with payment express. - //get payPal express id and make it available to template - //$payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0; - // $this->assign('payPalExpressId', $payPalExpressId); - self::addCreditCardJs(); $this->assign('paymentProcessorID', $this->_paymentProcessorID); diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index ba70f9bb0c..4944a35aaa 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -388,28 +388,6 @@ {/if} {literal} - function toggleConfirmButton() { - var payPalExpressId = "{/literal}{$payPalExpressId}{literal}"; - var elementObj = cj('input[name="payment_processor"]'); - if ( elementObj.attr('type') == 'hidden' ) { - var processorTypeId = elementObj.val( ); - } - else { - var processorTypeId = elementObj.filter(':checked').val(); - } - - if (payPalExpressId !=0 && payPalExpressId == processorTypeId) { - cj("#crm-submit-buttons").hide(); - } - else { - cj("#crm-submit-buttons").show(); - } - } - - cj('input[name="payment_processor"]').change( function() { - toggleConfirmButton(); - }); - CRM.$(function($) { toggleConfirmButton(); enableHonorType(); diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index 4f9bb7ae0f..74963fcfa3 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -200,6 +200,29 @@ }); }); {/literal} + + function toggleConfirmButton() { + var suppressSubmitButton = "{/literal}{$suppressSubmitButton}{literal}"; + var elementObj = cj('input[name="payment_processor"]'); + if ( elementObj.attr('type') == 'hidden' ) { + var processorTypeId = elementObj.val( ); + } + else { + var processorTypeId = elementObj.filter(':checked').val(); + } + + if (suppressSubmitButton) { + cj("#crm-submit-buttons").hide(); + } + else { + cj("#crm-submit-buttons").show(); + } + } + + cj('input[name="payment_processor_id"]').change( function() { + toggleConfirmButton(); + }); + {/if} {/crmRegion} diff --git a/templates/CRM/Event/Form/Registration/Register.tpl b/templates/CRM/Event/Form/Registration/Register.tpl index cb3049fcb4..2e067da846 100644 --- a/templates/CRM/Event/Form/Registration/Register.tpl +++ b/templates/CRM/Event/Form/Registration/Register.tpl @@ -164,27 +164,6 @@