Making a Better PHP Library for Google Checkout

Google Checkout LogoLong before Google had produced their own PHP example code for Google Checkout, I had the need to create my own. It was a library based upon the idea of keeping e-commerce online simple. My goal was to make it possible to implement a server and to persist transactional and order state information in a database with very little code. I would like to think I have succeeded. Take for example, the following code sample:


class ExampleGoogleCheckoutServer extends MySQLGoogleCheckoutServer {
  function doNewOrderNotification($request,$response) {
    $code = $request->shoppingCart->privateData['discountCode'];
    if ($code) {
      $discount = Discount::findByCode($code);
  function doOrderStateChangeNotification($request,$response) {
    if ($request->financialState() == "CHARGED") {
      // do something

Then in a separate file, we'll call it server.php, you would need:

$server = new MySQLGoogleCheckoutServer();
print $server->handlePost();

And that's all you have to do to create a simple server capable of recording a new purchase in your system and then keeping the state of that purchase up to date. The library offers a number of other capabilities as well depending upon your unique purchasing workflow and policies. From this server you can also issue commands to Google, to refund, cancel or archive an order for example.

I am continuing my work to document the library more completely, and to provide a more robust set of examples. In the meantime, I thought others might find this library useful and might also want to help me in its testing and development. The library is available for free under an open source license (BSD). Download "My PHP Google Checkout" and learn more by visiting its project homepage.

If you have questions or need specific documentation please let me know. I will use this feedback to help me prioritize what to work on next.

Recommended Entries


thank you for sharing this information.

hi thanks for your aerticle. where is MySQLGoogleCheckoutServer.php ? my site is:

Leave a comment

what will you say?

Recent Comments