Skip to content

Commit

Permalink
Merge pull request #18358 from eileenmcnaughton/event
Browse files Browse the repository at this point in the history
Use eventID rather than the object in completeTransaction
  • Loading branch information
seamuslee001 authored Sep 5, 2020
2 parents 587db57 + 7ba7175 commit b89e8c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4406,7 +4406,7 @@ public static function completeOrder($input, $ids, $objects, $isPostPaymentCreat
'financial_type_id',
];

$event = $objects['event'] ?? NULL;
$eventID = $objects['event']->id ?? NULL;

$paymentProcessorId = '';
if (isset($objects['paymentProcessor'])) {
Expand All @@ -4422,7 +4422,7 @@ public static function completeOrder($input, $ids, $objects, $isPostPaymentCreat

$contributionParams = array_merge([
'contribution_status_id' => $completedContributionStatusID,
'source' => self::getRecurringContributionDescription($contribution, $event),
'source' => self::getRecurringContributionDescription($contribution, $eventID),
], array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)
));

Expand Down Expand Up @@ -4636,12 +4636,12 @@ public function loadRelatedMembershipObjects($ids = []) {
* Get the description (source field) for the recurring contribution.
*
* @param CRM_Contribute_BAO_Contribution $contribution
* @param CRM_Event_DAO_Event|null $event
* @param int|null $eventID
*
* @return string
* @throws \CiviCRM_API3_Exception
*/
protected static function getRecurringContributionDescription($contribution, $event) {
protected static function getRecurringContributionDescription($contribution, $eventID) {
if (!empty($contribution->source)) {
return $contribution->source;
}
Expand All @@ -4652,8 +4652,8 @@ protected static function getRecurringContributionDescription($contribution, $ev
]);
return ts('Online Contribution') . ': ' . $contributionPageTitle;
}
elseif ($event) {
return ts('Online Event Registration') . ': ' . $event->title;
elseif ($eventID) {
return ts('Online Event Registration') . ': ' . CRM_Event_PseudoConstant::event($eventID);
}
elseif (!empty($contribution->contribution_recur_id)) {
return 'recurring contribution';
Expand Down
9 changes: 5 additions & 4 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3316,16 +3316,17 @@ public function testCompleteTransactionWithParticipantRecord() {
$mut = new CiviMailUtils($this, TRUE);
$mut->clearMessages();
$this->_individualId = $this->createLoggedInUser();
// Unset source to test whether one is generated if not set already on the contribution.
unset($this->_params['source']);
$contributionID = $this->createPendingParticipantContribution();
$this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event']);
$this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event', 'weight' => 2], ['name' => 'post_1', 'title' => 'title_post_2', 'frontend_title' => 'public 2']);
$this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event', 'weight' => 3], ['name' => 'post_2', 'title' => 'title_post_3', 'frontend_title' => 'public 3']);
$this->eliminateUFGroupOne();

$this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contributionID,
]
);
$this->callAPISuccess('contribution', 'completetransaction', ['id' => $contributionID]);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID, 'return' => ['contribution_source']]);
$this->assertEquals('Online Event Registration: Annual CiviCRM meet', $contribution['contribution_source']);
$participantStatus = $this->callAPISuccessGetValue('participant', [
'id' => $this->_ids['participant'],
'return' => 'participant_status_id',
Expand Down

0 comments on commit b89e8c1

Please sign in to comment.