Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20008 fix pending flow. #10030

Merged
merged 1 commit into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 42 additions & 33 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4548,43 +4548,52 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
}
$dao->free();

$membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change is just indentation - the if -else block

$membershipParams['membership_type_id'],
$primaryContributionID
);
$dates = array_fill_keys(array('join_date', 'start_date', 'end_date'), NULL);
if ($currentMembership) {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
* when Contribution mode is notify and membership is for renewal )
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);

// @todo - we should pass membership_type_id instead of null here but not
// adding as not sure of testing
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
$changeDate, NULL, $membershipParams['num_terms']
);

$dates['join_date'] = $currentMembership['join_date'];
if (CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $input)) === 'Pending') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!! Yeah, makes sense to add coverage for the whole process.

$membershipParams['num_terms'] = 0;
}
else {
$membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the else block is just formatting

$membershipParams['membership_type_id'],
$primaryContributionID
);
// @todo remove all this stuff in favour of letting the api call further down handle in
// (it is a duplication of what the api does).
$dates = array_fill_keys(array('join_date', 'start_date', 'end_date'), NULL);
if ($currentMembership) {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
* when Contribution mode is notify and membership is for renewal )
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);

// @todo - we should pass membership_type_id instead of null here but not
// adding as not sure of testing
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
$changeDate, NULL, $membershipParams['num_terms']
);

$dates['join_date'] = $currentMembership['join_date'];
}

//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
$dates['end_date'],
$dates['join_date'],
'today',
TRUE,
$membershipParams['membership_type_id'],
$membershipParams
);
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
$dates['end_date'],
$dates['join_date'],
'today',
TRUE,
$membershipParams['membership_type_id'],
$membershipParams
);

$membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
//we might be renewing membership,
//so make status override false.
$membershipParams['is_override'] = FALSE;
unset($dates['end_date']);
$membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
//we might be renewing membership,
//so make status override false.
$membershipParams['is_override'] = FALSE;
}
//CRM-17723 - reset static $relatedContactIds array()
// @todo move it to Civi Statics.
$var = TRUE;
CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
civicrm_api3('Membership', 'create', $membershipParams);
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3419,6 +3419,45 @@ public function testRepeatTransactionWithNonCreditCardDefault() {
$this->quickCleanUpFinancialEntities();
}

/**
* CRM-20008 Tests repeattransaction creates pending membership.
*/
public function testRepeatTransactionPendingMembership() {
list($originalContribution, $membership) = $this->setUpAutoRenewMembership();
$this->callAPISuccess('membership', 'create', array(
'id' => $membership['id'],
'end_date' => 'yesterday',
'status_id' => 'Expired',
));
$repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => 'Pending',
'trxn_id' => uniqid(),
));
$membershipStatusId = $this->callAPISuccess('membership', 'getvalue', array(
'id' => $membership['id'],
'return' => 'status_id',
));

// Let's see if the membership payments got created while we're at it.
$membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', array(
'memberhip_id' => $membership['id'],
));
$this->assertEquals(2, $membershipPayments['count']);

$this->assertEquals('Expired', CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'status_id', $membershipStatusId));
$this->callAPISuccess('Contribution', 'completetransaction', array('id' => $repeatedContribution['id']));
$membership = $this->callAPISuccessGetSingle('membership', array(
'id' => $membership['id'],
'return' => 'status_id, end_date',
));
$this->assertEquals('New', CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'status_id', $membership['status_id']));
$this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 month')), $membership['end_date']);

$this->quickCleanUpFinancialEntities();
$this->contactDelete($originalContribution['values'][1]['contact_id']);
}

/**
* Test sending a mail via the API.
*/
Expand Down