From 94db3e6e42f46c2df90603c616b520cb3053765c Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Sun, 11 Oct 2020 19:10:04 +0530 Subject: [PATCH] Fix sendconfirmation api to respect cc and bcc set in params --- CRM/Contribute/BAO/Contribution.php | 6 ++-- tests/phpunit/api/v3/ContributionTest.php | 37 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index c279e4df90..c6c68d9063 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2956,8 +2956,10 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac //not really sure what params might be passed in but lets merge em into values $values = array_merge($this->_gatherMessageValues($input, $values, $ids), $values); $values['is_email_receipt'] = !$returnMessageText; - if (!empty($input['receipt_date'])) { - $values['receipt_date'] = $input['receipt_date']; + foreach (['receipt_date', 'cc_receipt', 'bcc_receipt', 'receipt_from_name', 'receipt_from_email', 'receipt_text'] as $fld) { + if (!empty($input[$fld])) { + $values[$fld] = $input[$fld]; + } } $template = $this->_assignMessageVariablesToTemplate($values, $input, $returnMessageText); diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index deb2226133..0382b9fcff 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -3715,6 +3715,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ], [ 'Event', ]); + $this->checkReceiptDetails($mut, $contributionPage['id'], $contribution['id']); $mut->stop(); } @@ -3743,6 +3744,42 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ]); } + /** + * Check receipt details in sent mail via API + * + * @param CiviMailUtils $mut + * @param int $pageID Page ID + * @param int $contributionID Contribution ID + * + * @throws \CRM_Core_Exception + */ + public function checkReceiptDetails($mut, $pageID, $contributionID) { + $pageReceipt = [ + 'receipt_from_name' => "Page FromName", + 'receipt_from_email' => "page_from@email.com", + 'cc_receipt' => "page_cc@email.com", + 'receipt_text' => "Page Receipt Text", + ]; + $customReceipt = [ + 'receipt_from_name' => "Custom FromName", + 'receipt_from_email' => "custom_from@email.com", + 'cc_receipt' => "custom_cc@email.com", + 'receipt_text' => "Test Custom Receipt Text", + ]; + $this->callAPISuccess('ContributionPage', 'create', array_merge([ + 'id' => $pageID, + 'is_email_receipt' => 1, + ], $pageReceipt)); + + $this->callAPISuccess('contribution', 'sendconfirmation', array_merge([ + 'id' => $contributionID, + 'payment_processor_id' => $this->paymentProcessorID, + ], $customReceipt)); + + //Verify if custom receipt details are present in email. + $mut->checkMailLog(array_values($customReceipt), array_values($pageReceipt)); + } + /** * Test sending a mail via the API. */ -- 2.25.1