* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7732 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/gcheckout.php'); require_once(dirname(__FILE__).'/library/googleresponse.php'); require_once(dirname(__FILE__).'/library/googlemerchantcalculations.php'); require_once(dirname(__FILE__).'/library/googleresult.php'); require_once(dirname(__FILE__).'/library/googlerequest.php'); require_once(dirname(__FILE__).'/library/googlecart.php'); $merchant_id = Configuration::get('GCHECKOUT_MERCHANT_ID'); $merchant_key = Configuration::get('GCHECKOUT_MERCHANT_KEY'); $server_type = Configuration::get('GCHECKOUT_MODE'); $Gresponse = new GoogleResponse($merchant_id, $merchant_key); //$Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); //Setup the log file if (Configuration::get('GCHECKOUT_LOGS')) $Gresponse->SetLogFiles('googleerror.log', 'googlemessage.log', L_ALL); // Retrieve the XML sent in the HTTP POST request to the ResponseHandler $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA:file_get_contents("php://input"); if (get_magic_quotes_gpc()) $xml_response = stripslashes($xml_response); list($root, $data) = $Gresponse->GetParsedXML($xml_response); $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key); $status = $Gresponse->HttpAuthentication(); if (!$status) die('authentication failed'); /* Commands to send the various order processing APIs * Send charge order : $Grequest->SendChargeOrder($data[$root] * ['google-order-number']['VALUE'], ); * Send process order : $Grequest->SendProcessOrder($data[$root] * ['google-order-number']['VALUE']); * Send deliver order: $Grequest->SendDeliverOrder($data[$root] * ['google-order-number']['VALUE'], , , * ); * Send archive order: $Grequest->SendArchiveOrder($data[$root] * ['google-order-number']['VALUE']); * */ switch ($root) { case "request-received": break; case "error": break; case "diagnosis": break; case "checkout-redirect": break; case "merchant-calculation-callback": break; case "new-order-notification": // secure_cart[0] => id_cart // secure_cart[1] => secure_key $gcheckout = new GCheckout(); $secure_cart = explode('|', $data[$root]['shopping-cart']['merchant-private-data']['VALUE']); $cart = new Cart((int)$secure_cart[0]); $currency = $gcheckout->getCurrency((int)$cart->id_currency); unset($cart); $orderTotal = (float)($data[$root]['order-total']['VALUE']); $gcheckout->validateOrder((int)$secure_cart[0], Configuration::get('PS_OS_PAYMENT'), (float)$orderTotal, $gcheckout->displayName, NULL, array(), NULL, false, $secure_cart[1]); $Gresponse->SendAck(); break; case "order-state-change-notification": $Gresponse->SendAck(); break; case "charge-amount-notification": $Gresponse->SendAck(); break; case "chargeback-amount-notification": $Gresponse->SendAck(); break; case "refund-amount-notification": $Gresponse->SendAck(); break; case "risk-information-notification": $Gresponse->SendAck(); break; case 'authorization-amount-notification': $Gresponse->SendAck(); break; default: $Gresponse->SendBadRequestStatus("Invalid or not supported Message"); break; } /* In case the XML API contains multiple open tags with the same value, then invoke this function and perform a foreach on the resultant array. This takes care of cases when there is only one unique tag or multiple tags. Examples of this are "anonymous-address", "merchant-code-string" from the merchant-calculations-callback API */ function get_arr_result($child_node) { $result = array(); if (isset($child_node)) { if (is_associative_array($child_node)) { $result[] = $child_node; } else { foreach($child_node as $curr_node){ $result[] = $curr_node; } } } return $result; } /* Returns true if a given variable represents an associative array */ function is_associative_array($var) { return is_array($var) && !is_numeric(implode('', array_keys($var))); }