/**  
  * singleton function used to manage this object  
  *  
  * @param string $mode the mode of operation: live or test
  *  
  * @return object  
  * @static  
  */
 static function &singleton($mode, $component, &$paymentProcessor)
 {
     if (self::$_singleton === null) {
         self::$_singleton = new CRM_Core_Payment_GoogleIPN($mode, $paymentProcessor);
     }
     return self::$_singleton;
 }
 /**
  * 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.
  *
  */
 static function main($xml_response)
 {
     require_once 'Google/library/googleresponse.php';
     require_once 'Google/library/googlerequest.php';
     require_once 'Google/library/googlemerchantcalculations.php';
     require_once 'Google/library/googleresult.php';
     require_once 'Google/library/xml-processing/gc_xmlparser.php';
     $config = CRM_Core_Config::singleton();
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     $headers = CRM_Utils_System::getAllHeaders();
     if (GOOGLE_DEBUG_PP) {
         CRM_Core_Error::debug_var('RESPONSE', $xml_response, TRUE, TRUE, 'Google');
     }
     // Retrieve the root and data from the xml response
     $response = new GoogleResponse();
     list($root, $data) = $response->GetParsedXML($xml_response);
     // 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'];
     }
     if (empty($privateData) && array_key_exists('order-summary', $data[$root]) && 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'];
     // a dummy object to call get context and a parent function inside it.
     $ipn = new CRM_Core_Payment_GoogleIPN('live', $dummyProcessor);
     list($mode, $module, $paymentProcessorID) = $ipn->getContext($privateData, $orderNo, $root, $response, $serial);
     $mode = $mode ? 'test' : 'live';
     $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode);
     $merchant_id = $paymentProcessor['user_name'];
     $merchant_key = $paymentProcessor['password'];
     $response->SetMerchantAuthentication($merchant_id, $merchant_key);
     $server_type = $mode == 'test' ? 'sandbox' : 'production';
     $request = new GoogleRequest($merchant_id, $merchant_key, $server_type);
     $ipn = self::singleton($mode, $module, $paymentProcessor);
     if (GOOGLE_DEBUG_PP) {
         CRM_Core_Error::debug_var('RESPONSE-ROOT', $response->root, TRUE, TRUE, 'Google');
     }
     //Check status and take appropriate action
     $status = $response->HttpAuthentication($headers);
     switch ($root) {
         case "request-received":
         case "error":
         case "diagnosis":
         case "checkout-redirect":
         case "merchant-calculation-callback":
             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'];
             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 'REVIEWING':
                 case 'CHARGING':
                     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":
         case "refund-amount-notification":
         case "risk-information-notification":
             $response->SendAck($serial);
             break;
         default:
             break;
     }
 }
Beispiel #3
0
|                                                                    |
| CiviCRM is free software; you can copy, modify, and distribute it  |
| under the terms of the GNU Affero General Public License           |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
|                                                                    |
| CiviCRM is distributed in the hope that it will be useful, but     |
| WITHOUT ANY WARRANTY; without even the implied warranty of         |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
| See the GNU Affero General Public License for more details.        |
|                                                                    |
| You should have received a copy of the GNU Affero General Public   |
| License and the CiviCRM Licensing Exception along                  |
| with this program; if not, contact CiviCRM LLC                     |
| at info[AT]civicrm[DOT]org. If you have questions about the        |
| GNU Affero General Public License or the licensing of CiviCRM,     |
| see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+--------------------------------------------------------------------+
*/
/**
 * @package CRM
 * @copyright CiviCRM LLC (c) 2004-2015
 * $Id$
 */
session_start();
require_once '../civicrm.config.php';
$config = CRM_Core_Config::singleton();
$log = new CRM_Utils_SystemLogger();
$log->alert('payment_notification processor_name=Google_Checkout', $_REQUEST);
$rawPostData = file_get_contents('php://input');
CRM_Core_Payment_GoogleIPN::main($rawPostData);