From c2d8f267993100ef9a4ba80ef85b391a725cbb7a Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 25 Nov 2020 11:42:51 +1300 Subject: [PATCH] Remove legacy check This check dates right back to when we started extracting IPN code from code blocks in the processor. I don't believe it's meaningful --- CRM/Core/Payment/AuthorizeNetIPN.php | 13 +++-- CRM/Core/Payment/BaseIPN.php | 3 -- CRM/Core/Payment/PayPalIPN.php | 3 -- .../phpunit/CRM/Core/Payment/BaseIPNTest.php | 47 +------------------ 4 files changed, 10 insertions(+), 56 deletions(-) diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 47d130f446..1d9f0de5fd 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\PaymentProcessor; + /** * * @package CRM @@ -85,9 +87,6 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { $ids['paymentProcessor'] = $paymentProcessorID; $contribution->loadRelatedObjects($input, $ids); - if (empty($contribution->_relatedObjects['paymentProcessor'])) { - throw new CRM_Core_Exception("Could not find payment processor for contribution record: " . $contribution->id); - } // check if first contribution is completed, else complete first contribution $first = TRUE; @@ -339,12 +338,18 @@ INNER JOIN civicrm_contribution co ON co.contribution_recur_id = cr.id * * @return int * + * @throws \API_Exception * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ protected function getPaymentProcessorID(): int { // Attempt to get payment processor ID from URL - if (!empty($this->_inputParameters['processor_id'])) { + if (!empty($this->_inputParameters['processor_id']) && + 'AuthNet' === PaymentProcessor::get(FALSE) + ->addSelect('payment_processor_type_id:name') + ->addWhere('id', '=', $this->_inputParameters['processor_id']) + ->execute()->first()['payment_processor_type_id:name'] + ) { return (int) $this->_inputParameters['processor_id']; } // This is an unreliable method as there could be more than one instance. diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 994ab9a53d..dbf43f5c97 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -153,9 +153,6 @@ class CRM_Core_Payment_BaseIPN { $contribution = &$objects['contribution']; $ids['paymentProcessor'] = $paymentProcessorID; $success = $contribution->loadRelatedObjects($input, $ids); - if ($required && empty($contribution->_relatedObjects['paymentProcessor'])) { - throw new CRM_Core_Exception("Could not find payment processor for contribution record: " . $contribution->id); - } $objects = array_merge($objects, $contribution->_relatedObjects); return $success; } diff --git a/CRM/Core/Payment/PayPalIPN.php b/CRM/Core/Payment/PayPalIPN.php index bf39818447..14279e30a7 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -360,9 +360,6 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { if (!$contribution->loadRelatedObjects($input, $ids)) { return; } - if (empty($contribution->_relatedObjects['paymentProcessor'])) { - throw new CRM_Core_Exception("Could not find payment processor for contribution record: " . $contribution->id); - } $input['payment_processor_id'] = $paymentProcessorID; diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php index a2a59ffeb5..a6cafa18b6 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -315,32 +315,8 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { public function testLoadPledgeObjectsInvalidPledgeID() { $this->_setUpPledgeObjects(); $this->ids['pledge_payment'][0] = 0; - try { - $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL); - } - catch (CRM_Core_Exception $e) { - $this->assertEquals('Could not find payment processor for contribution record: 1', $e->getMessage()); - } - $this->assertArrayNotHasKey('pledge_payment', $this->objects); - $this->ids['pledge_payment'][0] = NULL; - try { - $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL); - } - catch (CRM_Core_Exception $e) { - $this->assertEquals('Could not find payment processor for contribution record: 1', $e->getMessage()); - } - $this->assertArrayNotHasKey('pledge_payment', $this->objects); - - $this->ids['pledge_payment'][0] = ''; - - try { - $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL); - $this->assertArrayHasKey('error_message', $result); - } - catch (CRM_Core_Exception $e) { - $this->assertEquals('Could not find payment processor for contribution record: 1', $e->getMessage()); - } + $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL); $this->assertArrayNotHasKey('pledge_payment', $this->objects); $this->ids['pledge_payment'][0] = 999; @@ -368,12 +344,6 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function testRequiredWithoutProcessorID() { $this->_setUpPledgeObjects(); - try { - $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL); - } - catch (CRM_Core_Exception $e) { - $this->assertEquals('Could not find payment processor for contribution record: 1', $e->getMessage()); - } // error is only returned if $required set to True $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL); $this->assertEquals(TRUE, $result); @@ -390,21 +360,6 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL)); } - /** - * Test that an error is returned if required set & contribution page exists - */ - public function testRequiredWithContributionPageError() { - $this->_setUpContributionObjects(); - try { - $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL); - } - catch (CRM_Core_Exception $e) { - $this->assertEquals('Could not find payment processor for contribution record: 1', $e->getMessage()); - } - // error is only returned if $required set to True - $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL); - } - public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() { $this->_setUpParticipantObjects('Pending from incomplete transaction'); $additionalParticipantId = $this->participantCreate([ -- 2.25.1