|
|
Documentation
PHP Sample Code for Google Checkout
File structure and function
There are two folders and a log file in the top level directory of google-checkout-php-sample.
1. "demo" directory - This contains two files cartdemo.php and responsehandlerdemo.php
- cartdemo.php
- This file demonstrates the steps required to add items, shipping, taxes and merchant-calculations to the cart before it is posted to the Checkout server. There are three use case functions defined with different settings for shipping and taxes along with different button usages.
- responsehandler.php
- This file will be used to handle the notifications, callbacks and order processing steps. The path for this file must be specified in the merchant's API callback URL in Settings->Integration of the merchant's seller account. This file can be used as is and modified by the merchant as per their business workflow details. Some of the intial steps performed in this file include collecting the XML response, request that has been received and get a parsed result in a PHP associative array for easy accesibility (For details of parse output refer xmlparser.php which has an example of how an XML maps to the object). Order processing can be done using the SendProcessOrder(..) type of methods provided in googleresponse.php. Some sample order processing command invocations have been provided as comments in the code
2. "library" directory - This contains the classes defined to describe the API structure so as to easily define and add XML entries by defining objects of these classes.
- googlecart.php
- This is the main class which must be instantiated to post a cart. It requires a merchant ID and key to be set and there is an option to specify which server is to be used for the transactions (Sandbox or Production). It also has methods to add items, shipping options, tax options and merchant-calculation details.
- googleitem.php
- This class is instantiated for every item to be added to the cart. It requires the item name, description, price and quantity to be specified.
- googleshipping.php
- This class is instantiated for every shipping option that is to be added to the cart. It requires the shipping name type an price to be specified. Other methods allow specification of the shipping restrictions.
- googletaxrule.php
- This class is used to define all tax rules for the tax tables. These may be rules for default or alternate tax tables. Methods have been provided to add states and zip patterns for the tax rules.
- googletaxtable.php
- This class is used to aggregate all the defined tax rules to define a tax table. This may be a default or alternate tax table identified by the "type" value.
- googleresponse.php
- An instance of this class is created in the responsehandlerdemo.php. This again requires the merchant id and merchant key to be specified. There are methods provided to send all the different order processing commands. All notifications are parsed and the merchant can take required action when a particular notification is received.
- googleresult.php
- This class is used for merchant-calculations and is invoked for each result in the merchant-calculations-result sent from the merchant in response to a callback.
- googlemerchantcalculations.php
- In order to process merchant calculations, an instance of this class is created. It is used to aggregate merchant results and respond with the XML response for the callback.
- "xml-processing" directory
- xmlbuilder.php
- This class generates XML and consists of "push" and "pop" methods to add open and close tags respectively. This is used internally by the library classes to generate XML file for posting carts.
- xmlparser.php
- This class parses XML documents using the SAX parser and is compatible with PHP v4 and 5. It converts them to DOM form returning the XML data in a PHP associative array. This is used internally by the library classes to parse XML requests and responses that are received from the Checkout server.
3. googlemessage.log: The log file records all the notification and order processing commands that are sent and received and can be useful information for debugging purposes.
If you're looking for the documentation of the earlier version of the PHP sample code, visit http://code.google.com/apis/checkout/samples/Google_Checkout_Sample_Code_PHP.html
Sign in to add a comment

