From 0495f30cfea9f3bc485ac891759b9a29508f35a5 Mon Sep 17 00:00:00 2001 From: jmcclelland Date: Tue, 22 Aug 2017 22:17:08 -0400 Subject: [PATCH] =?utf8?q?WIP=20CRM-20840=20-=20ensure=20no=20receipt=20fo?= =?utf8?q?r=20recur=20payment=20if=20contrib=20page=20says=20=E2=80=A6=20(?= =?utf8?q?#10850)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * CRM-20840 - Add unit test to ensure no receipt for recur payment if contrib page says no receipt (bug fixed elsewhere) * CRM-20840 - ensure unique address are sent to authorize.net * CRM-20840 - argument should be optional to avoid breakage elsewhere. --- CRM/Contribute/Form/Contribution.php | 2 +- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 84 ++++++++++++++++++- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 23b78ced6c..247f64b61b 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1423,7 +1423,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP CRM_Contribute_Form_AdditionalInfo::buildPremium($this); $this->_fields = array(); - $this->submit(array_merge($defaults, $params), $action, CRM_Utils_Array::value('pledge_payment_id', $params)); + return $this->submit(array_merge($defaults, $params), $action, CRM_Utils_Array::value('pledge_payment_id', $params)); } diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index d322397baf..da6311676d 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -33,6 +33,86 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { public function tearDown() { $this->quickCleanUpFinancialEntities(); } + /** + * Ensure recurring contributions from Contribution Pages + * with receipt turned off don't send a receipt. + */ + public function testIPNPaymentRecurNoReceipt() { + $mut = new CiviMailUtils($this, TRUE); + // Turn off receipts in contribution page. + $api_params = array( + 'id' => $this->_contributionPageID, + 'is_email_receipt' => FALSE, + ); + $this->callAPISuccess('contributionPage', 'update', $api_params); + + // Create initial recurring payment and initial contribution. + // Note - we can't use setupRecurringPaymentProcessorTransaction(), which + // would be convenient because it does not fully mimic the real user + // experience. Using setupRecurringPaymentProcessorTransaction() doesn't + // specify is_email_receipt so it is always set to 1. We need to more + // closely mimic what happens with a live transaction to test that + // is_email_receipt is not set to 1 if the originating contribution page + // has is_email_receipt set to 0. + $form = new CRM_Contribute_Form_Contribution(); + $form->_mode = 'Live'; + $contribution = $form->testSubmit(array( + 'total_amount' => 200, + 'financial_type_id' => 1, + 'receive_date' => date('m/d/Y'), + 'receive_date_time' => date('H:i:s'), + 'contact_id' => $this->_contactID, + 'contribution_status_id' => 1, + 'credit_card_number' => 4444333322221111, + 'cvv2' => 123, + 'credit_card_exp_date' => array( + 'M' => 9, + 'Y' => 2025, + ), + 'credit_card_type' => 'Visa', + 'billing_first_name' => 'Junko', + 'billing_middle_name' => '', + 'billing_last_name' => 'Adams', + 'billing_street_address-5' => time() . ' Lincoln St S', + 'billing_city-5' => 'Maryknoll', + 'billing_state_province_id-5' => 1031, + 'billing_postal_code-5' => 10545, + 'billing_country_id-5' => 1228, + 'frequency_interval' => 1, + 'frequency_unit' => 'month', + 'installments' => '', + 'hidden_AdditionalDetail' => 1, + 'hidden_Premium' => 1, + 'payment_processor_id' => $this->_paymentProcessorID, + 'currency' => 'USD', + 'source' => 'bob sled race', + 'contribution_page_id' => $this->_contributionPageID, + 'is_recur' => TRUE, + ), CRM_Core_Action::ADD); + + $this->_contributionID = $contribution->id; + $this->_contributionRecurID = $contribution->contribution_recur_id; + $recur_params = array( + 'id' => $this->_contributionRecurID, + 'return' => 'processor_id', + ); + $processor_id = civicrm_api3('ContributionRecur', 'getvalue', $recur_params); + // Process the initial one. + $IPN = new CRM_Core_Payment_AuthorizeNetIPN( + $this->getRecurTransaction(array('x_subscription_id' => $processor_id)) + ); + $IPN->main(); + + // Now send a second one (authorize seems to treat first and second contributions + // differently. + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction( + array('x_subscription_id' => $processor_id) + )); + $IPN->main(); + + // There should not be any email. + $mut->assertMailLogEmpty(); + } /** * Test IPN response updates contribution_recur & contribution for first & second contribution @@ -280,11 +360,11 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { /** * @return array */ - public function getRecurSubsequentTransaction() { + public function getRecurSubsequentTransaction($params = array()) { return array_merge($this->getRecurTransaction(), array( 'x_trans_id' => 'second_one', 'x_MD5_Hash' => 'EA7A3CD65A85757827F51212CA1486A8', - )); + ), $params); } } -- 2.25.1