From b813df8f661ddd5a1c09c3a4bbef457392a88467 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 12 Dec 2019 00:00:16 +1300 Subject: [PATCH] Paypal class cleanup - remove handling for returned error - this is never returned now - remove url parameter on invokeApi - this is never passed to it - throw an exception rather than use a fatal if curl not installed --- CRM/Core/Payment/PayPalImpl.php | 48 +++++++-------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 6310c5003e..2b971e5156 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -256,10 +256,6 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->invokeAPI($args); - if (is_a($result, 'CRM_Core_Error')) { - throw new PaymentProcessorException($result->message); - } - /* Success */ return $result['token']; @@ -302,10 +298,6 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->invokeAPI($args); - if (is_a($result, 'CRM_Core_Error')) { - throw new PaymentProcessorException(CRM_Core_Error::getMessages($result)); - } - /* Success */ $fieldMap = [ 'token' => 'token', @@ -358,10 +350,6 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->invokeAPI($args); - if (is_a($result, 'CRM_Core_Error')) { - throw new PaymentProcessorException(CRM_Core_Error::getMessages($result)); - } - /* Success */ $params['trxn_id'] = $result['transactionid']; $params['gross_amount'] = $result['amt']; @@ -425,10 +413,6 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->invokeAPI($args); - if (is_a($result, 'CRM_Core_Error')) { - return $result; - } - /* Success - result looks like" * array ( * 'profileid' => 'I-CP1U0PLG91R2', @@ -562,11 +546,6 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->invokeAPI($args); - // WAG - if (is_a($result, 'CRM_Core_Error')) { - return $result; - } - $params['recurr_profile_id'] = NULL; if (CRM_Utils_Array::value('is_recur', $params) == 1) { @@ -711,9 +690,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $args['NOTE'] = CRM_Utils_Array::value('reason', $params); $result = $this->invokeAPI($args); - if (is_a($result, 'CRM_Core_Error')) { - throw new PaymentProcessorException(CRM_Core_Error::getMessages($result, "\n")); - } + $message = "{$result['ack']}: profileid={$result['profileid']}"; return TRUE; } @@ -793,9 +770,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $args['ZIP'] = $params['country']; $result = $this->invokeAPI($args); - if (is_a($result, 'CRM_Core_Error')) { - return $result; - } + $message = "{$result['ack']}: profileid={$result['profileid']}"; return TRUE; } @@ -822,9 +797,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->invokeAPI($args); CRM_Core_Error::debug_var('$result', $result); - if (is_a($result, 'CRM_Core_Error')) { - throw new PaymentProcessorException(CRM_Core_Error::getMessages($result, "\n")); - } + $message = "{$result['ack']}: profileid={$result['profileid']}"; return TRUE; } @@ -1013,21 +986,18 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * returns an associative array containing the response from the server. * * @param array $args - * @param null $url * * @return array|object * @throws \Civi\Payment\Exception\PaymentProcessorException */ - public function invokeAPI($args, $url = NULL) { - - if ($url === NULL) { - if (empty($this->_paymentProcessor['url_api'])) { - throw new PaymentProcessorException(ts('Please set the API URL. Please refer to the documentation for more details')); - } + public function invokeAPI($args) { - $url = $this->_paymentProcessor['url_api'] . 'nvp'; + if (empty($this->_paymentProcessor['url_api'])) { + throw new PaymentProcessorException(ts('Please set the API URL. Please refer to the documentation for more details')); } + $url = $this->_paymentProcessor['url_api'] . 'nvp'; + $p = []; foreach ($args as $n => $v) { $p[] = "$n=" . urlencode($v); @@ -1037,7 +1007,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $nvpreq = implode('&', $p); if (!function_exists('curl_init')) { - CRM_Core_Error::fatal("curl functions NOT available."); + throw new PaymentProcessorException('curl functions NOT available.'); } //setting the curl parameters. -- 2.25.1