From 6c266de6ff3cd2c42407f4cc30d5ce40922ae342 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 13 Mar 2017 10:03:06 +1300 Subject: [PATCH 1/3] Remove deprecated function call from test --- tests/phpunit/api/v3/ContributionTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index d81434af900c..79b1926835ac 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -822,6 +822,9 @@ public function testCreateContributionWithSoftCreditDefaults() { $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); } + /** + * Test creating contribution with Soft Credit by passing in honor_contact_id. + */ public function testCreateContributionWithHonoreeContact() { $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id."; $subfile = "ContributionCreateWithHonoreeContact"; @@ -839,7 +842,8 @@ public function testCreateContributionWithHonoreeContact() { // Default soft credit amount = contribution.total_amount // Legacy mode in create api (honor_contact_id param) uses the standard "In Honor of" soft credit type $this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']); - $this->assertEquals(CRM_Core_OptionGroup::getValue('soft_credit_type', 'in_honor_of', 'name'), $result['values'][0]['soft_credit'][1]['soft_credit_type']); + $softCreditValueTypeID = $result['values'][0]['soft_credit'][1]['soft_credit_type']; + $this->assertEquals('in_honor_of', CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $softCreditValueTypeID)); $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id'])); $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id'])); From d891a27350adb239c786c02d0f26decaea9bb328 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 13 Mar 2017 10:54:13 +1300 Subject: [PATCH 2/3] CRM-20247 Add test & ensure $is_recur is assigned to the message_template. --- CRM/Contribute/BAO/Contribution.php | 20 +++----- tests/phpunit/api/v3/ContributionTest.php | 62 +++++++++++++++++++---- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 612d7f6d8fb4..a7a2537acb6f 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2426,7 +2426,7 @@ public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) { * messages * @throws Exception */ - public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $returnMessageText = TRUE) { + public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText = TRUE) { $this->loadRelatedObjects($input, $ids); if (empty($this->_component)) { @@ -2439,11 +2439,10 @@ public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $r $values['receipt_date'] = $input['receipt_date']; } - $template = CRM_Core_Smarty::singleton(); - $this->_assignMessageVariablesToTemplate($values, $input, $template, $recur, $returnMessageText); + $template = $this->_assignMessageVariablesToTemplate($values, $input, $returnMessageText); //what does recur 'mean here - to do with payment processor return functionality but // what is the importance - if ($recur && !empty($this->_relatedObjects['paymentProcessor'])) { + if (!empty($this->contribution_recur_id) && !empty($this->_relatedObjects['paymentProcessor'])) { $paymentObject = Civi\Payment\System::singleton()->getByProcessor($this->_relatedObjects['paymentProcessor']); $entityID = $entity = NULL; @@ -2552,7 +2551,7 @@ public function composeMessageArray(&$input, &$ids, &$values, $recur = FALSE, $r $values['is_pay_later'] = 1; } - if ($recur && $paymentObject) { + if (!empty($this->contribution_recur_id) && $paymentObject) { $url = $paymentObject->subscriptionURL($membership->id, 'membership', 'cancel'); $template->assign('cancelSubscriptionUrl', $url); $url = $paymentObject->subscriptionURL($membership->id, 'membership', 'billing'); @@ -2788,13 +2787,12 @@ public function _gatherMessageValues($input, &$values, $ids = array()) { * * @param $values * @param $input - * @param CRM_Core_SMARTY $template - * @param bool $recur * @param bool $returnMessageText * * @return mixed */ - public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = TRUE) { + public function _assignMessageVariablesToTemplate(&$values, $input, $returnMessageText = TRUE) { + $template = CRM_Core_Smarty::singleton(); $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); @@ -2889,7 +2887,7 @@ public function _assignMessageVariablesToTemplate(&$values, $input, &$template, ) ); $template->assign('is_monetary', 1); - $template->assign('is_recur', (bool) $recur); + $template->assign('is_recur', !empty($this->contribution_recur_id)); $template->assign('currency', $this->currency); $template->assign('address', CRM_Utils_Address::format($input)); if (!empty($values['customGroup'])) { @@ -4699,8 +4697,6 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re * @param int $contributionID * @param array $values * Values related to objects that have already been loaded. - * @param bool $recur - * Is it part of a recurring contribution. * @param bool $returnMessageText * Should text be returned instead of sent. This. * is because the function is also used to generate pdfs @@ -4723,7 +4719,7 @@ public static function sendMail(&$input, &$ids, $contributionID, &$values, $recu if (!$returnMessageText) { list($values['receipt_from_name'], $values['receipt_from_email']) = self::generateFromEmailAndName($input, $contribution); } - $return = $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText); + $return = $contribution->composeMessageArray($input, $ids, $values, $returnMessageText); // Contribution ID should really always be set. But ? if (!$returnMessageText && (!isset($input['receipt_update']) || $input['receipt_update']) && empty($contribution->receipt_date)) { civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id)); diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 79b1926835ac..e01cb93a9d4e 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2428,16 +2428,8 @@ public function testCompleteTransactionWithReceiptDateSet() { * CRM-1960 - Test to ensure that completetransaction respects the is_email_receipt setting */ public function testCompleteTransactionWithEmailReceiptInput() { - // Create a Contribution Page with is_email_receipt = TRUE - $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array( - 'receipt_from_name' => 'Mickey Mouse', - 'receipt_from_email' => 'mickey@mouse.com', - 'title' => "Test Contribution Page", - 'financial_type_id' => 1, - 'currency' => 'CAD', - 'is_monetary' => TRUE, - 'is_email_receipt' => TRUE, - )); + $contributionPage = $this->createReceiptableContributionPage(); + $this->_params['contribution_page_id'] = $contributionPage['id']; $params = array_merge($this->_params, array('contribution_status_id' => 2)); $contribution = $this->callAPISuccess('contribution', 'create', $params); @@ -2453,6 +2445,35 @@ public function testCompleteTransactionWithEmailReceiptInput() { $this->assertEquals('', $receipt_date); } + /** + * Test that $is_recur is assigned to the receipt. + */ + public function testCompleteTransactionForRecurring() { + + $this->swapMessageTemplateForTestTemplate(); + $recurring = $this->setUpRecurringContribution(); + $contributionPage = $this->createReceiptableContributionPage(array('is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1)); + + $this->_params['contribution_page_id'] = $contributionPage['id']; + $this->_params['contribution_recur_id'] = $recurring['id']; + + $contribution = $this->setUpForCompleteTransaction(); + + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $contribution['id'], + 'trxn_date' => date('2011-04-09'), + 'trxn_id' => 'kazam', + 'is_email_receipt' => 1, + )); + + $this->mut->checkMailLog(array( + 'is_recur:::1', + 'cancelSubscriptionUrl:::http://dummy.com', + )); + $this->mut->stop(); + $this->revertTemplateToReservedTemplate(); + } + /** * Complete the transaction using the template with all the possible. */ @@ -3494,4 +3515,25 @@ public function testSendMailWithRepeatTransactionAPIFalltoSystemFromNoDefaultFro $mut->stop(); } + /** + * Create a Contribution Page with is_email_receipt = TRUE. + * + * @param array $params + * Params to overwrite with. + * + * @return array|int + */ + protected function createReceiptableContributionPage($params = array()) { + $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array_merge(array( + 'receipt_from_name' => 'Mickey Mouse', + 'receipt_from_email' => 'mickey@mouse.com', + 'title' => "Test Contribution Page", + 'financial_type_id' => 1, + 'currency' => 'CAD', + 'is_monetary' => TRUE, + 'is_email_receipt' => TRUE, + ), $params)); + return $contributionPage; + } + } From 6626a6934b57f2cab5b9813efb5599f700dda18c Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 13 Mar 2017 11:48:29 +1300 Subject: [PATCH 3/3] CRM-20247 further removal of ignored is_recur parameter. This variable was part of a legacy flow via the BaseIPN. Removing the variable is a good tidy up step --- CRM/Contribute/BAO/Contribution.php | 4 +--- CRM/Contribute/Form/Task/PDF.php | 2 +- CRM/Core/Payment/BaseIPN.php | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index a7a2537acb6f..2d2434d27311 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2416,7 +2416,6 @@ public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) { * @param array $values * Any values that may have already been compiled by calling process. * This is augmented by values 'gathered' by gatherMessageValues - * @param bool $recur * @param bool $returnMessageText * Distinguishes between whether to send message or return. * message text. We are working towards this function ALWAYS returning message text & calling @@ -4705,9 +4704,8 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public static function sendMail(&$input, &$ids, $contributionID, &$values, $recur = FALSE, + public static function sendMail(&$input, &$ids, $contributionID, &$values, $returnMessageText = FALSE) { - $input['is_recur'] = $recur; $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $contributionID; diff --git a/CRM/Contribute/Form/Task/PDF.php b/CRM/Contribute/Form/Task/PDF.php index 508460c8b2e1..2455d38fdecd 100644 --- a/CRM/Contribute/Form/Task/PDF.php +++ b/CRM/Contribute/Form/Task/PDF.php @@ -206,7 +206,7 @@ public function postProcess() { $input['receipt_from_name'] = str_replace('"', '', $fromDetails[0]); } - $mail = CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, FALSE, + $mail = CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, $elements['createPdf']); if ($mail['html']) { diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 4a3d25f677da..d1bbb00cba24 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -471,10 +471,10 @@ public function getBillingID(&$ids) { } /** - * Send receipt from contribution. - * * @deprecated * + * @todo confirm this function is not being used by any payment processor outside core & remove. + * * Note that the compose message part has been moved to contribution * In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it * @@ -494,7 +494,7 @@ public function getBillingID(&$ids) { * @return array */ public function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE) { - return CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, $recur, + return CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values, $returnMessageText); }