diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 2937689fd2be..db99e14b493f 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2801,6 +2801,11 @@ public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $template->assign('first_name', $this->_relatedObjects['contact']->first_name); $template->assign('last_name', $this->_relatedObjects['contact']->last_name); $template->assign('displayName', $this->_relatedObjects['contact']->display_name); + + // For some unit tests contribution cannot contain paymentProcessor information + $billingMode = empty($this->_relatedObjects['paymentProcessor']) ? CRM_Core_Payment::BILLING_MODE_NOTIFY : $this->_relatedObjects['paymentProcessor']['billing_mode']; + $template->assign('contributeMode', CRM_Utils_Array::value($billingMode, CRM_Core_SelectValues::contributeMode())); + if (!empty($values['lineItem']) && !empty($this->_relatedObjects['membership'])) { $values['useForMember'] = TRUE; } @@ -2884,7 +2889,6 @@ public function _assignMessageVariablesToTemplate(&$values, $input, &$template, CRM_Utils_Date::processDate($this->receive_date) ); $values['receipt_date'] = (empty($this->receipt_date) ? NULL : $this->receipt_date); - $template->assign('contributeMode', 'notify'); $template->assign('action', $this->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index af7f6510b86c..c316d6adbbcf 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -1012,6 +1012,17 @@ public static function billingMode() { ); } + /** + * @return array + */ + public static function contributeMode() { + return array( + CRM_Core_Payment::BILLING_MODE_FORM => 'direct', + CRM_Core_Payment::BILLING_MODE_BUTTON => 'directIPN', + CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify', + ); + } + /** * Frequency unit for schedule reminders. * diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 498493607cc4..d3d1ca43caef 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2593,9 +2593,36 @@ public function testSendMail() { 'Event', ) ); + + $this->checkCreditCardDetails($mut, $contribution['id']); $mut->stop(); } + /** + * Check credit card details in sent mail via API + * + * @param $mut obj CiviMailUtils instance + * @param int $contributionID Contribution ID + * + */ + public function checkCreditCardDetails($mut, $contributionID) { + $contribution = $this->callAPISuccess('contribution', 'create', $this->_params); + $this->callAPISuccess('contribution', 'sendconfirmation', array( + 'id' => $contributionID, + 'receipt_from_email' => 'api@civicrm.org', + 'payment_processor_id' => $this->paymentProcessorID, + ) + ); + $mut->checkMailLog(array( + 'Credit Card Information', // credit card header + 'Billing Name and Address', // billing header + 'anthony_anderson@civicrm.org', // billing name + ), array( + 'Event', + ) + ); + } + /** * Test sending a mail via the API. */