Deprecated: Assigning the return value of new by reference is deprecated in /home/ina/public_html/blog/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /home/ina/public_html/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/ina/public_html/blog/wp-includes/theme.php on line 540
Blog by Ina Centaur » google

 

Google Checkout API - PHP Basic Digital Goods Library

Written by ina on Sunday, 25 of July , 2010 at 7:57 am
Tags: , , , , ,

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

flowchart of a super simple google checkout library for 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

Who is Ina Centaur?

A 25-year old American polymath of Taiwanese ancestry pretending to be old and Caucasian in Second Life. Semi-retired independent scholar also dabbling as an independent artist in new media, particularly theatre and the humanities—notably Shakespeare. Programmer, playwright and novelist. Formal academic background in http://portfolio.inacentaur.com/ina/scientist, philosophy, and bioengineering.

This is largely a personal blog which isn't always up-to-date. There's no one definitive way to stalk me ;-).