CRM-18676: Incorrect status for pay later free membership
[civicrm-core.git] / CRM / Contribute / Form / Contribution / Main.php
index 80543409ccf1be3bc3591cbb2e093d2b85cd6351..942d935b2dd3c5f182fdee298ad0f7052bb15833 100644 (file)
@@ -600,6 +600,11 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
   public static function formRule($fields, $files, $self) {
     $errors = array();
     $amount = self::computeAmount($fields, $self->_values);
+    if (CRM_Utils_Array::value('auto_renew', $fields) &&
+      CRM_Utils_Array::value('payment_processor_id', $fields) == 0
+    ) {
+      $errors['auto_renew'] = ts('You cannot have auto-renewal on if you are paying later.');
+    }
 
     if ((!empty($fields['selectMembership']) &&
         $fields['selectMembership'] != 'no_thanks'
@@ -1050,27 +1055,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
     // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
     $params['amount'] = self::computeAmount($params, $this->_values);
-    if (($this->_values['is_pay_later'] &&
-        empty($this->_paymentProcessor) &&
-        !array_key_exists('hidden_processor', $params)) ||
-      (CRM_Utils_Array::value('payment_processor_id', $params) == 0)
-      && ($is_quick_config == 0 || $params['amount'] != 0)
-    ) {
-      $params['is_pay_later'] = 1;
-    }
-    else {
-      $params['is_pay_later'] = 0;
-    }
-
-    // Would be nice to someday understand the point of this set.
-    $this->set('is_pay_later', $params['is_pay_later']);
-    // assign pay later stuff
-    $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
-    $this->assign('is_pay_later', $params['is_pay_later']);
-    if ($params['is_pay_later']) {
-      $this->assign('pay_later_text', $this->_values['pay_later_text']);
-      $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
-    }
 
     $params['separate_amount'] = $params['amount'];
     $memFee = NULL;
@@ -1163,6 +1147,29 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       $this->set('lineItem', $lineItem);
     }
 
+    if ($params['amount'] != 0 && (($this->_values['is_pay_later'] &&
+          empty($this->_paymentProcessor) &&
+          !array_key_exists('hidden_processor', $params)) ||
+        (CRM_Utils_Array::value('payment_processor_id', $params) == 0)
+        && ($is_quick_config == 0)
+      )
+    ) {
+      $params['is_pay_later'] = 1;
+    }
+    else {
+      $params['is_pay_later'] = 0;
+    }
+
+    // Would be nice to someday understand the point of this set.
+    $this->set('is_pay_later', $params['is_pay_later']);
+    // assign pay later stuff
+    $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
+    $this->assign('is_pay_later', $params['is_pay_later']);
+    if ($params['is_pay_later']) {
+      $this->assign('pay_later_text', $this->_values['pay_later_text']);
+      $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
+    }
+
     if ($this->_membershipBlock['is_separate_payment'] && !empty($params['separate_amount'])) {
       $this->set('amount', $params['separate_amount']);
     }