From 9be1374d716b788afc933d510e5c4c589b94b204 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 14 May 2014 12:26:44 +1200 Subject: [PATCH] CRM-14684 refactor function that identifies is a site supports back-office contributions & leave form layer part on forms --- CRM/Contribute/Form/AdditionalPayment.php | 2 +- CRM/Contribute/Form/Contribution.php | 2 +- CRM/Contribute/Page/Tab.php | 2 +- CRM/Core/Block.php | 2 +- CRM/Core/Config.php | 16 ++++++++++++++++ CRM/Core/Payment.php | 20 -------------------- CRM/Event/Page/Tab.php | 2 +- CRM/Member/Page/Tab.php | 4 +++- CRM/Pledge/Page/Payment.php | 2 +- CRM/Pledge/Page/Tab.php | 2 +- 10 files changed, 26 insertions(+), 28 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 1c7fc5cfa5..f54af2d560 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -196,7 +196,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract } // Set $newCredit variable in template to control whether link to credit card mode is included - CRM_Core_Payment::allowBackofficeCreditCard($this); + $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); return $defaults; } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index dd2dc1fbfe..b71b60c0b2 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -322,7 +322,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } // Set $newCredit variable in template to control whether link to credit card mode is included - CRM_Core_Payment::allowBackofficeCreditCard($this); + $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); // fix the display of the monetary value, CRM-4038 if (isset($defaults['total_amount'])) { diff --git a/CRM/Contribute/Page/Tab.php b/CRM/Contribute/Page/Tab.php index bac070363a..b6093725a9 100644 --- a/CRM/Contribute/Page/Tab.php +++ b/CRM/Contribute/Page/Tab.php @@ -283,7 +283,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page { $this->preProcess(); // check if we can process credit card contribs - CRM_Core_Payment::allowBackofficeCreditCard($this); + $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); $this->setContext(); diff --git a/CRM/Core/Block.php b/CRM/Core/Block.php index bbf5ec6e52..5690a41da8 100644 --- a/CRM/Core/Block.php +++ b/CRM/Core/Block.php @@ -368,7 +368,7 @@ class CRM_Core_Block { if (!empty($config->enableComponents)) { // check if we can process credit card contribs - $newCredit = CRM_Core_Payment::allowBackofficeCreditCard(); + $newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments(); foreach ($components as $componentName => $obj) { if (in_array($componentName, $config->enableComponents)) { diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 8533d4be40..6e6157f46a 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -851,6 +851,22 @@ AND $this->userFramework = $userFramework; $this->_setUserFrameworkConfig($userFramework); } + + /** + * Is back office credit card processing enabled for this site - ie are there any installed processors that support + * on-site processing + * @return bool + */ + static function isEnabledBackOfficeCreditCardPayments() { + // restrict to type=1 (credit card) payment processor payment_types and only include billing mode types 1 and 3 + $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, + "billing_mode IN ( 1, 3 ) AND payment_type = 1" + ); + if (count($processors) > 0) { + return TRUE; + } + return FALSE; + } } // end CRM_Core_Config diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 762eb8a878..bc84d21cfa 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -388,24 +388,4 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) } return $this->_paymentProcessor['url_recur']; } - - /** - * Check for presence of type 1 or type 3 enabled processors (means we can do back-office submit credit/debit card trxns) - * @public - */ - static function allowBackofficeCreditCard($template = NULL, $variableName = 'newCredit') { - $newCredit = FALSE; - // restrict to type=1 (credit card) payment processor payment_types and only include billing mode types 1 and 3 - $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, - "billing_mode IN ( 1, 3 ) AND payment_type = 1" - ); - if (count($processors) > 0) { - $newCredit = TRUE; - } - if ($template) { - $template->assign($variableName, $newCredit); - } - return $newCredit; - } - } diff --git a/CRM/Event/Page/Tab.php b/CRM/Event/Page/Tab.php index 14ff3f8421..9d971eba44 100644 --- a/CRM/Event/Page/Tab.php +++ b/CRM/Event/Page/Tab.php @@ -159,7 +159,7 @@ class CRM_Event_Page_Tab extends CRM_Core_Page { $this->preProcess(); // check if we can process credit card registration - CRM_Core_Payment::allowBackofficeCreditCard($this); + $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); // Only show credit card registration button if user has CiviContribute permission if (CRM_Core_Permission::access('CiviContribute')) { diff --git a/CRM/Member/Page/Tab.php b/CRM/Member/Page/Tab.php index 2aad0d971c..d4eb65e215 100644 --- a/CRM/Member/Page/Tab.php +++ b/CRM/Member/Page/Tab.php @@ -321,7 +321,9 @@ class CRM_Member_Page_Tab extends CRM_Core_Page { $this->preProcess(); // check if we can process credit card membership - $newCredit = CRM_Core_Payment::allowBackofficeCreditCard($this); + $newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments(); + $this->assign('newCredit', $newCredit); + if ($newCredit) { $this->_isPaymentProcessor = TRUE; } diff --git a/CRM/Pledge/Page/Payment.php b/CRM/Pledge/Page/Payment.php index 34c078d113..ac36d7e2d1 100644 --- a/CRM/Pledge/Page/Payment.php +++ b/CRM/Pledge/Page/Payment.php @@ -66,7 +66,7 @@ class CRM_Pledge_Page_Payment extends CRM_Core_Page { $this->assign('contactId', $this->_contactId); // check if we can process credit card contribs - CRM_Core_Payment::allowBackofficeCreditCard($this); + $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); // check is the user has view/edit signer permission $permission = 'view'; diff --git a/CRM/Pledge/Page/Tab.php b/CRM/Pledge/Page/Tab.php index 5b48573019..ca0e360704 100644 --- a/CRM/Pledge/Page/Tab.php +++ b/CRM/Pledge/Page/Tab.php @@ -136,7 +136,7 @@ class CRM_Pledge_Page_Tab extends CRM_Core_Page { $this->preProcess(); // check if we can process credit card registration - CRM_Core_Payment::allowBackofficeCreditCard($this); + $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); $this->setContext(); -- 2.25.1