diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 47d130f4461f..1d9f0de5fd3b 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 @@ public function main() { $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 @@ protected function getContributionRecurObject(string $processorID, int $contactI * * @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 994ab9a53dc3..dbf43f5c975a 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -153,9 +153,6 @@ public function loadObjects($input, &$ids, &$objects, $required, $paymentProcess $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 bf3981844710..14279e30a768 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -360,9 +360,6 @@ public function main() { 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 a2a59ffeb595..a6cafa18b68f 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -315,32 +315,8 @@ public function testLoadPledgeObjects() { 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 @@ public function testSendMailPledge() { */ 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 @@ public function testPaymentProcessorLoadsAsParam() { $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([