CRM-16808 follow up - finally remove all references to calling doTransferPayment...
authorEileen McNaughton <eileen@fuzion.co.nz>
Thu, 16 Jul 2015 22:07:59 +0000 (10:07 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Thu, 16 Jul 2015 22:07:59 +0000 (10:07 +1200)
CRM/Contribute/Form/AdditionalPayment.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Core/Payment.php
CRM/Core/Payment/Elavon.php
CRM/Core/Payment/FirstData.php
CRM/Core/Payment/Realex.php
CRM/Core/Payment/eWAY.php
CRM/Event/Cart/Form/Checkout/Payment.php
CRM/Event/Form/Registration/Confirm.php
tests/extensions/test.extension.manager.paymenttest/main.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php

index eba618cbf5634dd8c52ddec6da30e1002be3c7a4..05be49a28bbb931efeffd220653238ad1a4b05c5 100644 (file)
@@ -564,19 +564,20 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     $result = NULL;
 
     if ($paymentParams['amount'] > 0.0) {
-      // force a reget of the payment processor in case the form changed it, CRM-7179
-      $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
-      $result = $payment->doDirectPayment($paymentParams);
-    }
-
-    if (is_a($result, 'CRM_Core_Error')) {
-      //set the contribution mode.
-      $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
-      if ($this->_mode) {
-        $urlParams .= "&mode={$this->_mode}";
+      try {
+        // force a reget of the payment processor in case the form changed it, CRM-7179
+        $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
+        $result = $payment->doPayment($paymentParams);
+      }
+      catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
+        //set the contribution mode.
+        $urlParams = "action=add&cid={$this->_contactId}&id={$this->_id}&component={$this->_component}";
+        if ($this->_mode) {
+          $urlParams .= "&mode={$this->_mode}";
+        }
+        CRM_Core_Error::displaySessionError($result);
+        CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/add', $urlParams));
       }
-      CRM_Core_Error::displaySessionError($result);
-      CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/add', $urlParams));
     }
 
     if ($result) {
index 85e419bd113f6fc4b266f17cc2b31a5a100213b3..61ccdcf957b3d9442875ef2ae611a8c2a3e5f6c8 100644 (file)
@@ -1766,7 +1766,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
         $form->postProcessHook();
         // this does not return
         $payment = Civi\Payment\System::singleton()->getByProcessor($form->_paymentProcessor);
-        $payment->doTransferCheckout($form->_params, 'contribute');
+        $payment->doPayment($form->_params, 'contribute');
       }
     }
 
@@ -1853,16 +1853,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       else {
         $payment = $form->_paymentProcessor['object'];
       }
-
-      if ($form->_contributeMode == 'express') {
-        $result = $payment->doExpressCheckout($tempParams);
-        if (is_a($result, 'CRM_Core_Error')) {
-          throw new CRM_Core_Exception(CRM_Core_Error::getMessages($result));
-        }
-      }
-      else {
-        $result = $payment->doPayment($tempParams, 'contribute');
-      }
+      $result = $payment->doPayment($tempParams, 'contribute');
     }
 
     //assign receive date when separate membership payment
