INFRA-132 - CRM/Core - phpcbf
[civicrm-core.git] / CRM / Core / Payment / GoogleIPN.php
index 4dd6ed4241d3ce9f5fe951d0eff7ef1dd64757eb..6dbd487545aca4149b4a37c2068ba09b41fc1806 100644 (file)
@@ -51,21 +51,21 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
   static private $_singleton = NULL;
 
   /**
-   * mode of operation: live or test
+   * Mode of operation: live or test
    *
    * @var object
    */
   protected $_mode = NULL;
 
   /**
-   * @param $name
+   * @param string $name
    * @param $type
    * @param $object
    * @param bool $abort
    *
    * @return mixed
    */
-  static function retrieve($name, $type, $object, $abort = TRUE) {
+  public static function retrieve($name, $type, $object, $abort = TRUE) {
     $value = CRM_Utils_Array::value($name, $object);
     if ($abort && $value === NULL) {
       CRM_Core_Error::debug_log_message("Could not find an entry for $name");
@@ -87,13 +87,14 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
   /**
    * 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_GoogleIPN
    */
-  function __construct($mode, &$paymentProcessor) {
+  public function __construct($mode, &$paymentProcessor) {
     parent::__construct();
 
     $this->_mode = $mode;
@@ -103,14 +104,16 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
   /**
    * The function gets called when a new order takes place.
    *
-   * @param xml $dataRoot response send by google in xml format
-   * @param array $privateData contains the name value pair of <merchant-private-data>
+   * @param xml $dataRoot
+   *   Response send by google in xml format.
+   * @param array $privateData
+   *   Contains the name value pair of <merchant-private-data>.
    *
    * @param $component
    *
    * @return void
    */
-  function newOrderNotify($dataRoot, $privateData, $component) {
+  public function newOrderNotify($dataRoot, $privateData, $component) {
     $ids = $input = $params = array();
 
     $input['component'] = strtolower($component);
@@ -234,7 +237,6 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
       }
     }
 
-    // CRM_Core_Error::debug_var( 'c', $contribution );
     $contribution->save();
     $transaction->commit();
 
@@ -244,15 +246,17 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
   /**
    * The function gets called when the state(CHARGED, CANCELLED..) changes for an order
    *
-   * @param string $status status of the transaction send by google
+   * @param string $status
+   *   Status of the transaction send by google.
    * @param $dataRoot
-   * @param array $privateData contains the name value pair of <merchant-private-data>
+   * @param array $privateData
+   *   Contains the name value pair of <merchant-private-data>.
    *
    * @param $component
    *
    * @return void
    */
-  function orderStateChange($status, $dataRoot, $privateData, $component) {
+  public function orderStateChange($status, $dataRoot, $privateData, $component) {
     $input = $objects = $ids = array();
     $input['component'] = strtolower($component);
 
@@ -294,9 +298,9 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
       $ids['related_contact'] = NULL;
       $ids['onbehalf_dupe_alert'] = NULL;
       if ($contribution->trxn_id) {
-      list($ids['membership'], $ids['related_contact'], $ids['onbehalf_dupe_alert']) = explode(CRM_Core_DAO::VALUE_SEPARATOR,
+        list($ids['membership'], $ids['related_contact'], $ids['onbehalf_dupe_alert']) = explode(CRM_Core_DAO::VALUE_SEPARATOR,
         $contribution->trxn_id
-      );
+        );
       }
       foreach (array(
         'membership', 'related_contact', 'onbehalf_dupe_alert') as $fld) {
@@ -317,7 +321,6 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
 
     $transaction = new CRM_Core_Transaction();
 
-    // CRM_Core_Error::debug_var( 'c', $contribution );
     if ($status == 'PAYMENT_DECLINED' ||
       $status == 'CANCELLED_BY_GOOGLE' ||
       $status == 'CANCELLED'
@@ -345,7 +348,7 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
    * @param $ids
    * @param $objects
    */
-  function completeRecur($input, $ids, $objects) {
+  public function completeRecur($input, $ids, $objects) {
     if ($ids['contributionRecur']) {
       $recur               = &$objects['contributionRecur'];
       $contributionCount   = CRM_Core_DAO::singleValueQuery("
@@ -394,9 +397,10 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
   }
 
   /**
-   * 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 $component
    * @param $paymentProcessor
@@ -404,7 +408,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
    * @return object
    * @static
    */
-  static function &singleton($mode, $component, &$paymentProcessor) {
+  public static function &singleton($mode, $component, &$paymentProcessor) {
     if (self::$_singleton === NULL) {
       self::$_singleton = new CRM_Core_Payment_GoogleIPN($mode, $paymentProcessor);
     }
@@ -414,12 +418,12 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
   /**
    * The function retrieves the amount the contribution is for, based on the order-no google sends
    *
-   * @param int $orderNo <order-total> send by google
+   * @param int $orderNo
+   *   <order-total> send by google.
    *
    * @return amount
-   * @access public
    */
-  function getAmount($orderNo) {
+  public function getAmount($orderNo) {
     $contribution = new CRM_Contribute_DAO_Contribution();
     $contribution->invoice_id = $orderNo;
     if (!$contribution->find(TRUE)) {
@@ -433,9 +437,12 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
   /**
    * The function returns the component(Event/Contribute..), given the google-order-no and merchant-private-data
    *
-   * @param array $privateData contains the name value pair of <merchant-private-data>
-   * @param int $orderNo <order-total> send by google
-   * @param string $root root of xml-response
+   * @param array $privateData
+   *   Contains the name value pair of <merchant-private-data>.
+   * @param int $orderNo
+   *   <order-total> send by google.
+   * @param string $root
+   *   Root of xml-response.
    *
    * @param $response
    * @param $serial
@@ -443,7 +450,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
    * @return array context of this call (test, module, payment processor id)
    * @static
    */
-  function getContext($privateData, $orderNo, $root, $response, $serial) {
+  public function getContext($privateData, $orderNo, $root, $response, $serial) {
     $contributionID = CRM_Utils_Array::value('contributionID', $privateData);
     $contribution = new CRM_Contribute_DAO_Contribution();
     if ($root == 'new-order-notification') {
@@ -510,7 +517,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
    * a notification or request is sent by the Google Server.
    *
    */
-  static function main($xml_response) {
+  public static function main($xml_response) {
     require_once 'Google/library/googleresponse.php';
     require_once 'Google/library/googlerequest.php';
     require_once 'Google/library/googlemerchantcalculations.php';
@@ -536,7 +543,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
     // lets retrieve the private-data & order-no
     $privateData = NULL;
     if (array_key_exists('shopping-cart', $data[$root])) {
-    $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE'];
+      $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE'];
     }
     if (empty($privateData) && array_key_exists('order-summary', $data[$root])
         && array_key_exists('shopping-cart', $data[$root]['order-summary'])) {
@@ -576,65 +583,65 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
       case "merchant-calculation-callback":
         break;
 
-      case "new-order-notification": {
-          $response->SendAck($serial, FALSE);
-          $ipn->newOrderNotify($data[$root], $privateData, $module);
-          break;
+      case "new-order-notification":{
+        $response->SendAck($serial, FALSE);
+        $ipn->newOrderNotify($data[$root], $privateData, $module);
+        break;
         }
 
-      case "order-state-change-notification": {
-          $response->SendAck($serial, FALSE);
-          $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
-          $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
+      case "order-state-change-notification":{
+        $response->SendAck($serial, FALSE);
+        $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
+        $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
 
-          switch ($new_financial_state) {
-            case 'CHARGEABLE':
-              break;
+        switch ($new_financial_state) {
+          case 'CHARGEABLE':
+            break;
 
-            case 'CHARGED':
-            case 'PAYMENT_DECLINED':
-            case 'CANCELLED':
-            case 'CANCELLED_BY_GOOGLE':
-              $ipn->orderStateChange($new_financial_state, $data[$root], $privateData, $module);
-              break;
+          case 'CHARGED':
+          case 'PAYMENT_DECLINED':
+          case 'CANCELLED':
+          case 'CANCELLED_BY_GOOGLE':
+            $ipn->orderStateChange($new_financial_state, $data[$root], $privateData, $module);
+            break;
 
-            case 'REVIEWING':
-            case 'CHARGING':
-              break;
+          case 'REVIEWING':
+          case 'CHARGING':
+            break;
 
-            default:
-              break;
-          }
-          break;
+          default:
+            break;
+        }
+        break;
         }
 
-      case "authorization-amount-notification": {
-          $response->SendAck($serial, FALSE);
-          $new_financial_state = $data[$root]['order-summary']['financial-order-state']['VALUE'];
-          $new_fulfillment_order = $data[$root]['order-summary']['fulfillment-order-state']['VALUE'];
-
-          switch ($new_financial_state) {
-            case 'CHARGEABLE':
-              // For google-handled subscriptions chargeorder needn't be initiated,
-              // assuming auto-charging is turned on.
-              //$request->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
-              //$request->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
-              break;
-
-            case 'CHARGED':
-            case 'PAYMENT_DECLINED':
-            case 'CANCELLED':
-              break;
-
-            case 'REVIEWING':
-            case 'CHARGING':
-            case 'CANCELLED_BY_GOOGLE':
-              break;
-
-            default:
-              break;
-          }
-          break;
+      case "authorization-amount-notification":{
+        $response->SendAck($serial, FALSE);
+        $new_financial_state = $data[$root]['order-summary']['financial-order-state']['VALUE'];
+        $new_fulfillment_order = $data[$root]['order-summary']['fulfillment-order-state']['VALUE'];
+
+        switch ($new_financial_state) {
+          case 'CHARGEABLE':
+            // For google-handled subscriptions chargeorder needn't be initiated,
+            // assuming auto-charging is turned on.
+            //$request->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
+            //$request->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
+            break;
+
+          case 'CHARGED':
+          case 'PAYMENT_DECLINED':
+          case 'CANCELLED':
+            break;
+
+          case 'REVIEWING':
+          case 'CHARGING':
+          case 'CANCELLED_BY_GOOGLE':
+            break;
+
+          default:
+            break;
+        }
+        break;
         }
 
       case "charge-amount-notification":
@@ -656,7 +663,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
    *
    * @return bool
    */
-  function getInput(&$input, &$ids, $dataRoot) {
+  public function getInput(&$input, &$ids, $dataRoot) {
     if (!$this->getBillingID($ids)) {
       return FALSE;
     }
@@ -675,7 +682,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
 
     foreach ($lookup as $name => $googleName) {
       if (array_key_exists($googleName, $dataRoot['buyer-billing-address'])) {
-      $value = $dataRoot['buyer-billing-address'][$googleName]['VALUE'];
+        $value = $dataRoot['buyer-billing-address'][$googleName]['VALUE'];
       }
       $input[$name] = $value ? $value : NULL;
     }
@@ -686,7 +693,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
    * Converts the comma separated name-value pairs in <merchant-private-data>
    * to an array of name-value pairs.
    */
-  static function stringToArray($str) {
+  public static function stringToArray($str) {
     $vars = $labels = array();
     $labels = explode(',', $str);
     foreach ($labels as $label) {
@@ -696,4 +703,3 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
     return $vars;
   }
 }
-