INFRA-132 - Docblock formatting fixes
[civicrm-core.git] / CRM / Core / Payment / Realex.php
index 2122c6ad79b66ff297387710cda71b70acebef99..dd7999280882baad1a0e4de86ed7567d8eeed672 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 
 
 /*
-   * Copyright (C) 2009
-   * Licensed to CiviCRM under the Academic Free License version 3.0.
-   *
-   * Written and contributed by Kirkdesigns (http://www.kirkdesigns.co.uk)
-   *
-   */
+ * Copyright (C) 2009
+ * Licensed to CiviCRM under the Academic Free License version 3.0.
+ *
+ * Written and contributed by Kirkdesigns (http://www.kirkdesigns.co.uk)
+ */
 
 /**
  *
@@ -39,7 +38,7 @@
  * $Id$
  */
 class CRM_Core_Payment_Realex extends CRM_Core_Payment {
-  CONST AUTH_APPROVED = '00';
+  const AUTH_APPROVED = '00';
 
   protected $_mode = NULL;
 
@@ -57,13 +56,14 @@ class CRM_Core_Payment_Realex 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.
    *
    * @param $paymentProcessor
    *
    * @return \CRM_Core_Payment_Realex
    */
-  function __construct($mode, &$paymentProcessor) {
+  public function __construct($mode, &$paymentProcessor) {
     $this->_mode = $mode;
     $this->_paymentProcessor = $paymentProcessor;
     $this->_processorName = ts('Realex');
@@ -78,29 +78,11 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
   }
 
   /**
-   * singleton function used to manage this object
-   *
-   * @param string $mode the mode of operation: live or test
-   *
-   * @param object $paymentProcessor
-   *
-   * @return object
-   * @static
-   */
-  static function &singleton($mode, &$paymentProcessor) {
-    $processorName = $paymentProcessor['name'];
-    if (self::$_singleton[$processorName] === NULL) {
-      self::$_singleton[$processorName] = new CRM_Core_Payment_Realex($mode, $paymentProcessor);
-    }
-    return self::$_singleton[$processorName];
-  }
-
-  /**
-   * @param $params
+   * @param array $params
    *
    * @throws Exception
    */
-  function setExpressCheckOut(&$params) {
+  public function setExpressCheckOut(&$params) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
@@ -109,37 +91,38 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
    *
    * @throws Exception
    */
-  function getExpressCheckoutDetails($token) {
+  public function getExpressCheckoutDetails($token) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @throws Exception
    */
-  function doExpressCheckout(&$params) {
+  public function doExpressCheckout(&$params) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
   /**
-   * @param $params
+   * @param array $params
    *
    * @throws Exception
    */
-  function doTransferCheckout(&$params) {
+  public function doTransferCheckout(&$params) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
   /**
    * 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) {
 
     if (!defined('CURLOPT_SSLCERT')) {
       return self::error(9001, ts('RealAuth requires curl with SSL support'));
@@ -159,12 +142,11 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     }
 
     // Create sha1 hash for request
-    $hashme   = "{$this->_getParam('timestamp')}.{$this->_getParam('merchant_ref')}.{$this->_getParam('order_id')}.{$this->_getParam('amount')}.{$this->_getParam('currency')}.{$this->_getParam('card_number')}";
+    $hashme = "{$this->_getParam('timestamp')}.{$this->_getParam('merchant_ref')}.{$this->_getParam('order_id')}.{$this->_getParam('amount')}.{$this->_getParam('currency')}.{$this->_getParam('card_number')}";
     $sha1hash = sha1($hashme);
-    $hashme   = "$sha1hash.{$this->_getParam('secret')}";
+    $hashme = "$sha1hash.{$this->_getParam('secret')}";
     $sha1hash = sha1($hashme);
 
-
     // Generate the request xml that is send to Realex Payments.
     $request_xml = "<request type='auth' timestamp='{$this->_getParam('timestamp')}'>
           <merchantid>{$this->_getParam('merchant_ref')}</merchantid>
@@ -246,9 +228,9 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     }
 
     // Check the response hash
-    $hashme   = "{$this->_getParam('timestamp')}.{$this->_getParam('merchant_ref')}.{$this->_getParam('order_id')}.{$response['RESULT']}.{$response['MESSAGE']}.{$response['PASREF']}.{$response['AUTHCODE']}";
+    $hashme = "{$this->_getParam('timestamp')}.{$this->_getParam('merchant_ref')}.{$this->_getParam('order_id')}.{$response['RESULT']}.{$response['MESSAGE']}.{$response['PASREF']}.{$response['AUTHCODE']}";
     $sha1hash = sha1($hashme);
-    $hashme   = "$sha1hash.{$this->_getParam('secret')}";
+    $hashme = "$sha1hash.{$this->_getParam('secret')}";
     $sha1hash = sha1($hashme);
 
     if ($response['SHA1HASH'] != $sha1hash) {
@@ -278,12 +260,13 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
   /**
    * Helper function to convert XML string to multi-dimension array.
    *
-   * @param $xml
+   * @param string $xml
    *   an XML string.
    *
-   * @return array An array of the result with following keys:
+   * @return array
+   *   An array of the result with following keys:
    */
-  function xml_parse_into_assoc($xml) {
+  public function xml_parse_into_assoc($xml) {
     $input = array();
     $result = array();
 
@@ -307,7 +290,7 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
           array(
             1 => xml_get_error_code($xmlparser),
             2 => xml_get_current_line_number($xmlparser),
-            3 => xml_get_current_column_number($xmlparser)
+            3 => xml_get_current_column_number($xmlparser),
           )
         );
       }
@@ -315,14 +298,14 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     return $result;
   }
 
-  // private helper for  xml_parse_into_assoc, to recusively parsing the result
   /**
+   * Private helper for  xml_parse_into_assoc, to recusively parsing the result
    * @param $input
    * @param int $depth
    *
    * @return array
    */
-  function _xml_parse($input, $depth = 1) {
+  public function _xml_parse($input, $depth = 1) {
     $output = array();
     $children = array();
 
@@ -352,8 +335,8 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
   /**
    *  Format the params from the form ready for sending to Realex.  Also perform some validation
    */
-  function setRealexFields(&$params) {
-    if ((int)$params['amount'] <= 0) {
+  public function setRealexFields(&$params) {
+    if ((int) $params['amount'] <= 0) {
       return self::error(9001, ts('Amount must be positive'));
     }
 
@@ -424,17 +407,17 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     $this->_setParam('currency', $config->defaultCurrency);
 
     // Format the expiry date to MMYY
-    $expmonth = (string)$params['month'];
+    $expmonth = (string) $params['month'];
     $expmonth = (strlen($expmonth) === 1) ? '0' . $expmonth : $expmonth;
-    $expyear  = substr((string)$params['year'], 2, 2);
+    $expyear = substr((string) $params['year'], 2, 2);
     $this->_setParam('exp_date', $expmonth . $expyear);
 
     if (isset($params['credit_card_start_date']) && (strlen($params['credit_card_start_date']['M']) !== 0) &&
       (strlen($params['credit_card_start_date']['Y']) !== 0)
     ) {
-      $startmonth = (string)$params['credit_card_start_date']['M'];
+      $startmonth = (string) $params['credit_card_start_date']['M'];
       $startmonth = (strlen($startmonth) === 1) ? '0' . $startmonth : $startmonth;
-      $startyear  = substr((string)$params['credit_card_start_date']['Y'], 2, 2);
+      $startyear = substr((string) $params['credit_card_start_date']['Y'], 2, 2);
       $this->_setParam('start_date', $startmonth . $startyear);
     }
 
@@ -448,11 +431,13 @@ class CRM_Core_Payment_Realex 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
+   * @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();
@@ -461,12 +446,14 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
   /**
    * Get the value of a field if set
    *
-   * @param string $field the field
+   * @param string $field
+   *   The field.
    *
-   * @return mixed value of the field, or empty string if the field is
-   * not set
+   * @return mixed
+   *   value of the field, or empty string if the field is
+   *   not set
    */
-  function _getParam($field) {
+  public function _getParam($field) {
     if (isset($this->_params[$field])) {
       return $this->_params[$field];
     }
@@ -482,9 +469,10 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
    * @param string $field
    * @param mixed $value
    *
-   * @return bool false if value is not a scalar, true if successful
+   * @return bool
+   *   false if value is not a scalar, true if successful
    */
-  function _setParam($field, $value) {
+  public function _setParam($field, $value) {
     if (!is_scalar($value)) {
       return FALSE;
     }
@@ -499,7 +487,7 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
    *
    * @return object
    */
-  function &error($errorCode = NULL, $errorMessage = NULL) {
+  public function &error($errorCode = NULL, $errorMessage = NULL) {
     $e = CRM_Core_Error::singleton();
 
     if ($errorCode) {
@@ -529,10 +517,10 @@ class CRM_Core_Payment_Realex 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() {
     $error = array();
     if (empty($this->_paymentProcessor['user_name'])) {
       $error[] = ts('Merchant ID is not set for this payment processor');
@@ -550,4 +538,3 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     }
   }
 }
-