CRM-19793 Redirect payment processors that fail result in ugly fatal - be prettier
authoreileen <emcnaughton@wikimedia.org>
Thu, 22 Dec 2016 05:32:44 +0000 (18:32 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 23 Jan 2017 23:44:07 +0000 (12:44 +1300)
CRM/Event/Form/Registration/Confirm.php

index 0f4c774d74980ce8047ea9ceeb319fa0e33a5169..0a3c28f9e4e9b27eae28d6882719c85ed1dedb64 100644 (file)
@@ -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();
+  }
+
 }