INFRA-132 - Remove @static annotation
[civicrm-core.git] / CRM / Core / Payment / Dummy.php
index 05d19d37e2c2448b9404e1a70096f6462665fafd..7d7b10a65bb481d6b48dc04140ed7cd1bd36869c 100644 (file)
  * $Id: Dummy.php 45429 2013-02-06 22:11:18Z lobo $
  */
 
-/* NOTE:
- * When looking up response codes in the Authorize.Net API, they
- * begin at one, so always delete one from the "Position in Response"
+/**
+ * Dummy payment processor
  */
 class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
-  CONST CHARSET = 'iso-8859-1';
+  const CHARSET = 'iso-8859-1';
 
   protected $_mode = NULL;
 
@@ -38,54 +37,35 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
    * pattern and cache the instance in this variable
    *
    * @var object
-   * @static
    */
   static private $_singleton = NULL;
 
   /**
    * Constructor
    *
-   * @param string $mode the mode of operation: live or test
+   * @param string $mode
+   *   The mode of operation: live or test.
    *
    * @param $paymentProcessor
    *
    * @return \CRM_Core_Payment_Dummy
    */
-  function __construct($mode, &$paymentProcessor) {
+  public function __construct($mode, &$paymentProcessor) {
     $this->_mode = $mode;
     $this->_paymentProcessor = $paymentProcessor;
     $this->_processorName = ts('Dummy Processor');
   }
 
-  /**
-   * singleton function used to manage this object
-   *
-   * @param string $mode the mode of operation: live or test
-   *
-   * @param object $paymentProcessor
-   * @param null $paymentForm
-   * @param bool $force
-   *
-   * @return object
-   * @static
-   */
-  static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
-    $processorName = $paymentProcessor['name'];
-    if (CRM_Utils_Array::value($processorName, self::$_singleton) === NULL) {
-      self::$_singleton[$processorName] = new CRM_Core_Payment_Dummy($mode, $paymentProcessor);
-    }
-    return self::$_singleton[$processorName];
-  }
-
   /**
    * Submit a payment using Advanced Integration Method
    *
-   * @param  array $params assoc array of input parameters for this transaction
+   * @param array $params
+   *   Assoc array of input parameters for this transaction.
    *
-   * @return array the result in a nice formatted array (or an error object)
-   * @public
+   * @return array
+   *   the result in a nice formatted array (or an error object)
    */
-  function doDirectPayment(&$params) {
+  public function doDirectPayment(&$params) {
     // Invoke hook_civicrm_paymentProcessor
     // In Dummy's case, there is no translation of parameters into
     // the back-end's canonical set of parameters.  But if a processor
@@ -103,32 +83,44 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
       return $this->_doDirectPaymentResult;
     }
     if ($this->_mode == 'test') {
-      $query             = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
-      $p                 = array();
-      $trxn_id           = strval(CRM_Core_Dao::singleValueQuery($query, $p));
-      $trxn_id           = str_replace('test_', '', $trxn_id);
-      $trxn_id           = intval($trxn_id) + 1;
+      $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
+      $p = array();
+      $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p));
+      $trxn_id = str_replace('test_', '', $trxn_id);
+      $trxn_id = intval($trxn_id) + 1;
       $params['trxn_id'] = sprintf('test_%08d', $trxn_id);
     }
     else {
-      $query             = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'";
-      $p                 = array();
-      $trxn_id           = strval(CRM_Core_Dao::singleValueQuery($query, $p));
-      $trxn_id           = str_replace('live_', '', $trxn_id);
-      $trxn_id           = intval($trxn_id) + 1;
+      $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'";
+      $p = array();
+      $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p));
+      $trxn_id = str_replace('live_', '', $trxn_id);
+      $trxn_id = intval($trxn_id) + 1;
       $params['trxn_id'] = sprintf('live_%08d', $trxn_id);
     }
     $params['gross_amount'] = $params['amount'];
+    // Add a fee_amount so we can make sure fees are handled properly in underlying classes.
+    $params['fee_amount'] = 1.50;
+    $params['net_amount'] = $params['gross_amount'] - $params['fee_amount'];
+
     return $params;
   }
 
+  /**
+   * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login
+   * @return bool
+   */
+  protected function supportsLiveMode() {
+    return FALSE;
+  }
+
   /**
    * @param null $errorCode
    * @param null $errorMessage
    *
    * @return object
    */
-  function &error($errorCode = NULL, $errorMessage = NULL) {
+  public function &error($errorCode = NULL, $errorMessage = NULL) {
     $e = CRM_Core_Error::singleton();
     if ($errorCode) {
       $e->push($errorCode, 0, NULL, $errorMessage);
@@ -142,11 +134,10 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment {
   /**
    * This function checks to see if we have the right config values
    *
-   * @return string the error message if any
-   * @public
+   * @return string
+   *   the error message if any
    */
-  function checkConfig() {
+  public function checkConfig() {
     return NULL;
   }
 }
-