Skip to content

Commit

Permalink
Merge pull request #26078 from mattwire/contribclean
Browse files Browse the repository at this point in the history
REF: Small cleanup on contribution receipt code
  • Loading branch information
seamuslee001 authored May 8, 2023
2 parents 8f1d002 + 8477e25 commit 5a0bec6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
29 changes: 13 additions & 16 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2472,20 +2472,19 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
$this->_component = 'event';
}
else {
$this->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute'));
$this->_component = $input['component'] ?? 'contribute';
}
}
// @todo remove strtolower - check consistency
$this->_component = strtolower($this->_component);

// If the object is not fully populated then make sure it is - this is a more about legacy paths & cautious
// refactoring than anything else, and has unit test coverage.
if (empty($this->financial_type_id)) {
$this->find(TRUE);
}

$paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $input, CRM_Utils_Array::value(
'paymentProcessor',
$ids
));
$paymentProcessorID = $input['payment_processor_id'] ?? $ids['paymentProcessor'] ?? NULL;

if (!isset($input['payment_processor_id']) && !$paymentProcessorID && $this->contribution_page_id) {
$paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
Expand All @@ -2498,10 +2497,7 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
}

$this->loadRelatedObjects($paymentProcessorID, $ids);

if (empty($this->_component)) {
$this->_component = $input['component'] ?? NULL;
}
$paymentProcessor = $this->_relatedObjects['paymentProcessor'] ?? NULL;

//not really sure what params might be passed in but lets merge em into values
$values = array_merge($this->_gatherMessageValues($input, $values, $ids), $values);
Expand All @@ -2515,16 +2511,16 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
$template = $this->_assignMessageVariablesToTemplate($values, $input, $returnMessageText);
//what does recur 'mean here - to do with payment processor return functionality but
// what is the importance
if (!empty($this->contribution_recur_id) && !empty($this->_relatedObjects['paymentProcessor'])) {
$paymentObject = Civi\Payment\System::singleton()->getByProcessor($this->_relatedObjects['paymentProcessor']);
if (!empty($this->contribution_recur_id) && !empty($paymentProcessor)) {
$paymentObject = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor);

$entityID = $entity = NULL;
if (isset($ids['contribution'])) {
$entity = 'contribution';
$entityID = $ids['contribution'];
}
if (!empty($ids['membership'])) {
//not sure whether is is possible for this not to be an array - load related contacts loads an array but this code was expecting a string
// not sure whether it is possible for this not to be an array - load related contacts loads an array but this code was expecting a string
// the addition of the casting is in case it could get here & be a string. Added in 4.6 - maybe remove later? This AuthorizeNetIPN & PaypalIPN tests hit this
// line having loaded an array
$ids['membership'] = (array) $ids['membership'];
Expand All @@ -2536,16 +2532,17 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
$template->assign('updateSubscriptionBillingUrl', $paymentObject->subscriptionURL($entityID, $entity, 'billing'));
$template->assign('updateSubscriptionUrl', $paymentObject->subscriptionURL($entityID, $entity, 'update'));
}
// todo remove strtolower - check consistency
if (strtolower($this->_component) === 'event') {
$eventParams = ['id' => $this->_relatedObjects['participant']->event_id];

if ($this->_component === 'event') {
$eventID = $this->_relatedObjects['participant']->event_id;
$eventParams = ['id' => $eventID];
$values['event'] = [];

CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);

//get location details
$locationParams = [
'entity_id' => $this->_relatedObjects['participant']->event_id,
'entity_id' => $eventID,
'entity_table' => 'civicrm_event',
];
$values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
Expand Down
3 changes: 1 addition & 2 deletions api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ function _civicrm_api3_contribute_format_params($params, &$values) {
* @throws Exception
*/
function civicrm_api3_contribution_sendconfirmation($params) {
$ids = [];
$allowedParams = [
'receipt_from_email',
'receipt_from_name',
Expand All @@ -404,7 +403,7 @@ function civicrm_api3_contribution_sendconfirmation($params) {
'payment_processor_id',
];
$input = array_intersect_key($params, array_flip($allowedParams));
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id']);
CRM_Contribute_BAO_Contribution::sendMail($input, [], $params['id']);
return [];
}

Expand Down

0 comments on commit 5a0bec6

Please sign in to comment.