From d0522e761eba7982b95321d5e45cbfcd481851b7 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 22 Oct 2020 08:43:50 +1300 Subject: [PATCH] Minor extraction --- CRM/Core/Payment/AuthorizeNetIPN.php | 53 ++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index b02eefb8fc..7c85c3ed7a 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -52,28 +52,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { // load post ids in $ids $this->getIDs($ids, $input); - - // Attempt to get payment processor ID from URL - if (!empty($this->_inputParameters['processor_id'])) { - $paymentProcessorID = $this->_inputParameters['processor_id']; - } - else { - // This is an unreliable method as there could be more than one instance. - // Recommended approach is to use the civicrm/payment/ipn/xx url where xx is the payment - // 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 to get payment_processor_id 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' - ); - $paymentProcessorID = (int) civicrm_api3('PaymentProcessor', 'getvalue', [ - 'is_test' => 0, - 'options' => ['limit' => 1], - 'payment_processor_type_id' => $paymentProcessorTypeID, - 'return' => 'id', - ]); - } + $paymentProcessorID = $this->getPaymentProcessorID(); // Check if the contribution exists // make sure contribution exists and is valid @@ -371,4 +350,34 @@ INNER JOIN civicrm_contribution co ON co.contribution_recur_id = cr.id return $contRecur; } + /** + * Get the payment processor id. + * + * @return int + * + * @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'])) { + return (int) $this->_inputParameters['processor_id']; + } + // This is an unreliable method as there could be more than one instance. + // Recommended approach is to use the civicrm/payment/ipn/xx url where xx is the payment + // 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 to get payment_processor_id 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' + ); + return (int) civicrm_api3('PaymentProcessor', 'getvalue', [ + 'is_test' => 0, + 'options' => ['limit' => 1], + 'payment_processor_type_id' => $paymentProcessorTypeID, + 'return' => 'id', + ]); + } + } -- 2.25.1