Skip to content

Commit

Permalink
Merge pull request #9447 from monishdeb/CRM-19678
Browse files Browse the repository at this point in the history
CRM-19678: No Membership Renewal Activity is created when a Pay Later is set to Completed
  • Loading branch information
eileenmcnaughton authored Nov 28, 2016
2 parents 269eee9 + 0f07bb0 commit 08e132b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,9 @@ public static function transitionComponents($params, $processContributionObject
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formattedParams);

//CRM-19678: No Membership Renewal Activity is created when a Pay Later is set to Completed
CRM_Activity_BAO_Activity::addActivity($membership, 'Membership Renewal', $membership->contact_id);

$updateResult['membership_end_date'] = CRM_Utils_Date::customFormat($dates['end_date'],
'%B %E%f, %Y'
);
Expand Down
1 change: 1 addition & 0 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ public function testSubmit($params, $action, $creditCardMode = NULL) {
'id' => $params['id'],
));
$this->_id = $params['id'];
$this->_values = $existingContribution;
}
else {
$existingContribution = array();
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ public function participantCreate($params) {
* @return int
* Id Payment Processor
*/
public function processorCreate() {
public function processorCreate($params = array()) {
$processorParams = array(
'domain_id' => 1,
'name' => 'Dummy',
Expand All @@ -1377,6 +1377,7 @@ public function processorCreate() {
'sequential' => 1,
'payment_instrument_id' => 'Debit Card',
);
$processorParams = array_merge($processorParams, $params);
$processor = $this->callAPISuccess('PaymentProcessor', 'create', $processorParams);
return $processor['id'];
}
Expand Down
61 changes: 60 additions & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,65 @@ public function testCompleteTransactionMembershipPriceSet() {
$this->cleanUpAfterPriceSets();
}

/**
* Test if renewal activity is create after changing Pending contribution to Completed via offline
*/
public function testPendingToCompleteContribution() {
$contributionPage = $this->createPriceSetWithPage('membership');
$stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array(
'name' => 'Grace',
'return' => 'id')
);
$this->setUpPendingContribution($this->_ids['price_field_value'][0]);
$this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));

// change pending contribution to completed
$form = new CRM_Contribute_Form_Contribution();
$error = FALSE;
$form->_params = array(
'id' => $this->_ids['contribution'],
'total_amount' => 20,
'net_amount' => 20,
'fee_amount' => 0,
'financial_type_id' => 1,
'receive_date' => '04/21/2015',
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
'billing_middle_name' => '',
'billing_last_name' => 'Adams',
'billing_street_address-5' => '790L Lincoln St S',
'billing_city-5' => 'Maryknoll',
'billing_state_province_id-5' => 1031,
'billing_postal_code-5' => 10545,
'billing_country_id-5' => 1228,
'frequency_interval' => 1,
'frequency_unit' => 'month',
'installments' => '',
'hidden_AdditionalDetail' => 1,
'hidden_Premium' => 1,
'from_email_address' => '"civi45" <civi45@civicrm.com>',
'receipt_date' => '',
'receipt_date_time' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_mode' => 'membership',
'source' => 'Membership Signup and Renewal',
);
try {
$form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
}
catch (Civi\Payment\Exception\PaymentProcessorException $e) {
$error = TRUE;
}
$activity = $this->callAPISuccess('Activity', 'get', array(
'activity_type_id' => 'Membership Renewal',
'source_record_id' => $this->_ids['contribution'],
));
$this->assertEquals(1, $activity['count']);
}

/**
* Test membership is renewed when transaction completed.
*/
Expand Down Expand Up @@ -2531,7 +2590,7 @@ public function setUpPendingContribution($priceFieldValueID) {
'domain_id' => 1,
'contact_id' => $contactID,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
'total_amount' => 20.00,
'financial_type_id' => 1,
'payment_instrument_id' => 'Credit Card',
'non_deductible_amount' => 10.00,
Expand Down

0 comments on commit 08e132b

Please sign in to comment.