INFRA-132 - Docblock formatting fixes
[civicrm-core.git] / CRM / Core / Payment / Realex.php
index 8710fcc6271d2d2a2227cc7c57d466424754d6a6..dd7999280882baad1a0e4de86ed7567d8eeed672 100644 (file)
 
 
 /*
-   * 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)
+ */
 
 /**
  *
@@ -57,7 +56,8 @@ 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
    *
@@ -77,24 +77,6 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
     $this->_setParam('sequence', rand(1, 1000));
   }
 
-  /**
-   * Singleton function used to manage this object
-   *
-   * @param string $mode the mode of operation: live or test
-   *
-   * @param object $paymentProcessor
-   *
-   * @return object
-   * @static
-   */
-  public static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = false) {
-    $processorName = $paymentProcessor['name'];
-    if (self::$_singleton[$processorName] === NULL) {
-      self::$_singleton[$processorName] = new CRM_Core_Payment_Realex($mode, $paymentProcessor);
-    }
-    return self::$_singleton[$processorName];
-  }
-
   /**
    * @param array $params
    *
@@ -134,9 +116,11 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
   /**
    * 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)
+   * @return array
+   *   the result in a nice formatted array (or an error object)
    */
   public function doDirectPayment(&$params) {
 
@@ -158,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>
@@ -245,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) {
@@ -277,10 +260,11 @@ 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:
    */
   public function xml_parse_into_assoc($xml) {
     $input = array();
@@ -306,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),
           )
         );
       }
@@ -314,8 +298,8 @@ 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
    *
@@ -352,7 +336,7 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment {
    *  Format the params from the form ready for sending to Realex.  Also perform some validation
    */
   public function setRealexFields(&$params) {
-    if ((int)$params['amount'] <= 0) {
+    if ((int) $params['amount'] <= 0) {
       return self::error(9001, ts('Amount must be positive'));
     }
 
@@ -423,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);
     }
 
@@ -447,9 +431,11 @@ 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
    */
   public function _checkDupe($invoiceId) {
     $contribution = new CRM_Contribute_DAO_Contribution();
@@ -460,10 +446,12 @@ 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
    */
   public function _getParam($field) {
     if (isset($this->_params[$field])) {
@@ -481,7 +469,8 @@ 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
    */
   public function _setParam($field, $value) {
     if (!is_scalar($value)) {
@@ -528,7 +517,8 @@ 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
+   * @return string
+   *   the error message if any
    */
   public function checkConfig() {
     $error = array();