From 532279ddc23cd52eb007acde8fb87be9d03582ab Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Tue, 11 Jun 2019 18:43:48 +0100 Subject: [PATCH] Extract preProcess paypalexpress --- CRM/Event/Form/Registration/Confirm.php | 119 +++++++++++++----------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 1b35d29fe3..f9fdfa9ff3 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -84,61 +84,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { $this->assign('hookDiscount', $this->_params[0]['discount']); } - // The concept of contributeMode is deprecated. - if ($this->_contributeMode == 'express') { - $params = []; - // rfp == redirect from paypal - // rfp is probably not required - the getPreApprovalDetails should deal with any payment-processor specific 'stuff' - $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean', - CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET' - ); - - //we lost rfp in case of additional participant. So set it explicitly. - if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) { - if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) { - $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); - $params = array_merge($this->_params, $preApprovalParams); - } - CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, FALSE); - - // set a few other parameters that are not really specific to this method because we don't know what - // will break if we change this. - $params['amount'] = $this->_params[0]['amount']; - if (!empty($this->_params[0]['discount'])) { - $params['discount'] = $this->_params[0]['discount']; - $params['discountAmount'] = $this->_params[0]['discountAmount']; - $params['discountMessage'] = $this->_params[0]['discountMessage']; - } - - $params['amount_level'] = $this->_params[0]['amount_level']; - $params['currencyID'] = $this->_params[0]['currencyID']; - - // also merge all the other values from the profile fields - $values = $this->controller->exportValues('Register'); - $skipFields = [ - 'amount', - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "state_province_id-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "country_id-{$this->_bltID}", - ]; - - foreach ($values as $name => $value) { - // skip amount field - if (!in_array($name, $skipFields)) { - $params[$name] = $value; - } - if (substr($name, 0, 6) == 'price_') { - $params[$name] = $this->_params[0][$name]; - } - } - $this->set('getExpressCheckoutDetails', $params); - } - $this->_params[0] = array_merge($this->_params[0], $params); - $this->_params[0]['is_primary'] = 1; - } - else { + if (!$this->preProcessExpress()) { //process only primary participant params. $registerParams = $this->_params[0]; if (isset($registerParams["billing_state_province_id-{$this->_bltID}"]) @@ -188,6 +134,69 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { $this->set('params', $this->_params); } + /** + * Pre process function for Paypal Express confirm. + * @todo this is just a step in refactor as payment processor specific code does not belong in generic forms + * + * @return bool + * @throws \CRM_Core_Exception + */ + private function preProcessExpress() { + if ($this->_contributeMode !== 'express') { + return FALSE; + } + $params = []; + // rfp == redirect from paypal + // @fixme rfp is probably not required - the getPreApprovalDetails should deal with any payment-processor specific 'stuff' + $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); + + //we lost rfp in case of additional participant. So set it explicitly. + if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) { + if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) { + $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); + $params = array_merge($this->_params, $preApprovalParams); + } + CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, FALSE); + + // set a few other parameters that are not really specific to this method because we don't know what + // will break if we change this. + $params['amount'] = $this->_params[0]['amount']; + if (!empty($this->_params[0]['discount'])) { + $params['discount'] = $this->_params[0]['discount']; + $params['discountAmount'] = $this->_params[0]['discountAmount']; + $params['discountMessage'] = $this->_params[0]['discountMessage']; + } + + $params['amount_level'] = $this->_params[0]['amount_level']; + $params['currencyID'] = $this->_params[0]['currencyID']; + + // also merge all the other values from the profile fields + $values = $this->controller->exportValues('Register'); + $skipFields = [ + 'amount', + "street_address-{$this->_bltID}", + "city-{$this->_bltID}", + "state_province_id-{$this->_bltID}", + "postal_code-{$this->_bltID}", + "country_id-{$this->_bltID}", + ]; + + foreach ($values as $name => $value) { + // skip amount field + if (!in_array($name, $skipFields)) { + $params[$name] = $value; + } + if (substr($name, 0, 6) == 'price_') { + $params[$name] = $this->_params[0][$name]; + } + } + $this->set('getExpressCheckoutDetails', $params); + } + $this->_params[0] = array_merge($this->_params[0], $params); + $this->_params[0]['is_primary'] = 1; + return TRUE; + } + /** * Overwrite action, since we are only showing elements in frozen mode no help display needed. * -- 2.25.1