test fix
[civicrm-core.git] / CRM / Member / Form / MembershipRenewal.php
index addb5b71bda9387facb6723d6b0ac421b0d675a6..e1174be2fd73b165a271edca17c3a0feb66583d0 100644 (file)
@@ -33,7 +33,6 @@
 
 /**
  * This class generates form components for Membership Renewal
- *
  */
 class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
 
@@ -120,6 +119,11 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     'receive_date' => array('default' => 'now'),
   );
 
+  /**
+   * Pre-process form.
+   *
+   * @throws \Exception
+   */
   public function preProcess() {
 
     // This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
@@ -232,19 +236,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
 
     if ($this->_mode) {
-      // set default country from config if no country set
-      $config = CRM_Core_Config::singleton();
-      if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
-        $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
-      }
-
-      if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
-        $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
-      }
-
-      $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
-      $defaults = array_merge($defaults, $billingDefaults);
-
+      $defaults = $this->getBillingDefaults($defaults);
     }
     return $defaults;
   }
@@ -501,7 +493,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']);
@@ -518,7 +510,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     if (empty($this->_params['financial_type_id'])) {
       $this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
     }
-
+    $contributionRecurID = NULL;
     $this->assign('membershipID', $this->_id);
     $this->assign('contactID', $this->_contactID);
     $this->assign('module', 'Membership');
@@ -536,17 +528,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
@@ -565,6 +547,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
 
       if (!empty($this->_params['auto_renew'])) {
         $contributionRecurParams = $this->processRecurringContribution($paymentParams);
+        $contributionRecurID = $contributionRecurParams['contributionRecurID'];
         $paymentParams = array_merge($paymentParams, $contributionRecurParams);
       }
 
@@ -598,7 +581,6 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
 
     // These variable sets prior to renewMembership may not be required for this form. They were in
     // a function this form shared with other forms.
-    $contributionRecurID = isset($this->_params['contributionRecurID']) ? $this->_params['contributionRecurID'] : NULL;
     $membershipSource = NULL;
     if (!empty($this->_params['membership_source'])) {
       $membershipSource = $this->_params['membership_source'];
@@ -743,4 +725,24 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     }
   }
 
+  /**
+   * @param $defaults
+   *
+   * @return array
+   */
+  protected function getBillingDefaults($defaults) {
+    // set default country from config if no country set
+    $config = CRM_Core_Config::singleton();
+    if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
+      $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
+    }
+
+    if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
+      $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
+    }
+
+    $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
+    return array_merge($defaults, $billingDefaults);
+  }
+
 }