Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-19710 - Preserve is_email_receipt parameter through to email sent #9487

Closed
wants to merge 9 commits into from
14 changes: 13 additions & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2438,9 +2438,14 @@ public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $r
if (empty($this->_component)) {
$this->_component = CRM_Utils_Array::value('component', $input);
}
if (isset($input['is_email_receipt'])) {
$values['is_email_receipt'] = $input['is_email_receipt'];
}

// Store values in a temp variable, so they don't get lost after _gatherMessageValues
$tmp_values = $values;
//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 = array_merge($this->_gatherMessageValues($input, $values, $ids), $tmp_values);
if (!empty($input['receipt_date'])) {
$values['receipt_date'] = $input['receipt_date'];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agileware Can we assign $values after _gatherMessageValues() is done similar to receipt_date? Since we could avoid defining $tmp_values in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can, but if any extra options are passed through in $values that differ from any options after _gatherMessageValues(), they'll be lost anyway.

e.g. If receipt_from_email is passed along in $values, but differs from whatever is retrieved after _gatherMessageValues().

Not sure if/when this would ever be a problem. If you think it's not an issue, let me know and we'll adjust the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ditch this bit because I feel it's blocking the PR. That function is only called from here & ideally it would be dismantled into the calling function in bits e.g

extract this

    if ($this->address_id) {
      $addressParams = array('id' => $this->address_id);
      $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
      $addressDetails = array_values($addressDetails);
    }
    // Else we assign the billing address of the contribution contact.
    else {
      $addressParams = array('contact_id' => $this->contact_id, 'is_billing' => 1);
      $addressDetails = (array) CRM_Core_BAO_Address::getValues($addressParams);
      $addressDetails = array_values($addressDetails);
    }

    if (!empty($addressDetails[0]['display'])) {
      $values['address'] = $addressDetails[0]['display'];
    }

into a function & call from composeMessageArray, ideally with tests, and possibly some review of how consistently that address token is used.

slow & painful, yes.

Expand Down Expand Up @@ -2507,6 +2512,11 @@ public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $r
$values['totalAmount'] = $input['amount'];
}

// Set the value of is_email_confirm to the argument supplied in is_email_receipt, if available.
if (isset($input['is_email_receipt'])) {
$values['event']['is_email_confirm'] = $input['is_email_receipt'];
}

if ($values['event']['is_email_confirm']) {
$values['is_email_receipt'] = 1;
}
Expand Down Expand Up @@ -4461,6 +4471,7 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
'receive_date',
'receipt_date',
'contribution_status_id',
'is_email_receipt',
);
if (self::isSingleLineItem($primaryContributionID)) {
$inputContributionWhiteList[] = 'financial_type_id';
Expand Down Expand Up @@ -4684,6 +4695,7 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
civicrm_api3('Contribution', 'sendconfirmation', array(
'id' => $contribution->id,
'payment_processor_id' => $paymentProcessorId,
'is_email_receipt' => CRM_Utils_Array::value('is_email_receipt', $values),
));
CRM_Core_Error::debug_log_message("Receipt sent");
}
Expand Down
1 change: 1 addition & 0 deletions api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ function civicrm_api3_contribution_sendconfirmation($params) {
'bcc_receipt',
'receipt_text',
'payment_processor_id',
'is_email_receipt',
);
$input = array_intersect_key($params, array_flip($allowedParams));
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id'], $values);
Expand Down
30 changes: 30 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,36 @@ public function testCompleteTransactionWithEmailReceiptInput() {
$this->assertEquals('', $receipt_date);
}

/**
* CRM-19710 - Test to ensure that completetransaction respects the is_email_receipt setting, overriding default from contrib page
*/
public function testCompleteTransactionWithEmailReceiptInputTrue() {
$mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
// Create a Contribution Page with is_email_receipt = FALSE
$contributionPage = $this->callAPISuccess('ContributionPage', 'create', array(
'receipt_from_name' => 'Mickey Mouse',
'receipt_from_email' => '[email protected]',
'title' => "Test Contribution Page",
'financial_type_id' => 1,
'currency' => 'CAD',
'is_monetary' => TRUE,
'is_email_receipt' => 0,
));
$this->_params['contribution_page_id'] = $contributionPage['id'];
$params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
$contribution = $this->callAPISuccess('contribution', 'create', $params);
// Complete the transaction overriding is_email_receipt to = TRUE
$this->callAPISuccess('contribution', 'completetransaction', array(
'id' => $contribution['id'],
'is_email_receipt' => 1,
));
$mut->checkMailLog(array(
'Please print this receipt for your records.',
));
$mut->stop();
}

/**
* Complete the transaction using the template with all the possible.
*/
Expand Down