INFRA-132 - CRM/Core - phpcbf
[civicrm-core.git] / CRM / Core / Payment / eWAY.php
index 10f2a3236d4d66c670035883c6925a7b175434fd..4dfce475e741e0d435e4d7ad03c59c648177f594 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -26,7 +26,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | eWAY Core Payment Module for CiviCRM version 4.5 & 1.9             |
+ | eWAY Core Payment Module for CiviCRM version 4.6 & 1.9             |
  +--------------------------------------------------------------------+
  | Licensed to CiviCRM under the Academic Free License version 3.0    |
  |                                                                    |
@@ -92,7 +92,7 @@
  **/
 class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   # (not used, implicit in the API, might need to convert?)
-  CONST CHARSET = 'UTF-8';
+  const CHARSET = 'UTF-8';
 
   /**
    * We only need one instance of this object. So we use the singleton
@@ -106,12 +106,15 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   /**********************************************************
    * Constructor
    *
-   * @param string $mode the mode of operation: live or test
+   * @param string $mode
+   *   The mode of operation: live or test.
    *
-   * @return void
-   **********************************************************/
-  function __construct($mode, &$paymentProcessor) {
-    // require Standaard eWAY API libraries
+   * @param $paymentProcessor
+   *
+   * @return \CRM_Core_Payment_eWAY *******************************************************
+   */
+  public function __construct($mode, &$paymentProcessor) {
+    // require Standard eWAY API libraries
     require_once 'eWAY/eWAY_GatewayRequest.php';
     require_once 'eWAY/eWAY_GatewayResponse.php';
 
@@ -122,27 +125,38 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   }
 
   /**
-   * singleton function used to manage this object
+   * Singleton function used to manage this object
    *
-   * @param string $mode the mode of operation: live or test
+   * @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 (self::$_singleton[$processorName] === NULL) {
-      self::$_singleton[$processorName] = new CRM_Core_Payment_eWAY($mode, $paymentProcessor);
+  public static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
+    if (!empty($paymentProcessor['id'])) {
+      $cacheKey = $paymentProcessor['id'];
+    }
+    else {
+      //@todo eliminated instances of this in favour of id-specific instances.
+      $cacheKey = $mode . '_' . $paymentProcessor['name'];
+    }
+
+    if (self::$_singleton[$cacheKey] === NULL) {
+      self::$_singleton[$cacheKey] = new CRM_Core_Payment_eWAY($mode, $paymentProcessor);
     }
-    return self::$_singleton[$processorName];
+    return self::$_singleton[$cacheKey];
   }
 
   /**********************************************************
    * This function sends request and receives response from
    * eWAY payment process
    **********************************************************/
-  function doDirectPayment(&$params) {
+  public function doDirectPayment(&$params) {
     if (CRM_Utils_Array::value('is_recur', $params) == TRUE) {
       CRM_Core_Error::fatal(ts('eWAY - recurring payments not implemented'));
     }
@@ -180,7 +194,6 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
        $country        = $params['country'];
        */
 
-
     //-------------------------------------------------------------
     // Prepare some composite data from _paymentProcessor fields
     //-------------------------------------------------------------
@@ -311,12 +324,14 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
       $errorDesc = curl_error($submit);
 
       // Paranoia - in the unlikley event that 'curl' errno fails
-      if ($errorNum == 0)
-      $errorNum = 9005;
+      if ($errorNum == 0) {
+        $errorNum = 9005;
+      }
 
       // Paranoia - in the unlikley event that 'curl' error fails
-      if (strlen($errorDesc) == 0)
-      $errorDesc = "Connection to eWAY payment gateway failed";
+      if (strlen($errorDesc) == 0) {
+        $errorDesc = "Connection to eWAY payment gateway failed";
+      }
 
       return self::errorExit($errorNum, $errorDesc);
     }
@@ -403,7 +418,6 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
        }
        */
 
-
     //=============
     // Success !
     //=============
@@ -422,11 +436,12 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   /**
    * Checks to see if invoice_id already exists in db
    *
-   * @param  int     $invoiceId   The ID to check
+   * @param int $invoiceId
+   *   The ID to check.
    *
    * @return bool                 True if ID exists, else false
    */
-  function _checkDupe($invoiceId) {
+  public function _checkDupe($invoiceId) {
     $contribution = new CRM_Contribute_DAO_Contribution();
     $contribution->invoice_id = $invoiceId;
     return $contribution->find();
@@ -435,7 +450,7 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   /*************************************************************************************************
    * This function checks the eWAY response status - returning a boolean false if status != 'true'
    *************************************************************************************************/
-  function isError(&$response) {
+  public function isError(&$response) {
     $status = $response->Status();
 
     if ((stripos($status, "true")) === FALSE) {
@@ -447,7 +462,7 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   /**************************************************
    * Produces error message and returns from class
    **************************************************/
-  function &errorExit($errorCode = NULL, $errorMessage = NULL) {
+  public function &errorExit($errorCode = NULL, $errorMessage = NULL) {
     $e = CRM_Core_Error::singleton();
 
     if ($errorCode) {
@@ -462,7 +477,7 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
   /**************************************************
    * NOTE: 'doTransferCheckout' not implemented
    **************************************************/
-  function doTransferCheckout(&$params, $component) {
+  public function doTransferCheckout(&$params, $component) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
@@ -472,16 +487,18 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
    * NOTE: Called by Events and Contribute to check config params are set prior to trying
    *       register any credit card details
    *
-   * @param string $mode the mode we are operating in (live or test) - not used but could be
+   * @return null|string
+   * @internal param string $mode the mode we are operating in (live or test) - not used but could be
    * to check that the 'test' mode CustomerID was equal to '87654321' and that the URL was
    * set to https://www.eway.com.au/gateway_cvn/xmltest/TestPage.asp
    *
    * returns string $errorMsg if any errors found - null if OK
    *
-   ********************************************************************************************/
+   ******************************************************************************************
+   */
   //function checkConfig( $mode )          // CiviCRM V1.9 Declaration
   // CiviCRM V2.0 Declaration
-  function checkConfig() {
+  public function checkConfig() {
     $errorMsg = array();
 
     if (empty($this->_paymentProcessor['user_name'])) {
@@ -500,11 +517,17 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment {
     }
   }
 
-  function send_alert_email($p_eWAY_tran_num, $p_trxn_out, $p_trxn_back, $p_request, $p_response) {
+  /**
+   * @param $p_eWAY_tran_num
+   * @param $p_trxn_out
+   * @param $p_trxn_back
+   * @param $p_request
+   * @param $p_response
+   */
+  public function send_alert_email($p_eWAY_tran_num, $p_trxn_out, $p_trxn_back, $p_request, $p_response) {
     // Initialization call is required to use CiviCRM APIs.
     civicrm_initialize(TRUE);
 
-
     list($fromName, $fromEmail) = CRM_Core_BAO_Domain::getNameAndEmail();
     $from = "$fromName <$fromEmail>";
 
@@ -553,4 +576,3 @@ The CiviCRM eWAY Payment Processor Module
   }
 }
 // end class CRM_Core_Payment_eWAY
-