From ba2f3f653bced4da14c75773b8ae3fe9c4f0a240 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Thu, 27 Aug 2015 11:52:18 +1200 Subject: [PATCH] Consolidate some form parameter handling --- CRM/Contribute/Form/AbstractEditPayment.php | 15 +++++++++++---- CRM/Member/Form/Membership.php | 10 ++++++---- CRM/Member/Form/MembershipRenewal.php | 12 +----------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 912f2eaebe..98316e2680 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -642,11 +642,18 @@ LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co * access this function. */ protected function beginPostProcess() { - if (in_array('credit_card_exp_date', array_keys($this->_params))) { - $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); - $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); + if ($this->_mode) { + $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id']); + if (in_array('credit_card_exp_date', array_keys($this->_params))) { + $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); + $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); + } + $this->assign('credit_card_exp_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format($this->_params['credit_card_exp_date']))); + $this->assign('credit_card_number', + CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']) + ); + $this->assign('credit_card_type', $this->_params['credit_card_type']); } - $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 20ee9aa2b9..2c7fb5a744 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1108,6 +1108,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { public function submit() { $isTest = ($this->_mode == 'test') ? 1 : 0; $this->storeContactFields($this->_params); + $this->beginPostProcess(); $formValues = $this->_params; $joinDate = $startDate = $endDate = NULL; $membershipTypes = $membership = $calcDate = array(); @@ -1353,23 +1354,23 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $formValues); } + // @todo - test removing this line. The beginPostProcess Function should have done it for us. $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode ); - //get the payment processor id as per mode. + //get the payment processor id as per mode. Try removing in favour of beginPostProcess. $params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->_paymentProcessor['id']; $params['register_date'] = date('YmdHis'); // add all the additional payment params we need + // @todo the country & state values should be set by the call to $this->assignBillingAddress. $formValues["state_province-{$this->_bltID}"] = $formValues["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($formValues["billing_state_province_id-{$this->_bltID}"]); $formValues["country-{$this->_bltID}"] = $formValues["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($formValues["billing_country_id-{$this->_bltID}"]); - $formValues['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($formValues); - $formValues['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($formValues); - $formValues['ip_address'] = CRM_Utils_System::ipAddress(); $formValues['amount'] = $params['total_amount']; + // @todo this is a candidate for beginPostProcessFunction. $formValues['currencyID'] = $config->defaultCurrency; $formValues['description'] = ts("Contribution submitted by a staff person using member's credit card for signup"); $formValues['invoiceID'] = md5(uniqid(rand(), TRUE)); @@ -1392,6 +1393,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $paymentParams['email'] = $this->_contributorEmail; } + // This is a candidate for shared beginPostProcess function. CRM_Core_Payment_Form::mapParams($this->_bltID, $formValues, $paymentParams, TRUE); // CRM-7137 -for recurring membership, // we do need contribution and recurring records. diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 40d4172f15..e7a0f00af2 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -489,7 +489,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { */ protected function submit() { $this->storeContactFields($this->_params); - + $this->beginPostProcess(); $now = CRM_Utils_Date::getToday(NULL, 'YmdHis'); $this->convertDateFieldsToMySQL($this->_params); $this->assign('receive_date', $this->_params['receive_date']); @@ -524,17 +524,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { if ($this->_mode) { $this->_params['register_date'] = $now; - $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id']); - - $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); - $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); - $this->assign('credit_card_exp_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format($this->_params['credit_card_exp_date']))); - $this->assign('credit_card_number', - CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']) - ); - $this->assign('credit_card_type', $this->_params['credit_card_type']); $this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for renewal"); - $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $this->_params['total_amount']; // at this point we've created a contact and stored its address etc -- 2.25.1