CRM-16471 post refactoring - extract pending status from form
authorEileen McNaughton <eileen@fuzion.co.nz>
Sat, 27 Jun 2015 20:54:22 +0000 (08:54 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sat, 27 Jun 2015 20:54:22 +0000 (08:54 +1200)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Member/BAO/Membership.php
CRM/Member/Form/MembershipRenewal.php

index 464a97cda4de1c367611bc186aa41b2f5c4c895a..25a78f13e5c951ed67f97b4634391c2ffc2c3e72 100644 (file)
@@ -1531,6 +1531,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       $membershipTypeIDs = (array) $membershipParams['selectMembership'];
       $membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIDs);
       $membershipType = empty($membershipTypes) ? array() : reset($membershipTypes);
+      $isPending = $this->getIsPending();
+
       $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipType));
 
       $isPaidMembership = FALSE;
@@ -1552,8 +1554,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
 
       CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID,
         $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeIDs, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId,
-        $membershipLineItems, $isPayLater
-      );
+        $membershipLineItems, $isPayLater, $isPending);
       $this->assign('membership_assign', TRUE);
       $this->set('membershipTypeID', $membershipParams['selectMembership']);
     }
@@ -1563,6 +1564,26 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     }
   }
 
+  /**
+   * Is the payment a pending payment.
+   *
+   * We are moving towards always creating as pending and updating at the end (based on payment), so this should be
+   * an interim refactoring. It was shared with another unrelated form & some parameters may not apply to this form.
+   *
+   *
+   * @return bool
+   */
+  protected function getIsPending() {
+    if (((isset($this->_contributeMode)) || !empty
+        ($this->_params['is_pay_later'])
+      ) &&
+      (($this->_values['is_monetary'] && $this->_amount > 0.0))
+    ) {
+      return TRUE;
+    }
+    return FALSE;
+  }
+
   /**
    * Are we going to do 2 financial transactions.
    *
index 7ae6e3a963a2a5450f977777120e354c15deb379..c8ac51b7d8ac7b7fb29d2d39a57d05ae113e42b5 100644 (file)
@@ -1331,13 +1331,14 @@ AND civicrm_membership.is_test = %2";
    * @param array $membershipLineItems
    *   Line items specific to membership payment that is separate to contribution.
    * @param bool $isPayLater
+   * @param bool $isPending
    *
    * @throws \CRM_Core_Exception
    */
   public static function postProcessMembership(
     $membershipParams, $contactID, &$form, $premiumParams,
     $customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeIDs, $isPaidMembership, $membershipID,
-    $isProcessSeparateMembershipTransaction, $defaultContributionTypeID, $membershipLineItems, $isPayLater) {
+    $isProcessSeparateMembershipTransaction, $defaultContributionTypeID, $membershipLineItems, $isPayLater, $isPending) {
     $result = $membershipContribution = NULL;
     $isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE);
     $errors = $createdMemberships = $paymentResult = array();
@@ -1416,7 +1417,9 @@ AND civicrm_membership.is_test = %2";
           $pendingStatus = CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name');
           $pending = ($membershipContribution->contribution_status_id == $pendingStatus) ? TRUE : FALSE;
         }
-        self::extractPendingFormValue($form, $memType, $pending);
+        else {
+          $pending = $isPending;
+        }
         $membership = self::renewMembershipFormWrapper($contactID, $memType,
           $isTest, $form, date('YmdHis'),
           CRM_Utils_Array::value('cms_contactID', $membershipParams),
@@ -2347,28 +2350,6 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
     ));
   }
 
-  /**
-   * @param array $membershipParams
-   * @param int $contactID
-   * @param $customFieldsFormatted
-   * @param int $membershipID
-   * @param $memType
-   * @param bool $isTest
-   * @param int $numTerms
-   * @param $membershipContribution
-   * @param CRM_Core_Form $form
-   * @param bool $isPending
-   *
-   * @return array
-   */
-  public static function createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted,
-                                                 $membershipID, $memType, $isTest, $numTerms,
-                                                 $membershipContribution, &$form, $isPending) {
-
-
-    return $membership;
-  }
-
   /**
    * Turn array of errors into message string.
    *
@@ -2385,35 +2366,6 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
     return ts('Payment Processor Error message') . ': ' . implode('<br/>', $message);
   }
 
-  /**
-   * Determine if the form has a pending status.
-   *
-   * This is an interim refactoring step. This information should be extracted at the form layer.
-   *
-   * @deprecated
-   *
-   * @param CRM_Core_Form $form
-   * @param int $membershipID
-   *
-   * @return bool
-   */
-  public static function extractPendingFormValue($form, $membershipID, $pending = FALSE) {
-    $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipID);
-    //@todo this is a BAO function & should not inspect the form - the form should do this
-    // & pass required params to the BAO
-    if (CRM_Utils_Array::value('minimum_fee', $membershipTypeDetails) > 0.0) {
-      if (((isset($form->_contributeMode) && $form->_contributeMode == 'notify') || !empty($form->_params['is_pay_later'])
-        ) &&
-        (($form->_values['is_monetary'] && $form->_amount > 0.0) ||
-          CRM_Utils_Array::value('record_contribution', $form->_params)
-        )
-      ) {
-        $pending = TRUE;
-      }
-    }
-    return $pending;
-  }
-
   /**
    * Extract relevant values from the form so we can separate form logic from BAO logcis.
    *
index db484be71981d32ca1432227079c7ecb5acefa62..395ba5126742a0961944befce75b6aa98fe594c6 100644 (file)
@@ -610,6 +610,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     if ($formValues['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
       $this->_params['is_pay_later'] = 1;
     }
+
     $renewMembership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($this->_contactID,
       $formValues['membership_type_id'][1],
       $isTestMembership, $this,
@@ -617,7 +618,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
       NULL,
       $customFieldsFormatted, $numRenewTerms,
       $this->_membershipId,
-      CRM_Member_BAO_Membership::extractPendingFormValue($this, $formValues['membership_type_id'][1])
+      self::extractPendingFormValue($this, $formValues['membership_type_id'][1])
     );
 
     $endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
@@ -792,4 +793,31 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
   }
 
+  /**
+   * Determine if the form has a pending status.
+   *
+   * @deprecated
+   *
+   * @param CRM_Core_Form $form
+   * @param int $membershipID
+   *
+   * @return bool
+   */
+  public static function extractPendingFormValue($form, $membershipID) {
+    $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipID);
+    $pending = FALSE;
+    // @todo function was shared by 2 not-very-related forms & the below may include irrelevant stuff.
+    if (CRM_Utils_Array::value('minimum_fee', $membershipTypeDetails) > 0.0) {
+      if (((isset($form->_contributeMode) && $form->_contributeMode == 'notify') || !empty($form->_params['is_pay_later'])
+        ) &&
+        (($form->_values['is_monetary'] && $form->_amount > 0.0) ||
+          CRM_Utils_Array::value('record_contribution', $form->_params)
+        )
+      ) {
+        $pending = TRUE;
+      }
+    }
+    return $pending;
+  }
+
 }