My favorites | Sign in
Google
                
Search
for
Updated Feb 15, 2007 by jacob13moon
Labels: Featured
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

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.

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


Comment by davidgutschick, Aug 06, 2007

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.

Comment by donmubiri, Aug 10, 2007

someone please explain what server 2 server is all about

Comment by frooglemale, Aug 18, 2007

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!

:)

Comment by frooglemale, Aug 18, 2007

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!

:)

Comment by frooglemale, Aug 18, 2007

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!

Comment by prashcom, Sep 25, 2007

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

Comment by prashcom, Sep 25, 2007

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

Comment by prashcom, Sep 25, 2007

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 ;)

Comment by artistan, Oct 05, 2007

added carrier calculated shipping to this code if anyone wants it post a message.

Comment by james.le...@mac.com, Oct 10, 2007

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?

Comment by BLYZZARD.COM, Oct 26, 2007

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.

Comment by gspe...@cityamigo.com, Oct 27, 2007

This is soooo much cleaner than PP... thanks google.

Comment by sherifmayika, Nov 01, 2007

is there any documentation for novive php developers

sherif

Comment by thegempalace, Nov 16, 2007

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.

Comment by j...@nachnach.com, Nov 26, 2007

Slight problem, I'm trying to test this out, but it keeps asking for a Username and Password???

Comment by balasenthil, Dec 01, 2007

Hi

Is there a way to generate refund notifications for all past transactions?

Comment by pragyabchar, Dec 06, 2007

is there any way to integrate the google checkout procedure within one site?

Comment by shahdeveloper, Jan 06, 2008

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

enable with open ssl.please required help for this isue how to resolve this issue.upto mine some server configuration is required but i am not a linux etc oproficient so please tell in brief what to do.

Comment by blogscheduler, Feb 21, 2008

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.

Comment by Izonomia, Mar 13, 2008

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!!!

Comment by check...@quebix-solutions.co.uk, Mar 27, 2008

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

Comment by Jorojam02, Apr 04, 2008

is there any things knows about ipn just like paypal? does google checkout have this?

Comment by billskipton, Apr 08, 2008

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.

Comment by nicholasamps, Apr 09, 2008

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 also had to move $Gresponse->SendAck?(); from line 164 to 203 - if you want the script to CHARGE the card (it defaults to just auth it and you manually charge) un comment $Grequest->SendChargeOrder?($data$root?'google-order-number'?'VALUE'?,''); on 176.

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)

Comment by billskipton, Apr 09, 2008

Hi nicholasamps, When you implemented ResponseHandler? did you have to set up an SSL domain? I read somewhere that you needed to. Rgds, Bill

Comment by teddybugs, Apr 25, 2008

how to access the responsehandlerdemo.php

it keep display Invalid or not supported Message

Comment by nicholaswhitworth, May 01, 2008

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')

Comment by nicholasamps, May 02, 2008

PREVIOUS POST INCORRECT (by me). Response handler SANDBOX is fine without SSL - but Production needs it.

Comment by gcttestbuyer, May 07, 2008

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.

Comment by m...@axiuminternetmarketing.com, Jul 31, 2008

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?

Comment by mangal.varshney, Aug 14, 2008

Can anyone pls explain what needs to do for taking response from Google server...?

Comment by i...@on-top.co.uk, Aug 19, 2008

for all of you having problems this should solve them

http://code.google.com/p/google-checkout-php-sample-code/issues/detail?id=36

Comment by arbales, Sep 28, 2008

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.

Comment by i...@whoopie.net, Oct 09, 2008

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!)

Comment by edoceo....@gmail.com, Oct 21, 2008

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/

Comment by jmil...@trafficeducation.net, Oct 31, 2008

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.

Comment by inventma...@inventmagic.com, Nov 07, 2008

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.

Comment by jessie.java, Nov 17, 2008

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

Comment by kb.baiju, Jan 01, 2009

Nice documentation:)do you have a date on the new release?

Baiju http://www.baijukb.com

Comment by awevtrading, Jan 17, 2009

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.

Comment by u...@id55.com, Jan 22, 2009

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; 

    } 

    }
Comment by inventma...@inventmagic.com, Jan 27, 2009

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

$cart = new GoogleCart?($merchant_id, $merchant_key, $server_type,$currency);
$cart->SetMerchantPrivateData?(
new MerchantPrivateData?(array("User_Id?" => "ABC123")));
echo $cart->CheckoutServer2ServerButton?('digitalCart.php');

no errors come up but I dont get the values sent back to me....

Comment by riyesh077, Jan 30, 2009

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

Comment by ejge...@gone1981.com, Feb 09, 2009

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

fields returnURL
Response->>
fields

Comment by rreu...@fspp.com, Feb 10, 2009

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.

Comment by iprustam.mobile, Feb 22, 2009

Really nice examples! Thank you, they're very simple to understand and modify!

Comment by iprustam.mobile, Feb 22, 2009

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);

switch ($root) {

Then, open log.txt file at your server directory and check Google's response information.

Comment by velkymx, Apr 19, 2009

Maybe someone should TRY the demo code before posting it live. No help at all!

Comment by mayasky76, Jun 03, 2009

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?

Comment by mayasky76, Jun 03, 2009

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

Comment by I...@skyfacet.com, Jun 05, 2009
Comment by mayasky76, Jun 08, 2009

whoops! try this go to http://www.whoopie.net/

there is a link on the homepage

Comment by mayasky76, Jun 08, 2009

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!

Comment by reneholliday, Jul 05, 2009

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....

Comment by vikasbhardwj, Jul 12, 2009

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

Comment by gcheckoutsandbox, Sep 22, 2009

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?

Comment by craig.leinoff, Dec 08, 2009

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.

Comment by craig.leinoff, Dec 08, 2009

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.


Sign in to add a comment