From: eileen Date: Wed, 20 Feb 2019 13:13:44 +0000 (+1300) Subject: Switch Additional Payment to call Payment.send_confirmation api, strip out text X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=08d0eaac504963b198f771ea632890f76aa96eed;p=civicrm-core.git Switch Additional Payment to call Payment.send_confirmation api, strip out text --- diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index d7c49fa1b3..93cb1e0ee9 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -384,16 +384,8 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $statusMsg = ts('The payment record has been processed.'); // send email if (!empty($result) && !empty($this->_params['is_email_receipt'])) { - $this->_params['contact_id'] = $this->_contactId; - $this->_params['contribution_id'] = $this->_contributionId; - - // These 2 rows are temporarily added for sequencing of adding commits. They won't be needed when we - // switch to Payment.send_confirmation api - $contact = civicrm_api3('Contact', 'getsingle', ['id' => $this->_contactId, 'return' => 'email_greeting']); - $this->assign('emailGreeting', $contact['email_greeting_display']); - - $sendReceipt = $this->emailReceipt($this->_params); - if ($sendReceipt) { + $sendResult = civicrm_api3('Payment', 'sendconfirmation', ['id' => $result->id])['values'][$result->id]; + if ($sendResult['is_sent']) { $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.'); } } @@ -503,88 +495,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract } } - /** - * Function to send email receipt. - * - * @param array $params - * - * @return bool - */ - public function emailReceipt(&$params) { - $templateEngine = CRM_Core_Smarty::singleton(); - // email receipt sending - list($contributorDisplayName, $contributorEmail, $doNotMail) = CRM_Contact_BAO_Contact::getContactDetails($params['contact_id']); - if (!$contributorEmail || $doNotMail) { - return FALSE; - } - $templateEngine->assign('contactDisplayName', $contributorDisplayName); - // send message template - if ($this->_component == 'event') { - - // fetch event information from participant ID using API - $eventId = civicrm_api3('Participant', 'getvalue', array( - 'return' => "event_id", - 'id' => $this->_id, - )); - $event = civicrm_api3('Event', 'getsingle', array('id' => $eventId)); - - $templateEngine->assign('event', $event); - $templateEngine->assign('isShowLocation', $event['is_show_location']); - if (CRM_Utils_Array::value('is_show_location', $event) == 1) { - $locationParams = array( - 'entity_id' => $eventId, - 'entity_table' => 'civicrm_event', - ); - $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE); - $templateEngine->assign('location', $location); - } - } - - // assign payment info here - $paymentConfig['confirm_email_text'] = CRM_Utils_Array::value('confirm_email_text', $params); - $templateEngine->assign('paymentConfig', $paymentConfig); - - $templateEngine->assign('totalAmount', $this->_amtTotal); - - $isRefund = ($this->_paymentType == 'refund') ? TRUE : FALSE; - $templateEngine->assign('isRefund', $isRefund); - if ($isRefund) { - $templateEngine->assign('totalPaid', $this->_amtPaid); - $templateEngine->assign('refundAmount', $params['total_amount']); - } - else { - $balance = $this->_amtTotal - ($this->_amtPaid + $params['total_amount']); - $paymentsComplete = ($balance == 0) ? 1 : 0; - $templateEngine->assign('amountOwed', $balance); - $templateEngine->assign('paymentAmount', $params['total_amount']); - $templateEngine->assign('paymentsComplete', $paymentsComplete); - } - - // assign trxn details - $templateEngine->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $params)); - $templateEngine->assign('receive_date', CRM_Utils_Array::value('trxn_date', $params)); - $templateEngine->assign('paidBy', CRM_Core_PseudoConstant::getLabel( - 'CRM_Contribute_BAO_Contribution', - 'payment_instrument_id', - $params['payment_instrument_id'] - )); - $templateEngine->assign('checkNumber', CRM_Utils_Array::value('check_number', $params)); - - $sendTemplateParams = array( - 'groupName' => 'msg_tpl_workflow_contribution', - 'valueName' => 'payment_or_refund_notification', - 'contactId' => $params['contact_id'], - 'PDFFilename' => ts('notification') . '.pdf', - ); - - $sendTemplateParams['from'] = $params['from_email_address']; - $sendTemplateParams['toName'] = $contributorDisplayName; - $sendTemplateParams['toEmail'] = $contributorEmail; - - list($mailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); - return $mailSent; - } - /** * Wrapper for unit testing the post process submit function. * diff --git a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php index a23b090250..362dc43875 100644 --- a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php @@ -122,6 +122,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); + CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_spool ORDER BY id DESC'); parent::tearDown(); } @@ -150,6 +151,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { ]); $mut->stop(); + $mut->clearMessages(); } /** @@ -185,6 +187,14 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { public function testMultiplePaymentForPartiallyPaidContributionWithOneCreditCardPayment() { $mut = new CiviMailUtils($this, TRUE); $this->createContribution('Partially paid'); + // In general when there is tpl leakage we try to fix. At the moment, however, + // the tpl leakage on credit card related things is kind of 'by-design' - or + // at least we haven't found a way to replace the way in with Payment.send_confirmation + // picks them up from the form process so we will just clear templates here to stop leakage + // from previous tests causing a fail. + // The reason this is hard to fix is that we save a billing address per contribution not + // per payment so it's a problem with the data model + CRM_Core_Smarty::singleton()->clearTemplateVars(); // pay additional amount $this->submitPayment(50, NULL, TRUE); @@ -195,7 +205,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->submitPayment(20, 'live'); $this->checkResults(array(30, 50, 20), 3); $mut->assertSubjects(array('Payment Receipt -')); - $mut->checkMailLog(array( + $mut->checkMailLog([ 'Dear Anthony,', 'A payment has been received', 'Total Fees: $ 100.00', @@ -203,8 +213,13 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'Balance Owed: $ 20.00 ', 'Paid By: Check', 'Check Number: check-12345', - )); + ], + [ + 'Billing Name and Address', + 'Visa', + ]); $mut->stop(); + $mut->clearMessages(); } /**