We will make use of the provided code by the Google Team, as they have done all the leg work, so make use of it.
Prerequisite
Before we begin please make sure that you have the following be going on.
- An understanding of Classic ASP
and how XML works
- Both a Google Checkout Account and Google Checkout Sandbox Account
- A Copy of the Classic ASP Sample Code - Get a Copy Here
- Your website should already be at the point where all product information is able to be passed to Google.
Step 1 - Setup your environment
Once you have downloaded the sample code, extract the complete contents of the Zip file into the location you are going to run the code from. What I would suggest is that you keep the Google code in its own folder within your website, thsi will make using it alot easier.
Step 2 - Get your Merchant ID and Key
Login to your Google Checkout Sandbox Account - https://sandbox.google.com/checkout/
Click on the settings tab at the top of the screen, then click on the integration option from the left menu.
Make a note of your Gooogle Merchant ID and Google Merchant Key from the right of the screen.

NOTE - Your Sandbox Merchant ID and Merchant Key are different to your Live / Production details.
Step 3 - Setup the details for your call back page.
- Make sure that the For Extra security... tick box is unchecked (if you leave this checked you will get URL errors when posting your order form to Google
)
- Make sue the XML
option is selected for the Callback Method (this means Google will send XML
to your callback page and not name/value pairs)
- Enter your url of where your callback.asp page will be hosted. (when testing in sandbox this URL does not have to be SSL
secured and can use the normal HTTP protocol
Step 4 - Setup Testing Details
Ok once you have made a note of your merchant id and key, you need to enter these in the correct locations in order to process your orders and receive stuff back from Google.
We also need to setup the sample code to work as test code, so all transactions can be done against out test environment.
Open the file googleglobal.asp and do the following
- Change the values of the two contstants MerchantId and MerchantKey. These should match your testing, sandbox details for testing.
- Change the variable EnvType to SANDBOX
- Change the variable MerchantCurrency to match your country currency, GBP, USD, etc.
Note - Make sure all of the files contained in the code sample Zip file are location in the same folder
Step 5 - Create your page form
Now go into the page which you wish to submit to GoogleCheckout. This page is the one which will be passed directly to Google containing the order details.
On this page you need to create a form with a series of hidden fields
The basic fields are
- item_price_1 - the price of the item
- item_currency_1 - the currency for this item
- item_quantity_1 - the amount of this item
- item_description_1 - the description of this item
- item_name_1 - the name of this item
If you are passing more item you can do so by incrementing the number for example, iten_price_1, item_price_2 and so on.
In addition to the fields above you can additionally specific.
- ship_method_name_1 - this is the carrier or delivery method
- ship_method_price_1 - this is the cost of delivery for this item
Again for multiple items you can just increment the item number for example, ship_method_name_1, ship_method_name_2 and so on.
Now in addition to the item specific fields you can additionally specify any tax details, such as VAT or trade taxes you wish to apply to this order. Google will automatically add this on to your total for you at the checkout.
These fields are
- tax_rate - this is the actual rate of tax as a decimal i.e 17.5% would be 0.175
- tax_use_state - if in the US you must specify which state you are paying tax to.
- continue-shopping-url - if you specify this the link the shopper clicks on the purchase complete page in the checkout will take them to this url.
Form Target URL
Whilst in testing your form needs to post to
https://sandbox.google.com/checkout/cws/v2/Merchant/YOUR-MERCHANT_ID/checkoutForm
Note - Replace YOUR-MERCHANT_ID with the merchant ID for your Sandbox account.
Form Sample
<form name="googleform" action="https://sandbox.google.com/checkout/cws/v2/Merchant/YOUR-MERCHANT-ID/checkoutForm" method="post" charset="utf-8"><input type="hidden" value="Product_Name" name="item_name_1">
<input type="hidden" value="Product Description" name="item_description_1">
<input type="hidden" value="1" name="item_quantity_1">
<input type="hidden" value="99" name="item_price_1">
<input type="hidden" value="GBP" name="item_currency_1">
<input type="hidden" value="DHL" name="ship_method_name_1">
<input type="hidden" value="3.99" name="ship_method_price_1">
<input type="hidden" value="0.175" name="tax_rate">
<input type="hidden" value="NY" name="tax_us_state"></form>
Once you have passed all your information into this form, you can now post this form directly to Google
In my next post I will look at what to do this the details you have passed into Google
Sean J Connolly - AJAX and GIS Specialist
http://www.potissimus.co.uk
http://www.buzzproperties.co.uk/
MY Other Blogs
http://notjustajax.blogspot.com/
http://weeklywebsitetips.blogspot.com/
http://ghostystuff.blogspot.com/
http://tipstosellyourhouse.blogspot.com/



4 comments:
You don't know how pleased I am that I found this blog! I've just spent about 3 hours trying to get google checkout to work with HTML in their sandbox, but kept getting an XML error page or an invalid page message. Turns-out that Google's own example code is WRONG, but you got it right - way to go :-)
Thank you soooo much.
Thanks for the great words. Its nice to know I helped you out. If you need anything else jsut let me know.
Happy Coding
Sean
I am trying to send a "merchant-item-id" using a html post, but it seems that Google's docs seem incorrect. I guess if I have:
item_option_name_1
item_option_price_1, etc
how could I specify the merchant-item-id? Actually, all I want to do is tie this action back to my database with some kind of key.
Luis
In order to pass any information into Google you need to give it its correct path, in the case of merchant-item-id. You need to put in your html form a field with a name of "shopping-cart.items.item-1.merchant-item-id" rather than just merchant-item-id. This will pass the value into Google of this field, this can be anything you choose such as product id, item code or any other reference.
Now when you get this value back from Google in the response that is posted to your callback page, all you need to do is add the returned Google order number to you item, and from that point on just use the Google order number as your reference.
So in short the process is
1. Send an HTML form to Google Checkout with a field called shopping-cart.items.item-1.merchant-item-id which has a value of your own reference number.
2. On your callback page, at the first attempt by Google to send a response to your callback page, you will be send your own value as specified in your "shopping-cart.items.item-1.merchant-item-id" field along with a unique Google order number.
3. Create a process / page / service or what ever you wish that amends your item and links it to the Google order number returned by Google and update your item in your DB.
4. From them on use the Google order number as your reference as Google will always send this for any responses for this order.
Then just process the rest of the Google checkout responses as normal.
I hope this helps, if you need any more info just let me know.
Happy Coding
Sean
Post a Comment