);
$contributionStatusID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionId, 'contribution_status_id');
if ($contributionStatuses[$contributionStatusID] == 'Pending') {
+ // CRM-20432, Updating the Pending status of Membership Record along with contribution.
+ // Updating the membership status to Current from Pending.
+ //
+ // Updating the status directly here is good idea instead of doing it at Schedule job level,
+ // In which we may have to go through all the memberships which are pending and then their contributions of each.
+ // Which could make the process slower and time consuming for large records.
+ $membershipStatuses = CRM_Member_PseudoConstant::membershipStatus();
+ $pendingStatusId = array_search('Pending', $membershipStatuses);
+
+ $membership_payments = civicrm_api3('membership_payment', 'get',
+ array(
+ 'contribution_id' => $this->_contributionId,
+ 'membership_id.status_id' => $pendingStatusId,
+ )
+ );
+
+ if ($membership_payments["count"] > 0) {
+ $membership_payments = $membership_payments["values"];
+ foreach ($membership_payments as $membership_payment) {
+ $membership_id = $membership_payment["membership_id"];
+ $membership = civicrm_api3('Membership', 'getsingle', array(
+ 'id' => $membership_id,
+ ));
+ $currentStatusId = array_search('Current', $membershipStatuses);
+ $membership["status_id"] = $currentStatusId;
+ civicrm_api3('Membership', 'create', $membership);
+ }
+ }
civicrm_api3('Contribution', 'create',
array(
'id' => $this->_contributionId,
$this->checkResults(array(30, 70), 2);
}
+ /**
+ * Test the Membership status after completing the pending pay later Contribution.
+ */
+ public function testMembershipStatusAfterCompletingPayLaterContribution() {
+ $this->createContribution('Pending');
+ $membership = $this->createPendingMembershipAndRecordContribution($this->_contributionId);
+ // pay additional amount
+ $this->submitPayment(100);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contributionMembership = $this->callAPISuccessGetSingle('Membership', array('id' => $membership["id"]));
+ $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', array('id' => $contributionMembership["status_id"]));
+ $this->assertEquals('Current', $membershipStatus['name']);
+ }
+
+ private function createPendingMembershipAndRecordContribution($contributionId) {
+ $this->_individualId = $this->individualCreate();
+ $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
+ 'domain_id' => 1,
+ 'name' => "AnnualFixed",
+ 'member_of_contact_id' => 1,
+ 'duration_unit' => "year",
+ 'duration_interval' => 1,
+ 'period_type' => "fixed",
+ 'fixed_period_start_day' => "101",
+ 'fixed_period_rollover_day' => "1231",
+ 'relationship_type_id' => 20,
+ 'financial_type_id' => 2,
+ ));
+ $membershipStatuses = CRM_Member_PseudoConstant::membershipStatus();
+ $pendingStatusId = array_search('Pending', $membershipStatuses);
+ $membership = $this->callAPISuccess('Membership', 'create', array(
+ 'contact_id' => $this->_individualId,
+ 'membership_type_id' => $membershipTypeAnnualFixed['id'],
+ ));
+ // Updating Membership status to Pending
+ $membership = $this->callAPISuccess('Membership', 'create', array(
+ 'id' => $membership["id"],
+ 'status_id' => $pendingStatusId,
+ ));
+ $membershipPayment = $this->callAPISuccess('MembershipPayment', 'create', array(
+ 'membership_id' => $membership["id"],
+ 'contribution_id' => $contributionId,
+ ));
+ return $membership;
+ }
+
/**
* Test the submit function that completes the pending pay later Contribution with multiple payments.
*/