From 248141b96531f10dc913402276fef75f3b56dcdc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 17 Jul 2015 10:07:59 +1200 Subject: [PATCH] CRM-16808 follow up - finally remove all references to calling doTransferPayment & doDirectPayment & only call doPayment --- CRM/Contribute/Form/AdditionalPayment.php | 25 +++++++------- CRM/Contribute/Form/Contribution/Confirm.php | 13 ++----- CRM/Core/Payment.php | 2 +- CRM/Core/Payment/Elavon.php | 7 ---- CRM/Core/Payment/FirstData.php | 7 ---- CRM/Core/Payment/Realex.php | 9 ----- CRM/Core/Payment/eWAY.php | 9 ----- CRM/Event/Cart/Form/Checkout/Payment.php | 11 +++--- CRM/Event/Form/Registration/Confirm.php | 28 +++++---------- .../main.php | 34 ------------------- .../CRM/Core/Payment/AuthorizeNetTest.php | 2 +- 11 files changed, 31 insertions(+), 116 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index eba618cbf5..05be49a28b 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -564,19 +564,20 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $result = NULL; if ($paymentParams['amount'] > 0.0) { - // force a reget of the payment processor in case the form changed it, CRM-7179 - $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); - $result = $payment->doDirectPayment($paymentParams); - } - - if (is_a($result, 'CRM_Core_Error')) { - //set the contribution mode. - $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}"; - if ($this->_mode) { - $urlParams .= "&mode={$this->_mode}"; + try { + // force a reget of the payment processor in case the form changed it, CRM-7179 + $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); + $result = $payment->doPayment($paymentParams); + } + catch (\Civi\Payment\Exception\PaymentProcessorException $e) { + //set the contribution mode. + $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}"; + if ($this->_mode) { + $urlParams .= "&mode={$this->_mode}"; + } + CRM_Core_Error::displaySessionError($result); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/add', $urlParams)); } - CRM_Core_Error::displaySessionError($result); - CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/add', $urlParams)); } if ($result) { diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 85e419bd11..61ccdcf957 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -1766,7 +1766,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $form->postProcessHook(); // this does not return $payment = Civi\Payment\System::singleton()->getByProcessor($form->_paymentProcessor); - $payment->doTransferCheckout($form->_params, 'contribute'); + $payment->doPayment($form->_params, 'contribute'); } } @@ -1853,16 +1853,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr else { $payment = $form->_paymentProcessor['object']; } - - if ($form->_contributeMode == 'express') { - $result = $payment->doExpressCheckout($tempParams); - if (is_a($result, 'CRM_Core_Error')) { - throw new CRM_Core_Exception(CRM_Core_Error::getMessages($result)); - } - } - else { - $result = $payment->doPayment($tempParams, 'contribute'); - } + $result = $payment->doPayment($tempParams, 'contribute'); } //assign receive date when separate membership payment diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 5d60d321ee..860eaa3f67 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -633,7 +633,7 @@ abstract class CRM_Core_Payment { * the result in an nice formatted array (or an error object) * @abstract */ - abstract protected function doDirectPayment(&$params); + protected function doDirectPayment(&$params) {} /** * Process payment - this function wraps around both doTransferPayment and doDirectPayment. diff --git a/CRM/Core/Payment/Elavon.php b/CRM/Core/Payment/Elavon.php index bcbe845b7d..c106553b31 100644 --- a/CRM/Core/Payment/Elavon.php +++ b/CRM/Core/Payment/Elavon.php @@ -276,13 +276,6 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment { return $e; } - /** - * NOTE: 'doTransferCheckout' not implemented - */ - public function doTransferCheckout(&$params, $component) { - CRM_Core_Error::fatal(ts('This function is not implemented')); - } - /** * This public function checks to see if we have the right processor config values set. * diff --git a/CRM/Core/Payment/FirstData.php b/CRM/Core/Payment/FirstData.php index 810e7b2d89..3e66de93f6 100644 --- a/CRM/Core/Payment/FirstData.php +++ b/CRM/Core/Payment/FirstData.php @@ -315,13 +315,6 @@ class CRM_Core_Payment_FirstData extends CRM_Core_Payment { return $e; } - /** - * NOTE: 'doTransferCheckout' not implemented - */ - public function doTransferCheckout(&$params, $component) { - CRM_Core_Error::fatal(ts('This function is not implemented')); - } - /** * This public function checks to see if we have the right processor config values set. * diff --git a/CRM/Core/Payment/Realex.php b/CRM/Core/Payment/Realex.php index a31171ecbf..4fac079377 100644 --- a/CRM/Core/Payment/Realex.php +++ b/CRM/Core/Payment/Realex.php @@ -76,15 +76,6 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment { $this->_setParam('sequence', rand(1, 1000)); } - /** - * @param array $params - * - * @throws Exception - */ - public function doTransferCheckout(&$params) { - CRM_Core_Error::fatal(ts('This function is not implemented')); - } - /** * Submit a payment using Advanced Integration Method. * diff --git a/CRM/Core/Payment/eWAY.php b/CRM/Core/Payment/eWAY.php index 7360555dad..be16af3e2b 100644 --- a/CRM/Core/Payment/eWAY.php +++ b/CRM/Core/Payment/eWAY.php @@ -439,15 +439,6 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment { return $e; } - /** - * ************************************************ - * NOTE: 'doTransferCheckout' not implemented - * ************************************************ - */ - public function doTransferCheckout(&$params, $component) { - CRM_Core_Error::fatal(ts('This function is not implemented')); - } - /** * ***************************************************************************************** * This public function checks to see if we have the right processor config values set diff --git a/CRM/Event/Cart/Form/Checkout/Payment.php b/CRM/Event/Cart/Form/Checkout/Payment.php index bf454ecce9..292adda6f8 100644 --- a/CRM/Event/Cart/Form/Checkout/Payment.php +++ b/CRM/Event/Cart/Form/Checkout/Payment.php @@ -575,15 +575,14 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart { CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, TRUE); $params['month'] = $params['credit_card_exp_date']['M']; $params['year'] = $params['credit_card_exp_date']['Y']; - $result = &$payment->doDirectPayment($params); - if (is_a($result, 'CRM_Core_Error')) { + try { + $result = $payment->doPayment($params); + } + catch (\Civi\Payment\Exception\PaymentProcessorException $e) { CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/cart_checkout', "_qf_Payment_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE)); - return NULL; - } - elseif (!$result['trxn_id']) { - CRM_Core_Error::fatal(ts("Financial institution didn't return a transaction id.")); } + $trxnDetails = array( 'trxn_id' => $result['trxn_id'], 'trxn_date' => $result['now'], diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 9d378b464a..75ea1581d5 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -597,14 +597,6 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses); } } - elseif ($this->_contributeMode == 'express' && !empty($value['is_primary'])) { - if (is_object($payment)) { - $result = $payment->doExpressCheckout($value); - } - else { - CRM_Core_Error::fatal($paymentObjError); - } - } elseif (!empty($value['is_primary'])) { CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE); // payment email param can be empty for _bltID mapping @@ -614,22 +606,20 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { } if (is_object($payment)) { - $result = $payment->doDirectPayment($value); + try { + $result = $payment->doPayment($value); + $value = array_merge($value, $result); + } + catch (\Civi\Payment\Exception\PaymentProcessorException $e) { + CRM_Core_Error::displaySessionError($result); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); + } } else { CRM_Core_Error::fatal($paymentObjError); } } - if (is_a($result, 'CRM_Core_Error')) { - CRM_Core_Error::displaySessionError($result); - CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); - } - - if ($result) { - $value = array_merge($value, $result); - } - $value['receive_date'] = $now; if ($this->_allowConfirmation) { $value['participant_register_date'] = $this->_values['participant']['register_date']; @@ -865,7 +855,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { // call postprocess hook before leaving $this->postProcessHook(); // this does not return - $payment->doTransferCheckout($primaryParticipant, 'event'); + $payment->doPayment($primaryParticipant, 'event'); } else { CRM_Core_Error::fatal($paymentObjError); diff --git a/tests/extensions/test.extension.manager.paymenttest/main.php b/tests/extensions/test.extension.manager.paymenttest/main.php index 28d034bb0a..98d817ac8e 100644 --- a/tests/extensions/test.extension.manager.paymenttest/main.php +++ b/tests/extensions/test.extension.manager.paymenttest/main.php @@ -4,29 +4,6 @@ * Class test_extension_manager_paymenttest */ class test_extension_manager_paymenttest extends CRM_Core_Payment { - static private $_singleton = NULL; - - /** - * Singleton function used to manage this object. - * - * @param string $mode - * The mode of operation: live or test. - * @param array $paymentProcessor - * The details of the payment processor being invoked. - * @param CRM_Core_Form $paymentForm - * Reference to the form object if available. - * @param bool $force - * Should we force a reload of this payment object. - * - * @return object - */ - public static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) { - $processorName = $paymentProcessor['name']; - if (self::$_singleton[$processorName] === NULL) { - self::$_singleton[$processorName] = new test_extension_manager_paymenttest(); - } - return self::$_singleton[$processorName]; - } static $counts = array(); @@ -46,17 +23,6 @@ class test_extension_manager_paymenttest extends CRM_Core_Payment { self::$counts['enable'] = 1 + (int) self::$counts['enable']; } - /** - * This function collects all the information from a web/api form and invokes - * the relevant payment processor specific functions to perform the transaction - * - * @param array $params - * Assoc array of input parameters for this transaction. - * - */ - public function doDirectPayment(&$params) { - } - public function checkConfig() { } diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php index 8d892634e8..78bed99e81 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php @@ -308,7 +308,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase { // turn verifySSL off CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); - $result = $this->processor->doDirectPayment($params); + $result = $this->processor->doPayment($params); // turn verifySSL on CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL'); -- 2.25.1