PHP Sample Code for Google CheckoutFile structure and functionThere 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
|
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.
i had a web designer build a website for me and they used the sandbox version, but when they uploaded the files they didn't put it into production mode. Can someone tell me exactly where to input my merchant id and key into the .php files?
Can anyone pls explain what needs to do for taking response from Google server...?
for all of you having problems this should solve them
http://code.google.com/p/google-checkout-php-sample-code/issues/detail?id=36
So I'm having a very unusual problem. Everything is fine on my testing server (MAMP) but for some reason, anything that uses the google checkout library doesn't work. Even require_once-ing the files halts the execution of the script. I've tried everything relating to messing with the include paths and disabling my autoload, but I still can't get it to work. My production server has cURL, php5, apache2, etc (just like MAMP). What could be wrong?? Thanks, Austin.
Could all those super techies who think this is easy STOP SHOUTING and post a simple working example of a callback script that gets the info from checkout and puts it in a mysql database and updates it whenever checkout does an action! That is all quite a lot of people need right now so that they can do invoice printing etc... (cause you cant do that easily with checkout!)
Checkout samples were awesome! Thanks Google, server2server works without issue on my host! Much easier than PayPal?! Only took one hour to integrate my custom cart with the checkout process. Awesome! Thank you!
http://edoceo.com/
Our SSL site setup works just fine with this software; I'm past initial setup and functionality... it's all good. And I can see the plethora of lovely xml returned from Google regarding the transaction in the log. I have spent an entire work day trying to figure out integration (time is money in web development as I'm sure you know and I can't afford much more) but I'm just trying to integrate the response with our php/sql/database... I'm having the hardest time getting my local Google files to do ANYTHING based on the xml response.
At the very least I'd like to run a sql statement when, let's say, the new-financial-order-state is returned as "CHARGED". I've tried putting conditionals in the new-financial-state switch under case 'CHARGED': no dice. I've tried adding a conditional in the ProcessOrderStateChangeNotification?() function: no dice. Can anybody point me in the right direction of a functioning PHP/sql integration example? I just can't find any documentation and I'm going 2 days on this GC setup. Thanks to all who can help.
Is there any chance this could be more complex? I have very little I am trying to accomplish, I want to get sent a variable when a payment is complete that's it. either the payment is complete and they have a membership or the payment failed and they cannot access my site. I dont have the time to go through all this complex code as a solution to my simple problem. does google have a simple passthrough variable somewhere I can use without all this extra baggage.
www.mysite.com/Process_Page?.php?payment_Complete=true,id=12345
Please tell me this is available somewhere.
SSL certificate installed on your server for level 2 integration.
My Question: Is the SSL certificate installation necessary? How to intall SSL.
My plateform: winowsXP + mysql5.X + php5.X + apache
Nice documentation:)do you have a date on the new release?
Baiju http://www.baijukb.com
Jessie.java, It looks like the sandbox (test server) does not need an SSL certificate, while the production server does.
I suggest you read the apache manuals, it is possible to have your server generate it, you just have to work your way through a few steps.
Why the sample-code doesn't have function set serial number of the notification? I need it to response for google checkout handshake so that I had modified GoogleResponse?.php just added
function setSerialNumber($num) { $this->serial_number = $num; } ... function SendAck??($die=true) { $this->SendOKStatus(); $acknowledgment = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "<notification-acknowledgment xmlns=\"" . $this->schema_url . "\" serial-number=\"" . $this->serial_number . "\"/>"; $this->log->LogResponse??($acknowledgment); if($die) { die($acknowledgment); } else { echo $acknowledgment; } }Please someone tell me what I am doing wrong...All I want to do is add
<merchant-private-data> whatever data I need goes here </merchant-private-data>
I have used the $cart->SetMerchantPrivateData?($data) and all the other functions in the cart class related to merchant data....I get nothihng in the XML tag <merchant-private-data> google sends it back to me without this tag unless I define the value in the googlecart.php class file... Please any suggestions would be greatly appreciated... here is sample code
no errors come up but I dont get the values sent back to me....
can u help me
For what API callback URL is used? after a customer place order from my web page how can i execute one of my php file Please help me F1 ,F1,...
By riyesh07@gmail.com
I agree with older post. The documentation is all over the place and hard to follow. I work with api's for payment processing all day long with some of the largest processor's in the world. They always have -- Request --> Response along with required fields and size of fields.
I have been searching through this mess for a little over an hour now with no avail. Has anyone found a documentation in this site that can provide this? Ok. I see that there are a bunch of methods. Extremely unclear. ehem.. no comments. " check...@quebix-solutions.co.uk, "
Request->> url
Response->>Google has taken the time to answer all of these complaints. The answers are all at http://google.com. Type "php 101" into the long rectangle in the middle of the screen and then click "Google Search" with your pointing device. If you still have problems, consult your jr. high guidance counselor about different career options.
Really nice examples! Thank you, they're very simple to understand and modify!
inventma...@inventmagic.com
Firstly, you should set your API callback URL at Merchant's account (Settings->Integration) to 'http://yourdomain/demo/responsehandlerdemo.php'
Then, try to insert this debug code in responsehandlerdemo.php which writes all received information during transaction before " switch ($root) { ":
$f = fopen(dirname(FILE)."/log.txt", "a+"); fwrite($f, "\nROOT:\n".$root."\nData:\n".print_r($data, true)); fclose($f);
Then, open log.txt file at your server directory and check Google's response information.
Maybe someone should TRY the demo code before posting it live. No help at all!
OK GUYS HELLO THERE THIS IS A SOLUTION WITH A DOWNLOADABLE FILE !!!! NOTE
this works and I have used it on 2 websites now! ALL THIS DOES IS gets the response from google and stuffs the data into the mysql database
http://www.whoopie.net/downloads/checkout-example.zip
Contains 1)SQL commands to create the tables for the database 2)my version of the responsehandler file - this needs some amends - read the comments in the file! basically database info merchant key and id bit and thats it!
I really hope this helps - also keep checking out the site as a free cms system that has an online shop that integrates with checkout seamlessly is on the way - why? - why not?
Instructions for above 1) create your database (use the structure in the file I provided) 2) change the database information in the whoopie_checkoutex.php file 3) if going straight for production change the merchant id, key, currency and set the 'sandbox' to 'production' 4) upload the php file to some secure webspace (or not if in sandbox mode) 5) put the URL in the checkout callback field in the google checkout backoffice 6) make sure its set to XML in the checkbox below it 7) under the advanced option bit below that tick the tow ones that relate to phone numbers if you want to get those 8) now build your pages to read the database (pretty simple, but i can provide an example of that if required
all the best
Iain
"http://www.whoopie.net/downloads/checkout-example.zip"
this link is not working
whoops! try this go to http://www.whoopie.net/
there is a link on the homepage
I am currently modifying as I rather stupidly didnt allow for people calles o'shea did it very quickly and forgot to make the script deal with quote marks in the name (anyone with basic MySQl skills can fix this as it's now pretty obvious where things are hgappening and fixing the sql should be easy!
The path for this file must be specified in the merchant's API callback URL in Settings->Integration of the merchant's seller account.
How can you override this path requirement in the merchant's API callback setting? I have a number of sellers that use checkout and these sellers also sell on a number of different sites... So, how can these sellers input each sites callback requirement. It seems that sellers are limited to one site and one API callback....
hi mayasky76, I want one help from you.. I am using the scrip and php code provided by you on http://www.whoopie.net/ but i am facing on problem in that. Actually i have local buyer id which i stored in session variable. now when we are inserting data through responsehandlerdemo.php into table WPY_GOOGLE i want to insert the buyerid also which is in session. but i am unable to get that value from session. I dont want is the exaclty the problem and where is it?? pls help me i am stuck in this problem
thanks in advance vikas
I have simple website and i want to integrate google checkout. I want the credit cart box and billing info on my website and when i press submit, i want to use the google checkout to check all the conditions and get me responce back, just like aurthorize.net.
How can i do this?
For anyone who was having trouble getting responsehandler.php to charge the card once the "Chargeable" state is sent, I had to modify the sendAck (acknowledgment) method call: $Gresponse->SendAck?();
I instead changed it to be: $Gresponse->SendAck?(FALSE);
The reason is because SendAck?() takes a $die variable that defaults to true. I don't wholly get it, but if it dies, then the response handler file will stop processing, and it won't even do the switch for $new_financial_state.
As another note, a lot of my problems were solved when I realized that require_once() functions in a number of files (as well as the RESPONSE_HANDLER_ERROR_LOG_FILE and RESPONSE_HANDLER_LOG_FILE variables in the responsehandler.php file) were not using the proper path on my server. Either due to configuration problems or some other means of my own incompetence, the ini_set() function was not giving the proper path.. So log files were not being generated and the XML parser files were not be included (required, really) correctly either.