The ResponseHandler.php page demonstrates a simple implementation of a page that processes Google Checkout API responses. This page provides core functionality needed to handle Google Checkout's responses to Checkout API requests. It also provides a template for handling Merchant Calculations and Notification API responses.
ResponseHandler.php captures the XML in a Google Checkout API response and then sends that XML to the ProcessXmlData function. That function then analyzes the root tag of the XML response to determine what type of message is contained in the XML. Depending on the type of message contained in the XML, ProcessXmlData will route the XML response to another function in either ResponseHandlerAPIFunctions.php, MerchantCalculationsAPIFunctions.php or NotificationAPIFunctions.php.
To adapt the ResponseHandler.php implementation for use in your site, you will need to modify the functions in the library files to relay the information from Google Checkout API responses to your internal systems that process that data. For partners who are only implementing the Checkout API, this may require little or no effort.
Partners who are also implementing the Merchant Calculations API will need to modify the appropriate functions in MerchantCalculationsAPIFunctions.php to calculate tax, shipping and discounts for an offer and to return a <merchant-calculation-results> response.
Partners who are also implementing the Order Processing and Notification APIs will need to modify the appropriate functions in NotificationAPIFunctions.php to properly handle and store data about order notifications.
// Include Google Checkout PHP Client Library
include ("GlobalAPIFunctions.php");
// Include Response Message Processor
include ("ResponseHandlerAPIFunctions.php");
// Retrieve the XML sent in the HTTP POST request to the ResponseHandler
$xml_response = $HTTP_RAW_POST_DATA;
// 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
LogMessage($GLOBALS["logfile"], $xml_response);
/*
* Call the ProcessXmlData function, which is defined in
* ResponseHandlerAPIFunctions.php. The ProcessXmlData will route
* the XML data to the function that handles the particular type
* of XML message contained in the POST request.
*/
ProcessXmlData($xml_response);
?>
