From 3b855c8b31caac87288f5054531eabc99b911858 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 19 Mar 2022 11:09:16 +1300 Subject: [PATCH] Ensure pay_later_text is always assigned --- CRM/Contribute/Form/Contribution/Main.php | 31 ++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 9d6a15c9b9ca..8341ec9c9eb9 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -352,19 +352,14 @@ public function buildQuickForm() { $this->addElement('hidden', "email-{$this->_bltID}", 1); $this->add('text', 'total_amount', ts('Total Amount'), ['readonly' => TRUE], FALSE); } - $pps = $this->getProcessors(); + $this->addPaymentProcessorFieldsToForm(); - if (!empty($pps) && count($pps) === 1) { - $ppKeys = array_keys($pps); - $currentPP = array_pop($ppKeys); - if ($currentPP === 0) { - $this->assign('is_pay_later', $this->_values['is_pay_later']); - $this->assign('pay_later_text', $this->getPayLaterLabel()); - } - } + $this->assign('is_pay_later', $this->getCurrentPaymentProcessor() === 0 && $this->_values['is_pay_later']); + $this->assign('pay_later_text', $this->getCurrentPaymentProcessor() === 0 ? $this->getPayLaterLabel() : NULL); if ($contactID === 0) { $this->addCidZeroOptions(); + } //build pledge block. @@ -1562,4 +1557,22 @@ protected function hasSeparateMembershipPaymentAmount($params) { return $this->_separateMembershipPayment && (int) CRM_Member_BAO_MembershipType::getMembershipType($params['selectMembership'])['minimum_fee']; } + /** + * Get the loaded payment processor - the default for the form. + * + * If the form is using 'pay later' then the value for the manual + * pay later processor is 0. + * + * @return int|null + */ + protected function getCurrentPaymentProcessor(): ?int { + $pps = $this->getProcessors(); + if (!empty($pps) && count($pps) === 1) { + $ppKeys = array_keys($pps); + return array_pop($ppKeys); + } + // It seems like this might be un=reachable as there should always be a processor... + return NULL; + } + }