/** * 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/googlemerchantcalculations.php'; require_once 'Google/library/googleresult.php'; require_once 'Google/library/xml-processing/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); } require_once 'CRM/Utils/System.php'; $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 $xmlParser = new XmlParser($xml_response); $root = $xmlParser->GetRoot(); $data = $xmlParser->GetData(); $orderNo = $data[$root]['google-order-number']['VALUE']; // lets retrieve the private-data $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE']; $privateData = $privateData ? self::stringToArray($privateData) : ''; list($mode, $module, $paymentProcessorID) = self::getContext($xml_response, $privateData, $orderNo, $root); $mode = $mode ? 'test' : 'live'; require_once 'CRM/Financial/BAO/PaymentProcessor.php'; $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode); $ipn =& self::singleton($mode, $module, $paymentProcessor); // Create new response object $merchant_id = $paymentProcessor['user_name']; $merchant_key = $paymentProcessor['password']; $server_type = $mode == 'test' ? "sandbox" : ''; $response = new GoogleResponse($merchant_id, $merchant_key, $xml_response, $server_type); 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(); $ipn->newOrderNotify($data[$root], $privateData, $module); break; case "order-state-change-notification": $response->SendAck(); $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': $amount = $ipn->getAmount($orderNo); if ($amount) { $response->SendChargeOrder($data[$root]['google-order-number']['VALUE'], $amount, $message_log); $response->SendProcessOrder($data[$root]['google-order-number']['VALUE'], $message_log); } break; case 'CHARGED': case 'PAYMENT_DECLINED': case 'CANCELLED': $ipn->orderStateChange($new_financial_state, $data[$root], $module); break; case 'REVIEWING': case 'CHARGING': case 'CANCELLED_BY_GOOGLE': break; default: break; } case "charge-amount-notification": case "chargeback-amount-notification": case "refund-amount-notification": case "risk-information-notification": $response->SendAck(); break; default: break; } }