From 8bc79dfc4e5540c485dfa95aedf90621f60720ab Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 28 Jun 2015 08:54:22 +1200 Subject: [PATCH] CRM-16471 post refactoring - extract pending status from form --- CRM/Contribute/Form/Contribution/Confirm.php | 25 ++++++++- CRM/Member/BAO/Membership.php | 58 ++------------------ CRM/Member/Form/MembershipRenewal.php | 30 +++++++++- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 464a97cda4..25a78f13e5 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -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. * diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 7ae6e3a963..c8ac51b7d8 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -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('
', $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. * diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index db484be719..395ba51267 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -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; + } + } -- 2.25.1