<?php

require_once 'classes/PluginCallback.php';
require_once 'modules/billing/models/class.gateway.plugin.php';
require_once 'plugins/gateways/googlecheckout/googlefunctions.php';

class PluginGooglecheckoutCallback extends PluginCallback
{
    
    function processCallback()
    {
        if(isset($_COOKIE['returnToSignup'])){
    		if($_COOKIE['returnToSignup'] == 1){
    			NE_Lib::redirectPage('signup.php?step=6&pass=1');
    		}
    		if($_COOKIE['returnToSignup'] == 0){
    			NE_Lib::redirectPage('index.php');
    		}
    		exit;
        }
        
        $this->logger->log(4,'Google Checkout callback invoked');
        
        // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
        $fd = fopen('php://input', 'r');
        $xml_response = '';
        while (!feof($fd)) {
            $xml_response .= fread($fd, 1024);
        }
        fclose($fd);
        
        // Get rid of PHP's magical escaping of quotes 
        if (get_magic_quotes_gpc()) {
            $xml_response = stripslashes($xml_response);
        }
        
        // Log the XML received in the HTTP POST request
        $this->logger->log(4, "XML response: ".print_r($xml_response, true));
        
        // EWW
        $GLOBALS['logger'] =& $this->logger;
        $GLOBALS['db'] =& $this->db;
        $GLOBALS['user'] =& $this->user;
        $GLOBALS['customer'] =& $this->customer;
        
        ProcessXmlData($xml_response);
    }
    
}

?>
