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 repattrasasction create pending membership with pending con… #9827

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 30 additions & 1 deletion api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,36 @@ function civicrm_api3_contribution_repeattransaction(&$params) {
);
$input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));

return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
$notRenewing = array('Failed', 'Overdue', 'Refunded', 'Partially paid', 'Pending refund', 'Chargeback');
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');

// CRM-20008 create pending memberships with pending contribution.
if (isset($params['contribution_status_id']) && isset($contribution->_relatedObjects['membership']) && ($contributionStatuses[$params['contribution_status_id']] == 'Pending')) {
$contribution->_relatedObjects['memberships_pending'] = $contribution->_relatedObjects['membership'];
unset($contribution->_relatedObjects['membership']);
foreach ($contribution->_relatedObjects['memberships_pending'] as $membership) {
$pendingMembership = civicrm_api3('Membership', 'create', array(
'id' => $membership->id,
'membership_type_id' => $membership->membership_type_id,
'contact_id' => $membership->contact_id,
'contribution_recur_id' => $membership->contribution_recur_id,
'num_terms' => 1,
'status_id' => 'Pending',
));
}
}

$ipnProcessTransaction = _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
// Create any neccesary any Membership Payments now that we have a contribution id.
if (isset($params['contribution_status_id']) && isset($contribution->_relatedObjects['memberships_pending']) && ($contributionStatuses[$params['contribution_status_id']] == 'Pending')) {
foreach ($contribution->_relatedObjects['memberships_pending'] as $membership) {
civicrm_api3('MembershipPayment', 'create', array(
'contribution_id' => $ipnProcessTransaction['id'],
'membership_id' => $membership->id,
));
}
}
return $ipnProcessTransaction;
}
catch(Exception $e) {
throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
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 @@ -2131,6 +2131,44 @@ public function testRepeatTransactionUsesCompleted() {
$this->contactDelete($originalContribution['values'][1]['contact_id']);
}

/**
* 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' => 4,
));

$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',
));
// Return the name for our memebership status id.
$membershipStatusName = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus',
$membershipStatusId,
'label', 'id'
);
// Let's see if the membership payments got created while we're at it.
$membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', array(
'contribution_id' => $repeatedContribution['id'],
));

$this->assertNotEquals(0, $membershipPayments['count']);
$this->assertEquals('Pending', $membershipStatusName);
$this->quickCleanUpFinancialEntities();
$this->contactDelete($originalContribution['values'][1]['contact_id']);
}

/**
* CRM-16397 test appropriate action if total amount has changed for single line items.
*/
Expand Down Expand Up @@ -3213,6 +3251,7 @@ protected function setUpAutoRenewMembership($generalParams = array(), $recurPara
'financial_type_id' => "Member Dues",
'duration_unit' => "month",
'duration_interval' => 1,
'period_type' => 'rolling',
'name' => "Standard Member",
'minimum_fee' => 100,
));
Expand Down