From 71e680bd6633b1abd76bd699cc0fa653e794d078 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 2 Apr 2019 15:25:46 +1300 Subject: [PATCH] Rationalise loading of payment processor across the 3 update forms This only covers when the crid is in the URL since we have an existing better fn for that & it's easy to test. --- CRM/Contribute/Form/CancelSubscription.php | 2 -- CRM/Contribute/Form/ContributionRecur.php | 32 ++++++++++++++++++++++ CRM/Contribute/Form/UpdateBilling.php | 7 ----- CRM/Contribute/Form/UpdateSubscription.php | 9 ------ CRM/Core/Payment.php | 1 + 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/CRM/Contribute/Form/CancelSubscription.php b/CRM/Contribute/Form/CancelSubscription.php index ce98fbb513..4b2ce6b359 100644 --- a/CRM/Contribute/Form/CancelSubscription.php +++ b/CRM/Contribute/Form/CancelSubscription.php @@ -35,7 +35,6 @@ * This class provides support for canceling recurring subscriptions. */ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_ContributionRecur { - protected $_paymentProcessorObj = NULL; protected $_userContext = NULL; @@ -49,7 +48,6 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Contribute_Form_Contrib public function preProcess() { parent::preProcess(); if ($this->_crid) { - $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'obj'); $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_crid); $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit); $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval); diff --git a/CRM/Contribute/Form/ContributionRecur.php b/CRM/Contribute/Form/ContributionRecur.php index d0b1ee2873..6d3416ff78 100644 --- a/CRM/Contribute/Form/ContributionRecur.php +++ b/CRM/Contribute/Form/ContributionRecur.php @@ -61,6 +61,21 @@ class CRM_Contribute_Form_ContributionRecur extends CRM_Core_Form { */ protected $_mid = NULL; + /** + * Payment processor object. + * + * @var \CRM_Core_Payment + */ + protected $_paymentProcessorObj = NULL; + + /** + * @var array + * + * Current payment processor including a copy of the object in 'object' key for + * legacy reasons. + */ + public $_paymentProcessor = []; + /** * Explicitly declare the entity api name. */ @@ -83,6 +98,23 @@ class CRM_Contribute_Form_ContributionRecur extends CRM_Core_Form { $this->_crid = CRM_Utils_Request::retrieve('crid', 'Integer', $this, FALSE); $this->contributionRecurID = $this->_crid; $this->_coid = CRM_Utils_Request::retrieve('coid', 'Integer', $this, FALSE); + $this->setPaymentProcessor(); + } + + /** + * Set the payment processor object up. + * + * This is a function that needs to be better consolidated between the inheriting forms + * but this is good choice of function to call. + */ + protected function setPaymentProcessor() { + if ($this->_crid) { + $this->_paymentProcessor = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessor($this->contributionRecurID); + if (!$this->_paymentProcessor) { + CRM_Core_Error::statusBounce(ts('There is no valid processor for this subscription so it cannot be updated')); + } + $this->_paymentProcessorObj = $this->_paymentProcessor['object']; + } } } diff --git a/CRM/Contribute/Form/UpdateBilling.php b/CRM/Contribute/Form/UpdateBilling.php index 03c3b80c71..24030f032d 100644 --- a/CRM/Contribute/Form/UpdateBilling.php +++ b/CRM/Contribute/Form/UpdateBilling.php @@ -43,19 +43,12 @@ class CRM_Contribute_Form_UpdateBilling extends CRM_Contribute_Form_Contribution public $_bltID = NULL; - /** - * @var array current payment processor including a copy of the object in 'object' key - */ - public $_paymentProcessor = array(); - /** * Set variables up before form is built. */ public function preProcess() { parent::preProcess(); if ($this->_crid) { - $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'info'); - $this->_paymentProcessor['object'] = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'obj'); $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_crid); // Are we cancelling a recurring contribution that is linked to an auto-renew membership? diff --git a/CRM/Contribute/Form/UpdateSubscription.php b/CRM/Contribute/Form/UpdateSubscription.php index cbe2ee8333..501ab0ac26 100644 --- a/CRM/Contribute/Form/UpdateSubscription.php +++ b/CRM/Contribute/Form/UpdateSubscription.php @@ -72,15 +72,6 @@ class CRM_Contribute_Form_UpdateSubscription extends CRM_Contribute_Form_Contrib $this->setAction(CRM_Core_Action::UPDATE); if ($this->contributionRecurID) { - try { - $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorForRecurringContribution($this->contributionRecurID); - } - catch (CRM_Core_Exception $e) { - CRM_Core_Error::statusBounce(ts('There is no valid processor for this subscription so it cannot be edited.')); - } - catch (CiviCRM_API3_Exception $e) { - CRM_Core_Error::statusBounce(ts('There is no valid processor for this subscription so it cannot be edited.')); - } $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->contributionRecurID); } diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 1aaa4aa5f5..1197cd10fb 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -632,6 +632,7 @@ abstract class CRM_Core_Payment { if ($this->supports('changeSubscriptionAmount')) { return ['amount']; } + return []; } /** -- 2.25.1