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

what will you say?


Recently Elsewhere

Recent Entries

  • Say "Hello" to Daisy Amelia Hailey Reese

    In a way I am never to forget, our newest addition, Daisy Amelia Hailey Reese, was brought into the world at 5:16am on June...

  • Meet Melody

    People who know me, know that I love [Movable Type](http://www.majordojo.com/cgi-bin/mt/mt-search.cgi?blog_id=3&tag=movable%20type&limit=20). In fact I have devoted much of the last five years to the product and...

  • MOONSHOT

    On a recent trip to Chicago I stopped by a non-local mega-bookstore to look for a last minute gift for Harper as is required on...

  • Understanding Movable Type Template Sets

    Since releasing the [Hybrid News Theme](http://www.majordojo.com/2009/05/teaser-hybrid-news-theme-for-movable-type.php) I have been contacted by a number of people on the [ProNet mailing list](http://www.sixapart.com/mailman/listinfo/pronet/) asking me to shed some...

  • Obama's Speech to the Muslim World

    I implore everyone to watch Obama's speech. His entire speech is profound. It is moving in how it acknowledges and embraces our past, but...

badge-iheartmelody-white.png