Add unit test
authorJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 30 Apr 2018 05:40:03 +0000 (11:10 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 30 Apr 2018 09:05:59 +0000 (14:35 +0530)
CRM/Core/Payment/AuthorizeNetIPN.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php

index 6c46bd721fd101d0c5901759fefa9bdec7dbf25c..2696e2a1abb9f07e24f64c22ddddfd937b2c0224 100644 (file)
@@ -77,6 +77,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
         // processor id & the handleNotification function (which should call the completetransaction api & by-pass this
         // entirely). The only thing the IPN class should really do is extract data from the request, validate it
         // & call completetransaction or call fail? (which may not exist yet).
+        Civi::log()->warning('Unreliable method used for AuthNet IPN - this will cause problems if you have more than one instance');
         $paymentProcessorTypeID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
           'AuthNet', 'id', 'name'
         );
@@ -91,6 +92,9 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
       if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
         return FALSE;
       }
+      if (!empty($ids['paymentProcessor']) && $objects['contributionRecur']->payment_processor_id != $ids['paymentProcessor']) {
+        Civi::log()->warning('Payment Processor does not match the recurring processor id.', array('civi.tag' => 'deprecated'));
+      }
 
       if ($component == 'contribute' && $ids['contributionRecur']) {
         // check if first contribution is completed, else complete first contribution
index cb73bbb3f4c7e1c095427b2c50040cba85c79ef9..09385e4db92150cac8bf013980c6ba48feba7f76 100644 (file)
@@ -139,6 +139,26 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
     $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][1]['receive_date'])));
   }
 
+  /**
+   * Test payment processor is correctly assigned for the IPN payment.
+   */
+  public function testIPNPaymentRecurSuccessMultiAuthNetProcessor() {
+    //Create and set up recur payment using second instance of AuthNet Processor.
+    $this->_paymentProcessorID2 = $this->paymentProcessorAuthorizeNetCreate(array('name' => 'Authorize2', 'is_test' => 0));
+    $this->setupRecurringPaymentProcessorTransaction(array('payment_processor_id' => $this->_paymentProcessorID2));
+
+    //Call IPN with processor id.
+    $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('processor_id' => $this->_paymentProcessorID2)));
+    $IPN->main();
+    $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+    $this->assertEquals(1, $contribution['contribution_status_id']);
+    $this->assertEquals('6511143069', $contribution['trxn_id']);
+    // source gets set by processor
+    $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
+    $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+    $this->assertEquals(5, $contributionRecur['contribution_status_id']);
+  }
+
   /**
    * Test IPN response updates contribution_recur & contribution for first & second contribution
    */