Wednesday, November 7, 2007

Google Checkout API - phpmycheckout

I'm currently in the process of implementing the Google checkout system. I could just take the easy route and use the standard HTML button and be on my way. There are 2 ways to use the HTML button version and both are pretty simple. The first one is just simple form with hidden vars describing your product, qty and price. The second way is a little bit more complex. I use PHP so here a sample of the code I used to throw it together. The sample below uses the phpgcheckout classes from I simply copied the files from phpgcheckout up to the server and included the config.php file.

$key = 'Wpkdo4dlsorlf03l94kd';
$merchant_id = '1180294430430239';
$cart = new gCart($merchant_id,$key);
$cart->addItem('My Product title', 'My Product description, '1', '12.99');
$xml = $cart->getCart();
$hmac = CalcHmacSha1($xml,$key);
$cartxml = base64_encode($xml);

<form method="POST"
<?php echo $merchant_id; ?>/checkoutForm">
<input type="hidden" name="cart"
value="<?php echo $cartxml; ?>">
<input type="hidden" name="signature"
value="<?php echo $hmac; ?>">
<input type="image" name="Google Checkout"
alt="Fast checkout through Google"
<?php echo $merchant_id; ?>
&w=180&h=46&style=white&variant=text&loc=en_US" height="46"
width="180"> </form>

As you can see, this is just an excerpt of the cart I built in php (php5) using some of phpgcheckout's code. This isn't that difficult to do.. but there's one problem, I don't get anything back from google to tell me the order processed successfully. My current project requires I create a user account to access a training program after the card is charged. Supposedly this can be done through the google checkout API and I think I'm about half way there. But to be honest, Google's documentation SUCKS and they don't have a full set of sample code for php5. You would think Google would be a step up on the game in this area...?