Fix sendconfirmation api to respect cc and bcc set in params
authorJitendra Purohit <jitendra@fuzion.co.nz>
Sun, 11 Oct 2020 13:40:04 +0000 (19:10 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Sat, 17 Oct 2020 08:48:50 +0000 (14:18 +0530)
CRM/Contribute/BAO/Contribution.php
tests/phpunit/api/v3/ContributionTest.php

index c279e4df9045fd21534d58bd39d7bd2748413df8..c6c68d90632b11a50e56d2d880f68c6c71b4e3cc 100644 (file)
@@ -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);
index deb222613378c4cb3afc68d7ecfd63ea627ec9a8..0382b9fcff2dc4463906673e9f84b5d4d93e49d7 100644 (file)
@@ -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.
    */