Search code examples
phppostgoogle-checkout

reply to a server-to-server request?


i am trying to setup google checkout on my site, now at one point, google sends me a serial number, to which i am supposed to reply after posting the 'OK' header, ( some details here http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Notification_API.html#responding_to_notifications )

The problem is that, idk how to reply, i am trying this:

{
header('HTTP/1.0 200 OK');
$post = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
$post = substr($post, 14);
$pr = @'<?xml version="1.0" encoding="UTF-8"?>
       <notification-acknowledgment xmlns="http://checkout.google.com/schema/2" serial-number="' . $post . '" />';
        echo $pr;

        if (isset($post)) {

         //Something with the DB..
 }

After receiving this acknowledgement recieved notification google will stop posting me the request for the same serial numebr, but i keep on getting the requests(know this from db), implying that google is not able to receive my notification acknowledgement.

Where do i err>'?


Solution

  • I did some more search and some hit-and-trials, and the result is this :

    To make a server-to-server reply you just echo your reply. And if you need to pass any header, pass them before you echo anything,

    Note: if you are sending reply in xml, like in case of google checkout, beware of spaces and line returns in your echo text.

    $pr = "<xyz>
    123
    </xyz>";
    

    might not be same as $pr="<xyz>123</xyz>";