Learning Google Checkout and the Notification API

Published on Tuesday, 02 February 2010.

This is geared to the seasoned developer, and it provides only the basics for starting a complex Google Checkout integration. So, let's begin:

Reading Material

The Setup

It has to be done in the sandbox, when everything goes fine, you just switch to production (easy to write). Note: when creating the following accounts you can use a test credit card number like: 4111111111111111, 6011111111111117, or 5555555555554444. First, create a seller account and then create a buyer account. Then make sure to grab the merchant ID and merchant Key from the Integration Section on your Google Checkout dashboard.

The product page

Now, create a “Buy now” button via the Tools section here. Important note: you can create your own “Buy Now” buttons programmatically via the Checkout API. Then paste the code in your product page. Sample product page.

The API callback Page

Set the URL for the API callback in https://sandbox.google.com/checkout/sell/settings?section=Integration. On the same page, in the Advanced Settings section, do not set the option “Require notification acknowledgments to specify the serial number of the notification” (not supported for the purposes of this mini tutorial).

Create a webpage to receive the Notifications. For example, to quickly test if it is working:

<?php
$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);
}

mail('mail@example.com', 'GC Callback ' . date('d/m/Y H:i:s', time()), 
     'AHA!' . "\n\n" . $xml_response . "\n\n" . print_r($_SERVER, 1));

header('HTTP/1.0 200 OK');
exit;

That's it

Hopefully, this was a brief mini-tutorial but productive in giving you some hints or quick steps to move forward with your custom integration.