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:

<?php
require_once("MySQLGoogleCheckoutServer.php");
require_once("Discount.php");

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

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

require_once("lib/checkout.conf");
require_once("lib/MySQLGoogleCheckoutServer.php");
connect_to_db();
$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.

Related Entries

1 Comment

thank you for sharing this information.

Leave a comment



Recently Elsewhere

Recent Entries

  • My holiday reading

    Byrne, son of the Great Thomas the Learnéd from the land of the Swamp known as Louisiana and Lord of the Reeses, decedents of...

  • Will someone please pass me the hydrospanner?

    Thanks to my friend and brother in-law Erik who always manages to send me the [best](http://www.majordojo.com/2007/12/darth-vader-video-humor-for-the-day.php) [Star Wars](http://www.majordojo.com/2007/10/darth-vader-in-the-death-star-cafeteria.php) links in the world. This time he...

  • One of five features Perl 5 needs right now: mod_perlite

    A recent article written by chromatic in which he identifies mod\_perlite as of the [top 5 features Perl 5 needs right now](http://broadcast.oreilly.com/2008/12/five-features-perl-5-needs-now.html) has motivated me...

  • Thank you Trader Joe's

    Thankfully, I can only bear to eat one of these in any one sitting. Do you have a favorite Holiday treat either homemade or...

  • The Ultimate Guide to Installing Movable Type Plugins

    Without a doubt the most common support request I receive from users of [my many Movable Type plugins](/projects/) is around installation. If you are having...