From e58c1c1a94833dc50c3744ff78629f969feba409 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Sun, 11 Oct 2015 20:41:58 +1300 Subject: [PATCH] CRM-17256 paypal : fix up method selection code --- CRM/Core/Payment/Form.php | 2 +- CRM/Core/Payment/PayPalImpl.php | 52 ++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 73a816cf97..cb882254ee 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -307,7 +307,7 @@ class CRM_Core_Payment_Form { $paymentProcessorObject = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor); return array_intersect_key( $paymentProcessorObject->getBillingAddressFieldsMetadata($billingLocationID), - array_flip (self::getBillingAddressFields($paymentProcessor, $billingLocationID)) + array_flip(self::getBillingAddressFields($paymentProcessor, $billingLocationID)) ); } diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 9ae063b39d..5bb6842051 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -47,7 +47,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * @param string $mode * The mode of operation: live or test. * - * @param $paymentProcessor + * @param CRM_Core_Payment $paymentProcessor * * @return \CRM_Core_Payment_PayPalImpl */ @@ -68,7 +68,11 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { } /** - * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login + * Are back office payments supported. + * + * E.g paypal standard won't permit you to enter a credit card associated + * with someone else's login. + * * @return bool */ protected function supportsBackOffice() { @@ -123,8 +127,12 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { } /** - * Billing mode button is basically synonymous with paypal express - this is probably a good example of 'odds & sods' code we - * need to find a way for the payment processor to assign. A tricky aspect is that the payment processor may need to set the order + * Billing mode button is basically synonymous with paypal express. + * + * This is probably a good example of 'odds & sods' code we + * need to find a way for the payment processor to assign. + * + * A tricky aspect is that the payment processor may need to set the order * * @param CRM_Core_Form $form */ @@ -173,7 +181,9 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { } /** - * Express checkout code. Check PayPal documentation for more information + * Express checkout code. + * + * Check PayPal documentation for more information * * @param array $params * Assoc array of input parameters for this transaction. @@ -232,7 +242,9 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { } /** - * Get details from paypal. Check PayPal documentation for more information + * Get details from paypal. + * + * Check PayPal documentation for more information * * @param string $token * The key associated with this transaction. @@ -273,14 +285,16 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { } /** - * Do the express checkout at paypal. Check PayPal documentation for more information + * Do the express checkout at paypal. * - * @param array $params + * Check PayPal documentation for more information * - * @internal param string $token the key associated with this transaction + * @param array $params * * @return array - * the result in an nice formatted array (or an error object) + * The result in an nice formatted array. + * + * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function doExpressCheckout(&$params) { $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'); @@ -330,8 +344,9 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { return $params; } - //LCD add new function for handling recurring payments for PayPal Express /** + * Create recurring payments. + * * @param array $params * * @return mixed @@ -389,8 +404,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { return $params; } - //LCD end + /** + * Initialise. + * * @param $args * @param $method */ @@ -429,13 +446,14 @@ 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' - && (!empty($params['credit_card_number']) && empty($params['token'])) + if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express' + || ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Pro' && !empty($params['token'])) ) { - return parent::doPayment($params, $component); + $this->_component = $component; + return $this->doExpressCheckout($params); + } - $this->_component = $component; - return $this->doExpressCheckout($params); + return parent::doPayment($params, $component); } /** -- 2.25.1