A nice feature in this documentation would be a quick reference about what has to be modified to get the demo code working. For example, I got the standard checkout request to work after I put in my sandbox ID & key, but I'm having no luck with server 2 server, so a reference to which areas need editing in the code provided would save this novice a lot of time.
someone please explain what server 2 server is all about
server 2 server: the unofficial term for 2 web servers communicating between each other. IE your web site server and the server at Google Checkout.
If you have problems then check with your web host that communication to google's urls is possible at file_open level (or curl comms level) as most web hosts turn off this commuication by default. Strange but true but they will sort it for you!
:)
server 2 server: the unofficial term for 2 web servers communicating between each other. IE your web site server and the server at Google Checkout.
If you have problems then check with your web host that communication to google's urls is possible at file_open level (or curl comms level) as most web hosts turn off this commuication by default. Strange but true but they will sort it for you!
:)
server 2 server: the unofficial term for 2 web servers communicating between each other. IE your web site server and the server at Google Checkout.
If you have problems then check with your web host that communication to google's urls is possible at file_open level (or curl comms level) as most web hosts turn off this commuication by default. Strange but true but they will sort it for you!
Its really strange, Google has implemented Google checkout but lots of developers facing problem to integrate it successfully with response handler. I don't know why its not working fine for me as well. Can anyone pls explain what needs to do for taking response from Google server...?
In my Integration section i gave the callback url but still its showing Authentication problem.. what does this mean!!!!
Prashant Agarwal http://prashcom.blogspot.com
Its really strange, Google has implemented Google checkout but lots of developers facing problem to integrate it successfully with response handler. I don't know why its not working fine for me as well. Can anyone pls explain what needs to do for taking response from Google server...?
In my Integration section i gave the callback url but still its showing Authentication problem.. what does this mean!!!!
Prashant Agarwal http://prashcom.blogspot.com
ah ha... its google i can't belive this???
i tried to do one post but because i got server error so i submitted too many times and when i refreshed the page.. its coming too many times...
hey Google Guys!!! what are u doing...? If u don't have time to manage Google Checkout then give it to me.. i will do for u ;)
added carrier calculated shipping to this code if anyone wants it post a message.
I would like to second the request for a guide on what needs to be modified to get this going.
After spending a couple of days working with the code, I'm not very far in my integration process. I like that the documentation says responsehandler.php puts "a parsed result in a PHP associative array for easy accesibility." Um. What's the array?
You know, as a novice integrating API's into PHP, it would be nice if the had a sample.php page for download with one example item, laid out in a table with the an 'Add to cart' link, a 'Qty' box or a 'Qty' drop down box so they could add more than one at a time. With the proceed to checkout button at the bottom so that we had a working template to build from and try adding adaptations. Just a thought.
This is soooo much cleaner than PP... thanks google.
is there any documentation for novive php developers
sherif
Hi, Sorry to be sooo dumd :( but I know almost nothing about PHP ...... and I am trying to integarted google shopping with osc shopping cart developed in PHP.
I saw all documents .... can someone tell me 'WHERE' to upload which php or xml file .... I mean which folder to use for what file.
Thanx.
Slight problem, I'm trying to test this out, but it keeps asking for a Username and Password???
Hi
Is there a way to generate refund notifications for all past transactions?
is there any way to integrate the google checkout procedure within one site?
i used google check out with level 2 for my client in php.the code work fine in other servers but on the client server it give file save as option when google check out button is clicked.My client server install php 5 and Server API are CGI.cURL etc are also
I saw in the documentation that there was a new version out uploaded on feb 13th reffered to as 1.25c which was supposed to have version: 1235. I downloaded it and the zip made a folder called 1.25b, which had @version: 1234 2007-09-25 in it. Please fix and notify me when changes are made.
I'm reading these comments trying to work whether it is worth trying to get this working on my website. Two things are obvious:-
1. THERE MUST BE A SAMPLE APPLICATION
2. ..................................GOOGLE AREN'T LISTENING!!
3. THERE MUST BE A SAMPLE APPLICATION
4. ..................................GOOGLE AREN'T LISTENING!!
5. THERE MUST BE A SAMPLE APPLICATION
6. I'm wasting my time here because ..............GOOGLE AREN'T LISTENING!!!
WHY WOULD YOU TRY SOMETHING IF YOU DONT KNOW WHAT YOU ARE DOING. GOOGLE ARE NOT IN THE WRONG FOR YOUR MISFORTUNES.
I'm an exprienced PHP developer with years of exprience .... took me 10mins. THE API is there READ IT for X-sake. IT'S NOT SIMPLE BECAUSE IT'S BEEN DEVELOPED CORRECTLY LIKE ANY OTHER API OUT THERE.
YOU ALL WANT KNOWLEDGE FOR FREE AND THE SAD THING IS THAT YOU DON'T UNDERSTAND WHAT YOU ARE DOING....WHY SHOULD GOOGLE LISTEN WHEN THERE IS TONNES OF INFO AND DOCUMENTATION. I'VE MADE AN OBJECT OF THE INFO THAT DOES IT ALL AND IT WAS SO SO SO EASY....ALL YOU HAVE TO DO IS READ...THAT'S ALL THAT'S REQUIRED.
EAMON STRAUGHN
is there any things knows about ipn just like paypal? does google checkout have this?
Getting started to add GoogleCheckout? to your own cart, with PHP... (you will need to get a merchant ID and key before you can get serious). If you are trying to add a 'submit cart' button (ie you already have a cart program and you want to pass the order through to GoogleCheckout? for payment - as you probably do to PayPal? already), look at the cartdemo.php program. Basically you have to create a 'google-cart' object, then for each item you have to create a 'google-item' object and add the google-item to the google cart.There is then a few more bits to do (tax, shipping, etc) and then you create a checkout button.
How does this thing work?
This is a lot of code from google which makes OBJECTS into XML and sends it with CURL. The Google API works with XML (though there is another version which uses &var=value. http talk. (and another with Very Easy HTML form)
The main page (i use) (DIGITAL CART) uses under-functions and objects and classes. Mostly, anything called will require and initiate functions in the level below - for example, DIGITALCART requires GOOGLECART which requires GOOGLEREQUEST. GOOGLECART will use objects and functions in GOOGLEREQUEST on behalf of DIGITAL CART.
There are quite a few "turned off" functionalities in this - so look through it before you make anything... !
each (main) page has at the top - google merchant key, sandbox (or not) and currency. Which need to be set correctly.
You'll need CURL installed and have the google-response viewable from the internet.
WHAT DID I CHANGE? to make it work? (it's a very complex system - it took me 2-3 days to read the help and the code... however it is Very Flexible (much more than PayPal?).
- put merchant ID in top of main pages, (in demo) - to get ResponceHandler? to work you have to enter its address in merchant account (tools)
i used digital cart - which didn't require tax or shipping things, but you still have to enter product details. (it only uses item_1 and item_2 for display - after each they are "pushed" into the object.
>> does anybody else think that Functions and Objects as 'easy to understand' code slightly back-fires when you have levels of functions and functions and objects - making it much more complicated to follow a process-trail. (than straight 'no frills' code would be).
[ much like CSS back-fires on 'easy to use' as you usually end up with a 1000 line file for specifying all possible permutations of style (as styles cannot be treated as components like lego bricks)
Good luck, enjoy. (i wrote this as the comment I would have liked 3 days ago)
Hi nicholasamps, When you implemented ResponseHandler? did you have to set up an SSL domain? I read somewhere that you needed to. Rgds, Bill
how to access the responsehandlerdemo.php
it keep display Invalid or not supported Message
implementing ResponseHandler?... its says you need SSL - but it worked (for me) without - though make sure you CHECK the web-page-interface of the merchant account - there are A FEW KEY stumble-blocks there. (in the 'imlimentation' tab in 'settings')
PREVIOUS POST INCORRECT (by me). Response handler SANDBOX is fine without SSL - but Production needs it.
we are using responsehandler.php for fetch the values from google thanks page. But got the error message "Invalid or not supported Message". Even we changed the setting in .htaccess and ..htpasswd file. google error file shows the same thing "Invalid or not supported Message"... Is any code modification required in responsehandler.php file or else? Please guide us. ......
We are using the Sample PHP code for integration of Google Checkout with the merchant site v1.2.5 The values send through cartdemo.php file to google checkout page.