INFRA-132 - Batch #8
[civicrm-core.git] / CRM / Core / Payment / GoogleIPN.php
index c3e3b532b84a1022e9eaa47a85a06e3c671c8dd1..16c5d6633cf5e3eafb738dec24a35ddf4dd1b29b 100644 (file)
@@ -33,7 +33,6 @@
   */
 
 
-
 define('GOOGLE_DEBUG_PP', 0);
 
 /**
@@ -46,7 +45,6 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
    * pattern and cache the instance in this variable
    *
    * @var object
-   * @static
    */
   static private $_singleton = NULL;
 
@@ -87,7 +85,8 @@ 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
    *
@@ -103,8 +102,10 @@ 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
    *
@@ -120,9 +121,9 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
 
     $ids['contributionRecur'] = $ids['contributionPage'] = NULL;
     if ($input['component'] == "event") {
-      $ids['event']       = self::retrieve('eventID', 'Integer', $privateData, TRUE);
+      $ids['event'] = self::retrieve('eventID', 'Integer', $privateData, TRUE);
       $ids['participant'] = self::retrieve('participantID', 'Integer', $privateData, TRUE);
-      $ids['membership']  = NULL;
+      $ids['membership'] = NULL;
     }
     else {
       $ids['membership'] = self::retrieve('membershipID', 'Integer', $privateData, FALSE);
@@ -172,7 +173,7 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
           // create a contribution and then get it processed
           $contribution = new CRM_Contribute_DAO_Contribution();
           $contribution->contact_id = $ids['contact'];
-          $contribution->financial_type_id  = $objects['contributionType']->id;
+          $contribution->financial_type_id = $objects['contributionType']->id;
           $contribution->contribution_page_id = $objects['contribution']->contribution_page_id;
           $contribution->contribution_recur_id = $ids['contributionRecur'];
           $contribution->receive_date = date('YmdHis');
@@ -243,9 +244,11 @@ 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
    *
@@ -293,12 +296,15 @@ 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,
-        $contribution->trxn_id
-      );
+        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) {
+                 'membership',
+                 'related_contact',
+                 'onbehalf_dupe_alert',
+               ) as $fld) {
         if (!is_numeric($ids[$fld])) {
           unset($ids[$fld]);
         }
@@ -323,11 +329,11 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
       return $this->failed($objects, $transaction);
     }
 
-    $input['amount']     = $contribution->total_amount;
+    $input['amount'] = $contribution->total_amount;
     $input['fee_amount'] = NULL;
     $input['net_amount'] = NULL;
-    $input['trxn_id']    = $ids['contributionRecur'] ? $serial : $dataRoot['google-order-number']['VALUE'];
-    $input['is_test']    = $contribution->is_test;
+    $input['trxn_id'] = $ids['contributionRecur'] ? $serial : $dataRoot['google-order-number']['VALUE'];
+    $input['is_test'] = $contribution->is_test;
 
     $recur = NULL;
     if ($ids['contributionRecur']) {
@@ -345,8 +351,8 @@ class CRM_Core_Payment_GoogleIPN extends CRM_Core_Payment_BaseIPN {
    */
   public function completeRecur($input, $ids, $objects) {
     if ($ids['contributionRecur']) {
-      $recur               = &$objects['contributionRecur'];
-      $contributionCount   = CRM_Core_DAO::singleValueQuery("
+      $recur = &$objects['contributionRecur'];
+      $contributionCount = CRM_Core_DAO::singleValueQuery("
 SELECT count(*)
 FROM   civicrm_contribution
 WHERE  contribution_recur_id = {$ids['contributionRecur']}
@@ -392,15 +398,17 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
   }
 
   /**
+   * @deprecated
+   * Payment processor singletons removed - this is an IPN so left but probably can go
    * 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
    *
    * @return object
-   * @static
    */
   public static function &singleton($mode, $component, &$paymentProcessor) {
     if (self::$_singleton === NULL) {
@@ -412,7 +420,8 @@ 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
    */
@@ -430,15 +439,18 @@ 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
    * @internal param \xml $xml_response response send by google in xml format
-   * @return array context of this call (test, module, payment processor id)
-   * @static
+   * @return array
+   *   context of this call (test, module, payment processor id)
    */
   public function getContext($privateData, $orderNo, $root, $response, $serial) {
     $contributionID = CRM_Utils_Array::value('contributionID', $privateData);
@@ -479,8 +491,7 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
         $ids['event'] = $privateData['eventID'];
       }
       else {
-        list($ids['event'], $ids['participant']) =
-          explode(CRM_Core_DAO::VALUE_SEPARATOR, $contribution->trxn_id);
+        list($ids['event'], $ids['participant']) = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contribution->trxn_id);
       }
     }
 
@@ -505,7 +516,6 @@ WHERE  contribution_recur_id = {$ids['contributionRecur']}
   /**
    * This method is handles the response that will be invoked (from extern/googleNotify) every time
    * a notification or request is sent by the Google Server.
-   *
    */
   public static function main($xml_response) {
     require_once 'Google/library/googleresponse.php';
@@ -533,15 +543,16 @@ 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'])) {
+      && array_key_exists('shopping-cart', $data[$root]['order-summary'])
+    ) {
       $privateData = $data[$root]['order-summary']['shopping-cart']['merchant-private-data']['VALUE'];
     }
     $privateData = $privateData ? self::stringToArray($privateData) : '';
-    $orderNo     = $data[$root]['google-order-number']['VALUE'];
-    $serial      = $data[$root]['serial-number'];
+    $orderNo = $data[$root]['google-order-number']['VALUE'];
+    $serial = $data[$root]['serial-number'];
 
     // a dummy object to call get context and a parent function inside it.
     $ipn = new CRM_Core_Payment_GoogleIPN('live', $dummyProcessor);
@@ -573,66 +584,63 @@ 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":
       case "chargeback-amount-notification":
@@ -672,7 +680,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;
     }