Google Checkout API - PHP Basic Digital Goods Library
Written by ina on Sunday, 25 of July , 2010 at 7:57 am
Tags: API, checkout, google, payment, php, virtual goods
When tragic events happen, I have this tendency to go into API-craze. Perusing API’s are like unwrapping a new birthday present and checking out the specs and seeing what it can do - it can be sufficiently fascinating enough to ward off sorrow or tragedy-confusion. For fun, I went ahead and poked at the Google Checkout API.
The PHP Google Checkout sample code is very bulky, far more than I’d need for my virtual goods transactions, so here’s a simplified API - just the basics you’d need for processing your digital goods: Google-checkout-basic-digital-goods
Usage can’t be simpler… The easy-peasy way is to create your $xml post by beginning with xmlTop() and ending with xmlBot(), then concatenate a xmlItem() in between those two, for each item you wish to have. xmlItem() takes the arguments title, description, price (USD), and quantity, respectively.
$xml=xmlTop().xmlItem('Appleberry Crispz','funky applethangs that melt virtually in your mouth!',1,10).xmlItem('Blueberry Blisset','get hacked to virtual oblivion by blueberries in the Carribean!',0.50,5).xmlItem('Cranberry Chickens','chickens that taste like virtual chickens',21,1).xmlItem('dowager dame virtua','virtual dowagers on a stik',1000,5).xmlBot();
curlIt(id,key,$xml,(0 for production | 1 or default for sandbox)) returns the result, which you’d then process using parsedArray(parseReturn($xml)) to get an array with two entries: array(serial number,redirect-url).
For safety, I’d store the serial number into a db with varchar(99), as Google hasn’t published a maxchar cap, at least not according to Jacob Moon (let’s not even think about Twilight - but, zOMG, what a name!).
Redirect your user to the second entry in that array, and they’re ready to buy!
Category: API
- Add this post to
- Del.icio.us -
- Meneame -
- Digg