index 5d60d321ee53e8d8eec4ff4784e64f95dfcbf9b7..860eaa3f67d91aeb7e69c931f44c8d4fc4d22bf4 100644 (file)
@@ -633,7 +633,7 @@ abstract class CRM_Core_Payment {
    *   the result in an nice formatted array (or an error object)
    * @abstract
    */
-  abstract protected function doDirectPayment(&$params);
+  protected function doDirectPayment(&$params) {}
 
   /**
    * Process payment - this function wraps around both doTransferPayment and doDirectPayment.
index bcbe845b7d158c060c079dd24e18b4bd8bf0dcf7..c106553b315952e46ae87ab0b4785f8c19ad48e0 100644 (file)
@@ -276,13 +276,6 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment {
     return $e;
   }
 
-  /**
-   * NOTE: 'doTransferCheckout' not implemented
-   */
-  public function doTransferCheckout(&$params, $component) {
-    CRM_Core_Error::fatal(ts('This function is not implemented'));
-  }
-
   /**
    * This public function checks to see if we have the right processor config values set.
    *
index 810e7b2d890a7896ce73cb3f2193048f9cb3a4b6..3e66de93f6a142f10b242749c536acecd861fda9 100644 (file)
@@ -315,13 +315,6 @@ class CRM_Core_Payment_FirstData extends CRM_Core_Payment {
     return $e;
   }
 
-  /**
-   * NOTE: 'doTransferCheckout' not implemented
-   */
-  public function doTransferCheckout(&$params, $component) {
-    CRM_Core_Error::fatal(ts('This function is not implemented'));
-  }
-
   /**
    * This public function checks to see if we have the right processor config values set.
    *
index a31171ecbf6d503a691f59ed10826be3047f544c..4fac0793773cf24a5b5e2b2acde96ffef5ef87f9 100644 (file)
@@ -76,15 +76,6 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     $this->_setParam('sequence', rand(1, 1000));
   }
 
-  /**
-   * @param array $params
-   *
-   * @throws Exception
-   */
-  public function doTransferCheckout(&$params) {
-    CRM_Core_Error::fatal(ts('This function is not implemented'));
-  }
-
   /**
    * Submit a payment using Advanced Integration Method.
    *
index 7360555dadc117ed3f6a5eae1a62d5253db2daf6..be16af3e2bc3a3a749ca42cdf0ca90039614783f 100644 (file)
@@ -439,15 +439,6 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
     return $e;
   }
 
-  /**
-   * ************************************************
-   * NOTE: 'doTransferCheckout' not implemented
-   * ************************************************
-   */
-  public function doTransferCheckout(&$params, $component) {
-    CRM_Core_Error::fatal(ts('This function is not implemented'));
-  }
-
   /**
    * *****************************************************************************************
    * This public function checks to see if we have the right processor config values set
index bf454ecce957a4ad32e75cabab9a3f9eb0ff324d..292adda6f8d32d7fc7e59db29d85e9d4fff4821c 100644 (file)
@@ -575,15 +575,14 @@ class CRM_Event_Cart_Form_Checkout_Payment extends CRM_Event_Cart_Form_Cart {
     CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, TRUE);
     $params['month'] = $params['credit_card_exp_date']['M'];
     $params['year'] = $params['credit_card_exp_date']['Y'];
-    $result = &$payment->doDirectPayment($params);
-    if (is_a($result, 'CRM_Core_Error')) {
+    try {
+      $result = $payment->doPayment($params);
+    }
+    catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
       CRM_Core_Error::displaySessionError($result);
       CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/cart_checkout', "_qf_Payment_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE));
-      return NULL;
-    }
-    elseif (!$result['trxn_id']) {
-      CRM_Core_Error::fatal(ts("Financial institution didn't return a transaction id."));
     }
+
     $trxnDetails = array(
       'trxn_id' => $result['trxn_id'],
       'trxn_date' => $result['now'],
index 9d378b464adb7d22915dc19c3235784e1c791a8b..75ea1581d51f6b75dc1bf67adef0fd081ba96122 100644 (file)
@@ -597,14 +597,6 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
             $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses);
           }
         }
-        elseif ($this->_contributeMode == 'express' && !empty($value['is_primary'])) {
-          if (is_object($payment)) {
-            $result = $payment->doExpressCheckout($value);
-          }
-          else {
-            CRM_Core_Error::fatal($paymentObjError);
-          }
-        }
         elseif (!empty($value['is_primary'])) {
           CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE);
           // payment email param can be empty for _bltID mapping
@@ -614,22 +606,20 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
           }
 
           if (is_object($payment)) {
-            $result = $payment->doDirectPayment($value);
+            try {
+              $result = $payment->doPayment($value);
+              $value = array_merge($value, $result);
+            }
+            catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
+              CRM_Core_Error::displaySessionError($result);
+              CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
+            }
           }
           else {
             CRM_Core_Error::fatal($paymentObjError);
           }
         }
 
-        if (is_a($result, 'CRM_Core_Error')) {
-          CRM_Core_Error::displaySessionError($result);
-          CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
-        }
-
-        if ($result) {
-          $value = array_merge($value, $result);
-        }
-
         $value['receive_date'] = $now;
         if ($this->_allowConfirmation) {
           $value['participant_register_date'] = $this->_values['participant']['register_date'];
@@ -865,7 +855,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
           // call postprocess hook before leaving
           $this->postProcessHook();
           // this does not return
-          $payment->doTransferCheckout($primaryParticipant, 'event');
+          $payment->doPayment($primaryParticipant, 'event');
         }
         else {
           CRM_Core_Error::fatal($paymentObjError);
index 28d034bb0a12a3cdce60e49af71549034b2b6706..98d817ac8e82dcb27494aad7be4edb5b8778a385 100644 (file)
@@ -4,29 +4,6 @@
  * Class test_extension_manager_paymenttest
  */
 class test_extension_manager_paymenttest extends CRM_Core_Payment {
-  static private $_singleton = NULL;
-
-  /**
-   * Singleton function used to manage this object.
-   *
-   * @param string $mode
-   *   The mode of operation: live or test.
-   * @param array $paymentProcessor
-   *   The details of the payment processor being invoked.
-   * @param CRM_Core_Form $paymentForm
-   *   Reference to the form object if available.
-   * @param bool $force
-   *   Should we force a reload of this payment object.
-   *
-   * @return object
-   */
-  public static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
-    $processorName = $paymentProcessor['name'];
-    if (self::$_singleton[$processorName] === NULL) {
-      self::$_singleton[$processorName] = new test_extension_manager_paymenttest();
-    }
-    return self::$_singleton[$processorName];
-  }
 
   static $counts = array();
 
@@ -46,17 +23,6 @@ class test_extension_manager_paymenttest extends CRM_Core_Payment {
     self::$counts['enable'] = 1 + (int) self::$counts['enable'];
   }
 
-  /**
-   * This function collects all the information from a web/api form and invokes
-   * the relevant payment processor specific functions to perform the transaction
-   *
-   * @param array $params
-   *   Assoc array of input parameters for this transaction.
-   *
-   */
-  public function doDirectPayment(&$params) {
-  }
-
   public function checkConfig() {
   }
 
index 8d892634e838f21ad5dc67cba797a7cc1d32de6c..78bed99e815b2d593c95a8a9c5516ffb1d556fd5 100644 (file)
@@ -308,7 +308,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
 
     // turn verifySSL off
     CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
-    $result = $this->processor->doDirectPayment($params);
+    $result = $this->processor->doPayment($params);
     // turn verifySSL on
     CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');