From b2bfcb289c5895edbcac557df344ab06a024cbf0 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 16 Dec 2020 18:19:42 +1300 Subject: [PATCH] [REF] Extract code that assigns isPendingOutcome variable on thank you page --- CRM/Contribute/Form/Contribution/ThankYou.php | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index 41d8077543..2d12a1a6b2 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -279,34 +279,39 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $this->assign('friendURL', $url); } - $isPendingOutcome = TRUE; + $this->assign('isPendingOutcome', $this->isPendingOutcome($params)); + $this->freeze(); + + // can we blow away the session now to prevent hackery + // CRM-9491 + $this->controller->reset(); + } + + /** + * Is the outcome of this contribution still pending. + * + * @param array $params + * + * @return bool + */ + protected function isPendingOutcome(array $params): bool { + if (empty($params['payment_processor_id'])) { + return FALSE; + } try { // A payment notification update could have come in at any time. Check at the last minute. - $contributionStatusID = civicrm_api3('Contribution', 'getvalue', [ + civicrm_api3('Contribution', 'getvalue', [ 'id' => $params['contributionID'] ?? NULL, - 'return' => 'contribution_status_id', - 'is_test' => ($this->_mode == 'test') ? 1 : 0, + 'contribution_status_id' => 'Pending', + 'is_test' => '', + 'return' => 'id', 'invoice_id' => $params['invoiceID'] ?? NULL, ]); - if (CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID) === 'Pending' - && !empty($params['payment_processor_id']) - ) { - $isPendingOutcome = TRUE; - } - else { - $isPendingOutcome = FALSE; - } + return TRUE; } catch (CiviCRM_API3_Exception $e) { - + return FALSE; } - $this->assign('isPendingOutcome', $isPendingOutcome); - - $this->freeze(); - - // can we blow away the session now to prevent hackery - // CRM-9491 - $this->controller->reset(); } } -- 2.25.1