Consolidate some form parameter handling
authoreileenmcnaugton <eileen@fuzion.co.nz>
Wed, 26 Aug 2015 23:52:18 +0000 (11:52 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 26 Aug 2015 23:52:18 +0000 (11:52 +1200)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php

index 912f2eaebea1ca9b3915f7435d7186e22503e2da..98316e268023094630b2f57b8ebbdfaee5890350 100644 (file)
@@ -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();
   }
 
index 20ee9aa2b932db6142d0dcd3768d77e019e618d0..2c7fb5a744a6e2a790055379154cac2e82ff9bfc 100644 (file)
@@ -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.
index 40d4172f155c0f1c774083d28853c27ff89c6e7b..e7a0f00af212a49df2ff1e619dfc695fd3141902 100644 (file)
@@ -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