From 459091e180047352a17e734e731b3b3c8fa2ffa1 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 3 Nov 2014 20:59:23 +1300 Subject: [PATCH] towards CRM-15555 showing billing fields for backoffice contributions --- CRM/Contribute/Form/Contribution.php | 48 +++++++++++----- CRM/Core/Payment.php | 10 +++- CRM/Core/Payment/Form.php | 5 +- .../Form/AdditionalInfo/CreditCard.tpl | 55 +------------------ 4 files changed, 45 insertions(+), 73 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index d34144b289..9aebb2591e 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -183,6 +183,22 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP protected $_cdType; public $_honoreeProfileType; + /** + * array of billing panes to be displayed by billingBlock.tpl - currently this is likely to look like + * array('Credit Card' => ts('Credit Card') or array('Direct Debit => ts('Direct Debit') + * @todo billing details (address stuff) to be added when we stop hard coding the panes in billingBlock.tpl + * + * @var array + */ + public $billingPane = array(); + + /** + * array of the payment fields to be displayed in the payment fieldset (pane) in billingBlock.tpl + * this contains all the information to describe these fields from quickform. See CRM_Core_Form_Payment getPaymentFormFieldsMetadata + * + * @var array + */ + public $_paymentFields = array(); /** * logged in user's email * @var string @@ -271,30 +287,30 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->assign('contributionMode', $this->_mode); - - $this->_paymentProcessor = array('billing_mode' => 1); + if ($this->_action & CRM_Core_Action::DELETE) { + return; + } $this->assign('showCheckNumber', TRUE); $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); try { - $this->assignProcessors(); - if ($this->_contactID) { - list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); - $this->assign('displayName', $this->userDisplayName); - } + if ($this->_mode) { + $this->assignProcessors(); + if ($this->_contactID) { + list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); + $this->assign('displayName', $this->userDisplayName); + } - $this->assignBillingType(); + $this->assignBillingType(); - $this->_fields = array(); - CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); + $this->_fields = array(); + CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); + } } catch (CRM_Core_Exception $e) { CRM_Core_Error::fatal($e->getMessage()); } - if ($this->_action & CRM_Core_Action::DELETE) { - return; - } if (in_array('CiviPledge', CRM_Core_Config::singleton()->enableComponents) && !$this->_formType) { $this->preProcessPledge(); @@ -584,8 +600,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE) == TRUE) { $buildRecurBlock = TRUE; foreach ($this->billingPane as $name => $label) { - //@todo reduce variation so we don't have to convert 'credit_card' to 'CreditCard' - $paneNames[$label] = CRM_Utils_String::convertStringToCamel($name); + if (!empty($this->billingFieldSets[$name]['fields'])) { + //@todo reduce variation so we don't have to convert 'credit_card' to 'CreditCard' + $paneNames[$label] = CRM_Utils_String::convertStringToCamel($name); + } } } } diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index bfc013bc9b..4962dd72f5 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -88,7 +88,7 @@ abstract class CRM_Core_Payment { * * @param string $mode the mode of operation: live or test * @param array $paymentProcessor the details of the payment processor being invoked - * @param object $paymentForm reference to the form object if available + * @param object $paymentForm deprecated - avoid referring to this if possible. If you have to use it document why as this is scary interaction * @param boolean $force should we force a reload of this payment object * * @return CRM_Core_Payment @@ -103,6 +103,7 @@ abstract class CRM_Core_Payment { } $cacheKey = "{$mode}_{$paymentProcessor['id']}_" . (int)isset($paymentForm); + if (!isset(self::$_singleton[$cacheKey]) || $force) { $config = CRM_Core_Config::singleton(); $ext = CRM_Extension_System::singleton()->getMapper(); @@ -112,6 +113,9 @@ abstract class CRM_Core_Payment { } else { $paymentClass = 'CRM_Core_' . $paymentProcessor['class_name']; + if (empty($paymentClass)) { + throw new CRM_Core_Exception('no class provided'); + } require_once (str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php'); } @@ -220,7 +224,7 @@ abstract class CRM_Core_Payment { * @return string */ public function getPaymentTypeName() { - return $this->_paymentProcessor['payment_type'] == 1 ? 'credit_card' : 'debit_card'; + return $this->_paymentProcessor['payment_type'] == 1 ? 'credit_card' : 'direct_debit'; } /** @@ -229,7 +233,7 @@ abstract class CRM_Core_Payment { * @return string */ public function getPaymentTypeLabel() { - return $this->_paymentProcessor['payment_type'] == 1 ? 'Credit Card' : 'Debit Card'; + return $this->_paymentProcessor['payment_type'] == 1 ? 'Credit Card' : 'Direct Debit'; } /** diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index ee191dbc2e..161e9170c9 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -53,7 +53,9 @@ class CRM_Core_Payment_Form { /** * Add payment fields are depending on payment type * - * @param CRM_Core_Form $form + * @param CRM_Contribute_Form_Contribution $form + * @todo - add other forms specifically to the definition - since we don't have for $form - since we aren't adding the property to + * CRM_Core_Form (don't suppose we should?) * @param array $processor array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors */ static public function setPaymentFieldsByProcessor(&$form, $processor) { @@ -71,6 +73,7 @@ class CRM_Core_Payment_Form { $form->assign('paymentFields', $paymentFields); if ($processor['billing_mode'] != 4) { //@todo setPaymentFields defines the billing fields - this should be moved to the processor class & renamed getBillingFields + // currently we just add the standard lot unless it's an off-site processor (& then add none) //also set the billingFieldSet to hold all the details required to render the fieldset so we can iterate through the fieldset - making // it easier to re-order. For not the billingFieldSets param is used to determine whether to show the billing pane CRM_Core_Payment_Form::_setPaymentFields($form); diff --git a/templates/CRM/Contribute/Form/AdditionalInfo/CreditCard.tpl b/templates/CRM/Contribute/Form/AdditionalInfo/CreditCard.tpl index ba345d52b9..7441e20c14 100644 --- a/templates/CRM/Contribute/Form/AdditionalInfo/CreditCard.tpl +++ b/templates/CRM/Contribute/Form/AdditionalInfo/CreditCard.tpl @@ -28,57 +28,4 @@ {include file='CRM/Core/BillingBlock.tpl'} -{* build recurring contribution block. *} -{if $buildRecurBlock} -{literal} - -{/literal} -{/if} +{include file="CRM/Contribute/Form/AdditionalInfo/Payment.tpl"} -- 2.25.1