Merge pull request #4958 from pratikshad/code-cleanup-batch-19
[civicrm-core.git] / CRM / Core / Payment / PaymentExpress.php
index 802382545de49976475fbb06ecf393c6080b2e22..7b181db47f369d0324cd3cee623c095fb717763d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
   +--------------------------------------------------------------------+
-  | CiviCRM version 4.5                                                |
+  | CiviCRM version 4.6                                                |
   +--------------------------------------------------------------------+
   | This file is a part of CiviCRM.                                    |
   |                                                                    |
@@ -37,7 +37,7 @@
  * Class CRM_Core_Payment_PaymentExpress
  */
 class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
-  CONST CHARSET = 'iso-8859-1';
+  const CHARSET = 'iso-8859-1';
 
   protected $_mode = NULL;
 
@@ -46,55 +46,35 @@ class CRM_Core_Payment_PaymentExpress 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_PaymentExpress
    */
-  function __construct($mode, &$paymentProcessor) {
+  public function __construct($mode, &$paymentProcessor) {
 
     $this->_mode = $mode;
     $this->_paymentProcessor = $paymentProcessor;
     $this->_processorName = ts('DPS Payment Express');
   }
 
-  /**
-   * 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 = 'test', &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
-    $processorName = $paymentProcessor['name'];
-    if (self::$_singleton[$processorName] === NULL) {
-      self::$_singleton[$processorName] = new CRM_Core_Payment_PaymentExpress($mode, $paymentProcessor);
-    }
-    return self::$_singleton[$processorName];
-  }
-
   /**
    * This function checks to see if we have the right config values
    *
    * @internal param string $mode the mode we are operating in (live or test)
    *
-   * @return string the error message if any
-   * @public
+   * @return string
+   *   the error message if any
    */
-  function checkConfig() {
+  public function checkConfig() {
     $config = CRM_Core_Config::singleton();
 
     $error = array();
@@ -120,7 +100,7 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
    *
    * @throws Exception
    */
-  function setExpressCheckOut(&$params) {
+  public function setExpressCheckOut(&$params) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
@@ -129,7 +109,7 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
    *
    * @throws Exception
    */
-  function getExpressCheckoutDetails($token) {
+  public function getExpressCheckoutDetails($token) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
@@ -138,7 +118,7 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
    *
    * @throws Exception
    */
-  function doExpressCheckout(&$params) {
+  public function doExpressCheckout(&$params) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
@@ -146,26 +126,28 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
    * 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
+   * @param array $params
+   *   Assoc array of input parameters for this transaction.
    *
-   * @return array the result in an nice formatted array (or an error object)
+   * @return array
+   *   the result in an nice formatted array (or an error object)
    * @abstract
    */
-  function doDirectPayment(&$params) {
+  public function doDirectPayment(&$params) {
     CRM_Core_Error::fatal(ts('This function is not implemented'));
   }
 
   /**
    * Main transaction function
    *
-   * @param array $params name value pair of contribution data
+   * @param array $params
+   *   Name value pair of contribution data.
    *
    * @param $component
    *
    * @return void
-   * @access public
    */
-  function doTransferCheckout(&$params, $component) {
+  public function doTransferCheckout(&$params, $component) {
     $component = strtolower($component);
     $config = CRM_Core_Config::singleton();
     if ($component != 'contribute' && $component != 'event') {
@@ -187,19 +169,18 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
       );
     }
 
-
     /*
-         * Build the private data string to pass to DPS, which they will give back to us with the
-         *
-         * transaction result.  We are building this as a comma-separated list so as to avoid long URLs.
-         *
-         * Parameters passed: a=contactID, b=contributionID,c=contributionTypeID,d=invoiceID,e=membershipID,f=participantID,g=eventID
-         */
+     * Build the private data string to pass to DPS, which they will give back to us with the
+     *
+     * transaction result.  We are building this as a comma-separated list so as to avoid long URLs.
+     *
+     * Parameters passed: a=contactID, b=contributionID,c=contributionTypeID,d=invoiceID,e=membershipID,f=participantID,g=eventID
+     */
 
     $privateData = "a={$params['contactID']},b={$params['contributionID']},c={$params['contributionTypeID']},d={$params['invoiceID']}";
 
     if ($component == 'event') {
-    $merchantRef = substr($params['contactID'] . "-" . $params['contributionID'] . " " . substr($params['description'], 27, 20), 0, 24);
+      $merchantRef = substr($params['contactID'] . "-" . $params['contributionID'] . " " . substr($params['description'], 27, 20), 0, 24);
       $privateData .= ",f={$params['participantID']},g={$params['eventID']}";
     }
     elseif ($component == 'contribute') {
@@ -217,7 +198,7 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
       'MerchantReference' => $merchantRef,
       'TxnData1' => $params['qfKey'],
       'TxnData2' => $privateData,
-      'TxnData3' => $component . ",".$this->_paymentProcessor['id'],
+      'TxnData3' => $component . "," . $this->_paymentProcessor['id'],
       'TxnType' => 'Purchase',
       // Leave this empty for now, causes an error with DPS if we populate it
       'TxnId' => '',
@@ -228,9 +209,8 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
     CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $dpsParams);
 
     /*
-         *  determine whether method is pxaccess or pxpay by whether signature (mac key) is defined
-         */
-
+     *  determine whether method is pxaccess or pxpay by whether signature (mac key) is defined
+     */
 
     if (empty($this->_paymentProcessor['signature'])) {
       /*
@@ -269,7 +249,7 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
     }
     else {
       $processortype = "pxaccess";
-      require_once ('PaymentExpress/pxaccess.inc.php');
+      require_once 'PaymentExpress/pxaccess.inc.php';
       // URL
       $PxAccess_Url = $this->_paymentProcessor['url_site'];
       // User ID
@@ -295,4 +275,3 @@ class CRM_Core_Payment_PaymentExpress extends CRM_Core_Payment {
     }
   }
 }
-