From: Eileen McNaughton Date: Fri, 3 Nov 2023 02:23:03 +0000 (+1300) Subject: PHp8.x notice fix - remove use of legacy paymentObject X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6ce23a46eb0f39a0b3af4020a354e59ac01a2de9;p=civicrm-core.git PHp8.x notice fix - remove use of legacy paymentObject --- diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 6b9b5472ef..aa378a4ec4 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -70,13 +70,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { */ protected $_paymentProcessors = []; - /** - * Instance of the payment processor object. - * - * @var CRM_Core_Payment - */ - protected $_paymentObject; - /** * Entity that $this->_id relates to. * diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 8227fb63af..7edb7b92d6 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -19,6 +19,7 @@ use Civi\Payment\Exception\PaymentProcessorException; class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditPayment { use CRM_Contact_Form_ContactFormTrait; use CRM_Contribute_Form_ContributeFormTrait; + use CRM_Financial_Form_PaymentProcessorFormTrait; /** * The id of the contribution that we are processing. @@ -1154,8 +1155,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->_lineItem = $lineItem; } - $this->_paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']); - $this->_paymentProcessor = $this->_paymentObject->getPaymentProcessor(); + $paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']); + $this->_paymentProcessor = $paymentObject->getPaymentProcessor(); // Set source if not set if (empty($submittedValues['source'])) { @@ -2363,7 +2364,7 @@ WHERE contribution_id = {$id} $form->assign('is_recur_interval', $form->_values['is_recur_interval'] ?? NULL); $form->assign('is_recur_installments', $form->_values['is_recur_installments'] ?? NULL); - $paymentObject = $form->getVar('_paymentObject'); + $paymentObject = $this->getPaymentProcessorObject(); if ($paymentObject) { $form->assign('recurringHelpText', $paymentObject->getText('contributionPageRecurringHelp', [ 'is_recur_installments' => !empty($form->_values['is_recur_installments']), diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 5f7d9aa04a..d213af0d61 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -747,7 +747,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $form->assign('is_recur_interval', $this->getContributionPageValue('is_recur_interval')); $form->assign('is_recur_installments', $this->getContributionPageValue('is_recur_installments')); - $paymentObject = $form->getVar('_paymentObject'); + $paymentObject = $this->_paymentProcessor['object']; if ($paymentObject) { $form->assign('recurringHelpText', $paymentObject->getText('contributionPageRecurringHelp', [ 'is_recur_installments' => !empty($form->_values['is_recur_installments']), diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 46fb52bf9d..f1f4a242cd 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -23,6 +23,7 @@ use Civi\Api4\PriceSet; class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { use CRM_Financial_Form_FrontEndPaymentFormTrait; use CRM_Contribute_Form_ContributeFormTrait; + use CRM_Financial_Form_PaymentProcessorFormTrait; /** * The id of the contribution page that we are processing. @@ -60,8 +61,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { */ public $_paymentProcessor; - public $_paymentObject = NULL; - /** * Order object, used to calculate amounts, line items etc. * @@ -869,8 +868,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { // The concept of contributeMode is deprecated. // The payment processor object can provide info about the fields it shows. - if ($isMonetary && $this->_paymentProcessor['object'] instanceof \CRM_Core_Payment) { - $paymentProcessorObject = $this->_paymentProcessor['object']; + if ($isMonetary) { + $paymentProcessorObject = $this->getPaymentProcessorObject(); $this->assign('paymentAgreementTitle', $paymentProcessorObject->getText('agreementTitle', [])); $this->assign('paymentAgreementText', $paymentProcessorObject->getText('agreementText', [])); $paymentFields = $paymentProcessorObject->getPaymentFormFields(); @@ -1055,18 +1054,6 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } - /** - * Get the payment processor object for the submission, returning the manual one for offline payments. - * - * @return CRM_Core_Payment - */ - protected function getPaymentProcessorObject() { - if (!empty($this->_paymentProcessor)) { - return $this->_paymentProcessor['object']; - } - return new CRM_Core_Payment_Manual(); - } - /** * Get the amount for the main contribution. * diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 85e98bc758..3b46f59f0d 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -945,8 +945,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page { ) { $this->_paymentProcessor = $paymentProcessorDetail; $this->assign('paymentProcessor', $this->_paymentProcessor); - // Setting this is a bit of a legacy overhang. - $this->_paymentObject = $paymentProcessorDetail['object']; } } // It's not clear why we set this on the form. diff --git a/CRM/Core/Payment/ProcessorForm.php b/CRM/Core/Payment/ProcessorForm.php index 381090f7aa..35715f69db 100644 --- a/CRM/Core/Payment/ProcessorForm.php +++ b/CRM/Core/Payment/ProcessorForm.php @@ -42,14 +42,14 @@ class CRM_Core_Payment_ProcessorForm { return; } $form->set('paymentProcessor', $form->_paymentProcessor); - $form->_paymentObject = System::singleton()->getByProcessor($form->_paymentProcessor); + $paymentObject = System::singleton()->getByProcessor($form->_paymentProcessor); if ($form->paymentInstrumentID) { - $form->_paymentObject->setPaymentInstrumentID($form->paymentInstrumentID); + $paymentObject->setPaymentInstrumentID($form->paymentInstrumentID); } - $form->_paymentObject->setBackOffice($form->isBackOffice); + $paymentObject->setBackOffice($form->isBackOffice); $form->assign('isBackOffice', $form->isBackOffice); - $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons()); + $form->assign('suppressSubmitButton', $paymentObject->isSuppressSubmitButtons()); CRM_Financial_Form_Payment::addCreditCardJs($form->getPaymentProcessorID()); $form->assign('paymentProcessorID', $form->getPaymentProcessorID()); @@ -61,7 +61,7 @@ class CRM_Core_Payment_ProcessorForm { // also set cancel subscription url if (!empty($form->_paymentProcessor['is_recur']) && !empty($form->_values['is_recur'])) { - $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(NULL, NULL, 'cancel'); + $form->_values['cancelSubscriptionUrl'] = $paymentObject->subscriptionURL(NULL, NULL, 'cancel'); } $paymentProcessorBillingFields = array_keys($form->_paymentProcessor['object']->getBillingAddressFields()); @@ -110,7 +110,7 @@ class CRM_Core_Payment_ProcessorForm { if (!empty($form->_membershipBlock) && !empty($form->_membershipBlock['is_separate_payment']) && (!empty($form->_paymentProcessor['class_name']) && - !$form->_paymentObject->supports('MultipleConcurrentPayments') + !$paymentObject->supports('MultipleConcurrentPayments') ) ) { diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index a3614cfba5..971b0cd269 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -18,6 +18,7 @@ * This class generates form components for processing Event. */ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { + use CRM_Financial_Form_PaymentProcessorFormTrait; /** * The fields involved in this page. diff --git a/CRM/Financial/Form/PaymentProcessorFormTrait.php b/CRM/Financial/Form/PaymentProcessorFormTrait.php new file mode 100644 index 0000000000..8a6451ee82 --- /dev/null +++ b/CRM/Financial/Form/PaymentProcessorFormTrait.php @@ -0,0 +1,57 @@ +getPaymentProcessorMode()) . 'Mode'], $this->getAvailablePaymentProcessorIDS()); + } + + /** + * Get the payment processor IDs available on the form. + * + * @return false|array + */ + protected function getAvailablePaymentProcessorIDS() { + return FALSE; + } + + /** + * Get the mode (test or live) of the payment processor. + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @return string|null + * test or live + * @throws \CRM_Core_Exception + */ + public function getPaymentProcessorMode(): ?string { + return CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this); + } + + /** + * Get the payment processor object for the submission, returning the manual one for offline payments. + * + * @return CRM_Core_Payment + */ + protected function getPaymentProcessorObject() { + if (!empty($this->_paymentProcessor)) { + return $this->_paymentProcessor['object']; + } + return new CRM_Core_Payment_Manual(); + } + +} diff --git a/ext/eventcart/CRM/Event/Cart/Form/Checkout/Payment.php b/ext/eventcart/CRM/Event/Cart/Form/Checkout/Payment.php index ba283646d6..ed358fedce 100644 --- a/ext/eventcart/CRM/Event/Cart/Form/Checkout/Payment.php +++ b/ext/eventcart/CRM/Event/Cart/Form/Checkout/Payment.php @@ -162,8 +162,6 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart { ) { $this->_paymentProcessor = $paymentProcessorDetail; $this->assign('paymentProcessor', $this->_paymentProcessor); - // Setting this is a bit of a legacy overhang. - $this->_paymentObject = $paymentProcessorDetail['object']; } } // It's not clear why we set this on the form.