1

I've integrated Google Checkout with a site, got it working / pretending to charge people fine and also processing the order notifications fine.

However, when I make a request back to Google to get the details of the notification, I receive a 400 response, something about invalid XML.

Thing is, everything for this integration so far has been HTML key value pairs, but all of a sudden I need to parse and deal with XML? I may be missing something, but I can't see where in the docs it tells me exactly what my request should look like.

See here: http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API_Notification_API.html#Receiving_and_Processing_Notifications

It clearly lists an example with name / value pairs, yet apparently I actually need to send them as XML?

Here's where I am right now:

<?php    $header_arr = array("Authorization: Basic ".$authKey,
                    "Content-Type: application/xml; charset=UTF-8",
            "Accept: application/xml; charset=UTF-8");

$request='type=notification-history-request&serial-number='.$serialNumber;

$ch = curl_init($test_URL);     
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_arr);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);

if (curl_errno($ch)) {
  $log.=', error! :'.curl_error($ch);
} else {
  $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  $log.=', status code is: '.$status_code;  //400
}
?>

This returns a 400 each time - yes I realise I'm setting an accept header for XML, this is as the docs specify, here: http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API.html#https_auth_scheme

So, I find myself needing to send the correct request... any ideas?

P.S I've also checked through google's sample code but it's so layered and dependency-ridden that while I've managed to use some of it, the rest is a mystery - so unless you can give me line numbers, the samples aren't much help

totallyNotLizards
  • 8,489
  • 9
  • 51
  • 85

1 Answers1

1

OK turns out this was really simple.

I had the param names wrong - 'type' should have been '_type', like this:

$request='_type=notification-history-request&serial-number='.$serialNumber;

I'm getting the response I need now, panic averted :)

totallyNotLizards
  • 8,489
  • 9
  • 51
  • 85
  • What's the correct process of receiving the notification history? Do you make this request in your callback-url ? (I read something about the order having to be 5 minutes old, so the confusion arises) – Ozzy Jun 03 '12 at 12:20
  • there's a good question. sorry but it's been so long since I implemented this that I don't even remember what site I put it on. as far as I remember, what I was doing was a response to a poke from Google - they send the payment / order notification to your site, then it's up to you to return the request and ask for more data. So that would suggest that when they send you the notification, there *is* data available. Hope that helps – totallyNotLizards Jun 04 '12 at 14:03