From 55f9f63462e4c961344426d5838b57a93de617b0 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 22 Dec 2016 18:32:44 +1300 Subject: [PATCH] CRM-19793 Redirect payment processors that fail result in ugly fatal - be prettier --- CRM/Event/Form/Registration/Confirm.php | 35 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 0f4c774d74..0a3c28f9e4 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -573,14 +573,10 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { } if (is_object($payment)) { - try { - $result = $payment->doPayment($value); - $value = array_merge($value, $result); - } - catch (\Civi\Payment\Exception\PaymentProcessorException $e) { - CRM_Core_Session::singleton()->setStatus($e->getMessage()); - CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); - } + // Not quite sure why we don't just user $value since it contains the data + // from result + // @todo ditch $result & retest. + list($result, $value) = $this->processPayment($payment, $value); } else { CRM_Core_Error::fatal($paymentObjError); @@ -824,7 +820,8 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { // call postprocess hook before leaving $this->postProcessHook(); // this does not return - $payment->doPayment($primaryParticipant, 'event'); + + $this->processPayment($payment, $primaryParticipant); } else { CRM_Core_Error::fatal($paymentObjError); @@ -1306,4 +1303,24 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { $form->postProcess(); } + /** + * Process the payment, redirecting back to the page on error. + * + * @param $payment + * @param $value + * + * @return array + */ + private function processPayment($payment, $value) { + try { + $result = $payment->doPayment($value, 'event'); + return array($result, $value); + } + catch (\Civi\Payment\Exception\PaymentProcessorException $e) { + CRM_Core_Session::singleton()->setStatus($e->getMessage()); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}")); + } + return array(); + } + } -- 2.25.1