From e491d0c9c15b484355b7e2ac5ded7c32419a7dce Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sat, 28 Apr 2018 16:15:45 +0100 Subject: [PATCH] Remove usage of deprecated function from paypal --- CRM/Core/Payment.php | 11 +++++++++ CRM/Core/Payment/PayPalImpl.php | 42 ++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 202e3fe729..8626cd790d 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -103,6 +103,17 @@ abstract class CRM_Core_Payment { */ protected $cancelUrl; + /** + * Processor type label. + * + * (Deprecated parameter but used in some messages). + * + * @deprecated + * + * @var string + */ + public $_processorName; + /** * The profile configured to show on the billing form. * diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 99c2565465..3fa0066892 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -110,7 +110,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ protected function supportsBackOffice() { - if ($this->_processorName == ts('PayPal Pro')) { + if ($this->isPayPalType($this::PAYPAL_PRO)) { return TRUE; } return FALSE; @@ -129,7 +129,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ protected function supportsPreApproval() { - if ($this->_processorName == ts('PayPal Express') || $this->_processorName == ts('PayPal Pro')) { + if ($this->isPayPalType($this::PAYPAL_EXPRESS) || $this->isPayPalType($this::PAYPAL_PRO)) { return TRUE; } return FALSE; @@ -147,13 +147,13 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { public function buildForm(&$form) { if ($this->supportsPreApproval()) { $this->addPaypalExpressCode($form); - if ($this->_processorName == ts('PayPal Express')) { + if ($this->isPayPalType($this::PAYPAL_EXPRESS)) { CRM_Core_Region::instance('billing-block-post')->add(array( 'template' => 'CRM/Financial/Form/PaypalExpress.tpl', 'name' => 'paypal_express', )); } - if ($this->_processorName == ts('PayPal Pro')) { + if ($this->isPayPalType($this::PAYPAL_PRO)) { CRM_Core_Region::instance('billing-block-pre')->add(array( 'template' => 'CRM/Financial/Form/PaypalPro.tpl', )); @@ -226,7 +226,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function validatePaymentInstrument($values, &$errors) { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal' && !$this->isPaypalExpress($values)) { + if ($this->isPayPalType($this::PAYPAL_PRO) && !$this->isPaypalExpress($values)) { CRM_Core_Payment_Form::validateCreditCard($values, $errors, $this->_paymentProcessor['id']); CRM_Core_Form::validateMandatoryFields($this->getMandatoryFields(), $values, $errors); } @@ -505,9 +505,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function doPayment(&$params, $component = 'contribute') { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express' - || ($this->_paymentProcessor['payment_processor_type'] == 'PayPal' && !empty($params['token'])) - ) { + if ($this->isPayPalType($this::PAYPAL_EXPRESS) || ($this->isPayPalType($this::PAYPAL_PRO) && !empty($params['token']))) { $this->_component = $component; return $this->doExpressCheckout($params); @@ -648,9 +646,8 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { */ public function checkConfig() { $error = array(); - $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name'); - if ($this->_paymentProcessor['payment_processor_type_id'] != CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType)) { + if (!$this->isPayPalType($this::PAYPAL_STANDARD)) { if (empty($this->_paymentProcessor['signature'])) { $error[] = ts('Signature is not set in the Administer » System Settings » Payment Processors.'); } @@ -676,7 +673,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function cancelSubscriptionURL() { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Standard') { + if ($this->isPayPalType($this::PAYPAL_STANDARD)) { return "{$this->_paymentProcessor['url_site']}cgi-bin/webscr?cmd=_subscr-find&alias=" . urlencode($this->_paymentProcessor['user_name']); } else { @@ -691,9 +688,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * Method to check for. * * @return bool + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function isSupported($method) { - if ($this->_paymentProcessor['payment_processor_type'] != 'PayPal') { + if (!$this->isPayPalType($this::PAYPAL_PRO)) { // since subscription methods like cancelSubscription or updateBilling is not yet implemented / supported // by standard or express. return FALSE; @@ -706,9 +704,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * * @return bool * Should the form button by suppressed? + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function isSuppressSubmitButtons() { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express') { + if ($this->isPayPalType($this::PAYPAL_EXPRESS)) { return TRUE; } return FALSE; @@ -719,9 +718,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @param array $params * * @return array|bool|object + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function cancelSubscription(&$message = '', $params = array()) { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') { + if ($this->isPayPalType($this::PAYPAL_PRO)) { $args = array(); $this->initialize($args, 'ManageRecurringPaymentsProfileStatus'); @@ -741,6 +741,9 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { /** * Process incoming notification. + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ static public function handlePaymentNotification() { $params = array_merge($_GET, $_REQUEST); @@ -787,7 +790,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function updateSubscriptionBillingInfo(&$message = '', $params = array()) { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') { + if ($this->isPayPalType($this::PAYPAL_PRO)) { $config = CRM_Core_Config::singleton(); $args = array(); $this->initialize($args, 'UpdateRecurringPaymentsProfile'); @@ -823,9 +826,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @param array $params * * @return array|bool|object + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function changeSubscriptionAmount(&$message = '', $params = array()) { - if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') { + if ($this->isPayPalType($this::PAYPAL_PRO)) { $config = CRM_Core_Config::singleton(); $args = array(); $this->initialize($args, 'UpdateRecurringPaymentsProfile'); @@ -1139,10 +1143,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * Get array of fields that should be displayed on the payment form. * * @return array - * @throws CiviCRM_API3_Exception + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function getPaymentFormFields() { - if ($this->_processorName == ts('PayPal Pro')) { + if ($this->isPayPalType($this::PAYPAL_PRO)) { return $this->getCreditCardFormFields(); } else { @@ -1177,7 +1181,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ protected function isPaypalExpress($params) { - if ($this->_processorName == ts('PayPal Express')) { + if ($this->isPayPalType($this::PAYPAL_EXPRESS)) { return TRUE; } -- 2.25.1