WIP CRM-20840 - ensure no receipt for recur payment if contrib page says … (#10850)
authorjmcclelland <jamie@progressivetech.org>
Wed, 23 Aug 2017 02:17:08 +0000 (22:17 -0400)
committerEileen McNaughton <eileen@mcnaughty.com>
Wed, 23 Aug 2017 02:17:08 +0000 (14:17 +1200)
* 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
tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php

index 23b78ced6c8dfd4e137588a8b9ead4a8030ac536..247f64b61b744b1ee9782609ff22148c0235f787 100644 (file)
@@ -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));
 
   }
 
index d322397bafb7d65de973dc2afc49e81f0747f7b7..da6311676d0d1c8ca3706addd5b10e261a093660 100644 (file)
@@ -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);
   }
 
 }