Skip to content

Commit

Permalink
NFC cleanup to Membership/Renewal form classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire authored and eileenmcnaughton committed Aug 20, 2018
1 parent 77727ea commit c26225d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
22 changes: 13 additions & 9 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,6 @@ public function submit() {
$formValues = $this->setPriceSetParameters($formValues);
$params = $softParams = $ids = array();

$allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
$allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$this->processBillingAddress();

if ($this->_id) {
Expand Down Expand Up @@ -1178,7 +1176,6 @@ public function submit() {
$params['tax_amount'] = $formValues['tax_amount'];
}
$params['total_amount'] = CRM_Utils_Array::value('amount', $formValues);
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
if (!empty($lineItem[$this->_priceSetId])) {
foreach ($lineItem[$this->_priceSetId] as &$li) {
if (!empty($li['membership_type_id'])) {
Expand All @@ -1190,6 +1187,7 @@ public function submit() {
///CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
if ($isQuickConfig && $submittedFinancialType) {
$li['financial_type_id'] = $submittedFinancialType;
}
Expand Down Expand Up @@ -1251,9 +1249,9 @@ public function submit() {
}
}

// max related memberships - take from form or inherit from membership type
foreach ($this->_memTypeSelected as $memType) {
if (array_key_exists('max_related', $formValues)) {
// max related memberships - take from form or inherit from membership type
$membershipTypeValues[$memType]['max_related'] = CRM_Utils_Array::value('max_related', $formValues);
}
$membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues,
Expand All @@ -1278,6 +1276,9 @@ public function submit() {
$softParams['contact_id'] = $this->_contactID;
}
}

$pendingMembershipStatusId = CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending');

if (!empty($formValues['record_contribution'])) {
$recordContribution = array(
'total_amount',
Expand Down Expand Up @@ -1308,10 +1309,11 @@ public function submit() {
}
}

$completedContributionStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
if (empty($params['is_override']) &&
CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Completed', $allContributionStatus)
CRM_Utils_Array::value('contribution_status_id', $params) != $completedContributionStatusId
) {
$params['status_id'] = array_search('Pending', $allMemberStatus);
$params['status_id'] = $pendingMembershipStatusId;
$params['skipStatusCal'] = TRUE;
$params['is_pay_later'] = 1;
$this->assign('is_pay_later', 1);
Expand Down Expand Up @@ -1430,12 +1432,14 @@ public function submit() {
$ids['contribution'] = $contribution->id;
$params['contribution_recur_id'] = $paymentParams['contributionRecurID'];
}
$paymentStatus = NULL;

if ($params['total_amount'] > 0.0) {
$payment = $this->_paymentProcessor['object'];
try {
$result = $payment->doPayment($paymentParams);
$formValues = array_merge($formValues, $result);
$paymentStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $formValues['payment_status_id']);
// Assign amount to template if payment was successful.
$this->assign('amount', $params['total_amount']);
}
Expand All @@ -1456,8 +1460,8 @@ public function submit() {
}
}

if ($formValues['payment_status_id'] != array_search('Completed', $allContributionStatus)) {
$params['status_id'] = array_search('Pending', $allMemberStatus);
if ($paymentStatus !== 'Completed') {
$params['status_id'] = $pendingMembershipStatusId;
$params['skipStatusCal'] = TRUE;
// unset send-receipt option, since receipt will be sent when ipn is received.
unset($formValues['send_receipt'], $formValues['send_receipt']);
Expand All @@ -1475,7 +1479,7 @@ public function submit() {
}
}
$now = date('YmdHis');
$params['receive_date'] = $now;
$params['receive_date'] = date('YmdHis');
$params['invoice_id'] = $formValues['invoiceID'];
$params['contribution_source'] = ts('%1 Membership Signup: Credit card or direct debit (by %2)',
array(1 => $membershipType, 2 => $userName)
Expand Down
9 changes: 9 additions & 0 deletions tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ public function testSubmitPartialPayment($thousandSeparator) {
* Test the submit function of the membership form.
*/
public function testSubmitRecur() {
CRM_Core_Session::singleton()->getStatus(TRUE);
$pendingVal = $this->callAPISuccessGetValue('OptionValue', array(
'return' => "id",
'option_group_id' => "contribution_status",
Expand Down Expand Up @@ -767,6 +768,14 @@ public function testSubmitRecur() {
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
), 1);
$this->assertEquals([
[
'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been added. The new membership End Date is ' . date('F jS, Y', strtotime('last day of this month')) . ' 12:00 AM.',
'title' => 'Complete',
'type' => 'success',
'options' => NULL,
],
], CRM_Core_Session::singleton()->getStatus());
}

/**
Expand Down

0 comments on commit c26225d

Please sign in to comment.