From f4aff12e7c93c7a781629c886c4e250c5d4ac4f6 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Mon, 30 Apr 2018 11:10:03 +0530 Subject: [PATCH] Add unit test --- CRM/Core/Payment/AuthorizeNetIPN.php | 4 ++++ .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 6c46bd721f..2696e2a1ab 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -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 diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index cb73bbb3f4..09385e4db9 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -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 */ -- 2.25.1