From cc9841984e945dfd5abba8eb34dd18e255109919 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 4 Nov 2014 00:47:08 +1300 Subject: [PATCH] CRM-15555 fix membership forms by inheriting & re-using abstract payment methods --- CRM/Contribute/Form/AbstractEditPayment.php | 23 +++++++++ CRM/Contribute/Form/Contribution.php | 18 +------ CRM/Core/Payment/Form.php | 2 +- CRM/Member/Form.php | 4 +- CRM/Member/Form/Membership.php | 52 ++------------------- CRM/Member/Form/MembershipRenewal.php | 45 +----------------- 6 files changed, 32 insertions(+), 112 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 5612dae1ae..5e9be9e97c 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -574,4 +574,27 @@ LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co return $submittedValues; } + /** + * common block for setting up the parts of a form that relate to credit / debit card + * @throws Exception + */ + protected function assignPaymentRelatedVariables() { + try { + 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->_fields = array(); + CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); + } + } + catch (CRM_Core_Exception $e) { + CRM_Core_Error::fatal($e->getMessage()); + } + } } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index e7d3dc8cde..dcc4f96202 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -294,23 +294,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->assign('showCheckNumber', TRUE); $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); - try { - 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->_fields = array(); - CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); - } - } - catch (CRM_Core_Exception $e) { - CRM_Core_Error::fatal($e->getMessage()); - } + $this->assignPaymentRelatedVariables(); if (in_array('CiviPledge', CRM_Core_Config::singleton()->enableComponents) && !$this->_formType) { $this->preProcessPledge(); diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 3f1c574b80..f89058f2e5 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -362,7 +362,7 @@ class CRM_Core_Payment_Form { } /** - * @param CRM_Core_Form $form + * @param CRM_Contribute_Form_Contribution| CRM_Contribute_Form_Contribution_Main|CRM_Member_Form_Membership $form * @param array $processor array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors * @param bool $isBillingDataOptional * diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 749bb46ebc..495ce91d46 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -37,14 +37,14 @@ * Base class for offline membership / membership type / membership renewal and membership status forms * */ -class CRM_Member_Form extends CRM_Core_Form { +class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { /** * The id of the object being edited / created * * @var int */ - protected $_id; + public $_id; /** * The name of the BAO object for this form diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index ebe668c821..6b0b11b727 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -61,10 +61,10 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { */ protected $_memberEmail = NULL; - /* + /*l43 * Contact ID of the member */ - protected $_contactID = NULL; + public $_contactID = NULL; /* * Display name of the person paying for the membership (used for receipts) @@ -148,51 +148,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->assign('membershipMode', $this->_mode); if ($this->_mode) { - $this->_paymentProcessor = array('billing_mode' => 1); - $validProcessors = array(); - $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'billing_mode IN ( 1, 3 )'); - - foreach ($processors as $ppID => $label) { - $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); - if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { - continue; - } - elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { - continue; - } - else { - $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this); - $error = $paymentObject->checkConfig(); - if (empty($error)) { - $validProcessors[$ppID] = $label; - } - $paymentObject = NULL; - } - } - if (empty($validProcessors)) { - CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); - } - else { - $this->_processors = $validProcessors; - } - // also check for billing information - // get the billing location type - $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); - // CRM-8108 remove ts around Billing location type - //$this->_bltID = array_search( ts('Billing'), $locationTypes ); - $this->_bltID = array_search('Billing', $locationTypes); - if (!$this->_bltID) { - CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); - } - $this->set('bltID', $this->_bltID); - $this->assign('bltID', $this->_bltID); - - $this->_fields = array(); - - CRM_Core_Payment_Form::setCreditCardFields($this); - - // this required to show billing block - $this->assign_by_ref('paymentProcessor', $paymentProcessor); + $this->assignPaymentRelatedVariables(); } if ($this->_action & CRM_Core_Action::ADD) { @@ -766,7 +722,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $this->_processors, TRUE, array('onChange' => "buildAutoRenew( null, this.value );") ); - CRM_Core_Payment_Form::buildCreditCard($this, TRUE); + CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, TRUE); } // Retrieve the name and email of the contact - this will be the TO for receipt email diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index a0af3de959..cf6d85653c 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -137,52 +137,9 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { )); } $this->assign('membershipMode', $this->_mode); - - $this->_paymentProcessor = array('billing_mode' => 1); + $this->assignPaymentRelatedVariables(); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'billing_mode IN ( 1, 3 )'); - - foreach ($processors as $ppID => $label) { - $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); - if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { - continue; - } - elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { - continue; - } - else { - $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this); - $error = $paymentObject->checkConfig(); - if (empty($error)) { - $validProcessors[$ppID] = $label; - } - $paymentObject = NULL; - } - } - if (empty($validProcessors)) { - CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); - } - else { - $this->_processors = $validProcessors; - } - // also check for billing information - // get the billing location type - $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); - // CRM-8108 remove ts around Billing location type - //$this->_bltID = array_search( ts('Billing'), $locationTypes ); - $this->_bltID = array_search('Billing', $locationTypes); - if (!$this->_bltID) { - CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); - } - $this->set('bltID', $this->_bltID); - $this->assign('bltID', $this->_bltID); - - $this->_fields = array(); - - CRM_Core_Payment_Form::setCreditCardFields($this); - - // this required to show billing block - $this->assign_by_ref('paymentProcessor', $paymentProcessor); } else { $this->assign('membershipMode', FALSE); -- 2.25.1