From 36723fe908973f72dc5cd57a249ee236fcfec868 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 8 Nov 2023 11:51:44 +1300 Subject: [PATCH] Use supports noReturn instead of contributeMode check In some cases actions are taken on notify contributions because they won't return - ie call hooks or send emails. In all cases but 1 paypal express is treated the same as notify - I think this last case is oversight not design. --- CRM/Contribute/Form/Contribution/Confirm.php | 2 +- CRM/Core/Payment.php | 14 ++++++++++++++ CRM/Event/Form/Registration.php | 5 ++--- CRM/Event/Form/Registration/Confirm.php | 6 ++---- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 5c87b87c32..1ab3ac4641 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -2721,7 +2721,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if (!empty($form->_paymentProcessor)) { try { $payment = Civi\Payment\System::singleton()->getByProcessor($form->_paymentProcessor); - if ($form->_contributeMode == 'notify') { + if ($this->getPaymentProcessorObject()->supports('noReturn')) { // We want to get rid of this & make it generic - eg. by making payment processing the last thing // and always calling it first. $form->postProcessHook(); diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 9e0f2a33a8..524abcf157 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1871,6 +1871,20 @@ abstract class CRM_Core_Payment { return method_exists(CRM_Utils_System::getClassName($this), 'changeSubscriptionAmount'); } + /** + * Checks if payment processor supports not returning to the form processing. + * + * The exists to support historical event form logic where emails are sent + * & the form postProcess hook is called before redirecting the browser where + * the user is redirected. + * + * @return bool + */ + public function supportsNoReturn(): bool { + $billingMode = (int) $this->_paymentProcessor['billing_mode']; + return $billingMode === self::BILLING_MODE_NOTIFY || $billingMode === self::BILLING_MODE_BUTTON; + } + /** * Checks if payment processor supports recurring contributions * diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index c10351632b..588dd46f92 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -1581,10 +1581,9 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { $this->set('participantInfo', $this->_participantInfo); } - //send mail Confirmation/Receipt - if ($this->_contributeMode != 'checkout' || - $this->_contributeMode != 'notify' + if ($this->getPaymentProcessorObject()->supports('noReturn') ) { + // Send mail Confirmation/Receipt. $this->sendMails($params, $registerByID, $participantCount); } } diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 04be4e89af..2bfea768ac 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -550,8 +550,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { if (!empty($value['is_pay_later']) || $value['amount'] == 0 || // The concept of contributeMode is deprecated. - $this->_contributeMode == 'checkout' || - $this->_contributeMode == 'notify' + $this->getPaymentProcessorObject()->supports('noReturn') ) { if ($value['amount'] != 0) { $pending = TRUE; @@ -749,8 +748,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { // for Transfer checkout. // The concept of contributeMode is deprecated. - if (($this->_contributeMode == 'checkout' || - $this->_contributeMode == 'notify' + if (($this->getPaymentProcessorObject()->supports('noReturn') ) && empty($params[0]['is_pay_later']) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0 -- 2.25.1