From 077017db90f4e950c4be53aab9f526b96ed4ec58 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 12 Jul 2015 23:08:57 +1200 Subject: [PATCH] CRM-16402 remove deprecated PaymentSingleton --- CRM/Contribute/Form/Contribution/Confirm.php | 6 ++-- CRM/Contribute/Page/UserDashboard.php | 2 -- CRM/Core/Payment.php | 31 -------------------- CRM/Core/Payment/AuthorizeNetIPN.php | 2 +- CRM/Event/Cart/Form/Checkout/Payment.php | 7 +---- CRM/Event/Form/Participant.php | 2 +- CRM/Event/Form/Registration/Confirm.php | 4 +-- CRM/Event/Form/Registration/Register.php | 2 +- CRM/Member/BAO/Membership.php | 2 +- 9 files changed, 10 insertions(+), 48 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index bcc80a2b3d..1e0d0e9adc 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -218,7 +218,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET' ); if ($rfp) { - $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); + $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); $expressParams = $payment->getPreApprovalDetails($this->get('pre_approval_parameters')); $this->_params['payer'] = CRM_Utils_Array::value('payer', $expressParams); @@ -1762,7 +1762,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr // call postProcess hook before leaving $form->postProcessHook(); // this does not return - $payment = CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); + $payment = Civi\Payment\System::singleton()->getByProcessor($form->_paymentProcessor); $payment->doTransferCheckout($form->_params, 'contribute'); } } @@ -1842,7 +1842,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $result = NULL; if ($form->_values['is_monetary'] && !$form->_params['is_pay_later'] && $minimumFee > 0.0) { - $payment = CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); + $payment = $form->_paymentProcessor['object']; if ($form->_contributeMode == 'express') { $result = $payment->doExpressCheckout($tempParams); diff --git a/CRM/Contribute/Page/UserDashboard.php b/CRM/Contribute/Page/UserDashboard.php index 3d001aa707..a6d95f38b3 100644 --- a/CRM/Contribute/Page/UserDashboard.php +++ b/CRM/Contribute/Page/UserDashboard.php @@ -82,8 +82,6 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo continue; } - // note that we are passing a CRM_Core_Page object ($this) as if it were a form here: - $paymentObject = CRM_Core_Payment::singleton($mode, $paymentProcessor, $this); require_once 'api/v3/utils.php'; //@todo calling api functions directly is not supported diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 4ae367fce3..b5731feccd 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -71,37 +71,6 @@ abstract class CRM_Core_Payment { protected $_paymentProcessor; - /** - * Singleton function used to manage this object. - * - * We will migrate to calling Civi\Payment\System::singleton()->getByProcessor($paymentProcessor) - * & Civi\Payment\System::singleton()->getById($paymentProcessor) directly as the main access methods & work - * to remove this function all together - * - * @param string $mode - * The mode of operation: live or test. - * @param array $paymentProcessor - * The details of the payment processor being invoked. - * @param object $paymentForm - * Deprecated - avoid referring to this if possible. If you have to use it document why as this is scary interaction. - * @param bool $force - * Should we force a reload of this payment object. - * - * @return CRM_Core_Payment - * @throws \CRM_Core_Exception - */ - public static function singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) { - // make sure paymentProcessor is not empty - // CRM-7424 - if (empty($paymentProcessor)) { - return CRM_Core_DAO::$_nullObject; - } - //we use two lines because we can't remove the '&singleton' without risking breakage - //of extension classes that extend this one - $object = Civi\Payment\System::singleton()->getByProcessor($paymentProcessor); - return $object; - } - /** * Opportunity for the payment processor to override the entire form build. * diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 85e3a60b82..c479e6d298 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -339,7 +339,7 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ids['paymentProcessor'], $input['is_test'] ? 'test' : 'live' ); - $paymentObject = CRM_Core_Payment::singleton($input['is_test'] ? 'test' : 'live', $paymentProcessor); + $paymentObject = $paymentProcessor['object']; if (!$paymentObject->checkMD5($input['MD5_Hash'], $input['trxn_id'], $input['amount'], TRUE)) { CRM_Core_Error::debug_log_message("MD5 Verification failed."); diff --git a/CRM/Event/Cart/Form/Checkout/Payment.php b/CRM/Event/Cart/Form/Checkout/Payment.php index 8bdd10cf1e..bf454ecce9 100644 --- a/CRM/Event/Cart/Form/Checkout/Payment.php +++ b/CRM/Event/Cart/Form/Checkout/Payment.php @@ -391,11 +391,6 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart { $errors = array(); if ($self->payment_required && empty($self->_submitValues['is_pay_later'])) { - $payment = CRM_Core_Payment::singleton($self->_mode, $self->_paymentProcessor, CRM_Core_DAO::$_nullObject); - $error = $payment->checkConfig($self->_mode); - if ($error) { - $errors['_qf_default'] = $error; - } CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors); // validate payment instrument values (e.g. credit card number) @@ -576,7 +571,7 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart { $params['ip_address'] = CRM_Utils_System::ipAddress(); $params['currencyID'] = $config->defaultCurrency; - $payment = &CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); + $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor); 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']; diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 1645a8ee52..a3ef71f36b 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1187,7 +1187,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $mapParams = array_merge(array('contact_id' => $contactID), $this->_params); CRM_Core_Payment_Form::mapParams($this->_bltID, $mapParams, $paymentParams, TRUE); - $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); + $payment = $this->_paymentProcessor['object']; // CRM-15622: fix for incorrect contribution.fee_amount $paymentParams['fee_amount'] = NULL; diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 11dcbcf4bb..9d378b464a 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -90,7 +90,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { //we lost rfp in case of additional participant. So set it explicitly. if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) { - $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); + $payment = $this->_paymentProcessor['object']; $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.'); if (is_object($payment)) { $expressParams = $payment->getExpressCheckoutDetails($this->get('token')); @@ -580,7 +580,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { // required only if paid event if ($this->_values['event']['is_monetary'] && !($this->_allowWaitlist || $this->_requireApproval)) { if (is_array($this->_paymentProcessor)) { - $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); + $payment = $this->_paymentProcessor['object']; } $result = NULL; diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 44254ac314..8100e4e7ee 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -1098,7 +1098,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $this->set('invoiceID', $invoiceID); if (is_array($this->_paymentProcessor)) { - $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); + $payment = $this->_paymentProcessor['object']; } // default mode is direct $this->set('contributeMode', 'direct'); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index c8020476f8..e31c841b99 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1298,7 +1298,7 @@ AND civicrm_membership.is_test = %2"; // call postProcess hook before leaving $form->postProcessHook(); // this does not return - $payment = CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); + $payment = $form->_paymentProcessor['object']; $payment->doTransferCheckout($form->_params, 'contribute'); } } -- 2.25.1