Latest Posts

Using Google Checkout with Coldfusion- Part one

Posted on February 06, 2007, under ColdFusion | 17260 Views

This series will cover the initial setup and the basics of using the CheckoutCFC project for integration with Google Checkout.  You will have to get your hand dirty but the provided CFCs will help get you started.   In this post,we will cover Level 1: setting up the sandbox account, creating a sample cart, submitting the cart to Google and processing the cart in the merchant account. 

Levels Explained:

  • Level 1: Receive new order notifications by email, then use the Merchant Center, a Google web application that lets you manage orders from your web browser.
  • Level 2: Create a web service to handle new order notifications and all other order communications with Google programmatically.

Future entries in this series will cover Level 2 integration - automating the processes.

Disclosure:

I do not work for Google.  This content is not endorsed or supported by Google in anyway. 

 

About Google Checkout

Google Checkout is a checkout process that you integrate with your website, enabling your customers to buy from you quickly and securely, using a single username and password. And once they do, you can use Checkout to charge their credit cards, process their orders, and receive payment in your bank account.

Until December 31, 2007, Merchants (you) can process their Google Checkout sales for FREE.  That is right, at absolutely no cost.  Beginning January 1, 2008, when you use Google Checkout⢠to process your sales, you'll only be charged a low 2% + $0.20 per transaction. With Google Checkout, there are no monthly, setup, or gateway service fees. These standard, non-promotional fees may be updated from time to time.

Google Checkout fees

 

Getting Started

Google has two sites that you will need to register for: sandbox and production.  The sandbox will be your development account.  The production account will need to be registered for your client (or yourself).  You will have to either have a Federal tax ID (EIN) or use your SSN to setup the account. HINT: for the sandbox use EIN and enter a number in this format: 00-0000000.  

Create Accounts:

 

Download & install CheckoutCFC

  1.  Download Latest from Subversion  (hosted by RiaForge.com)
  2. Create a folder under your webroot, this example will use checkoutcfc as the folder.
  3. Unzip the contents of checkoutcfc.zip into the folder.  You will see the following structure:
  • components
    • googlecheckout.cfc
    • googlecheckoutresponsehandler.cfc
    • checkout.ini.cfm
  • tags
    • hmac.cfm
    • sha_1.cfm
  • sample_checkoutcart.cfm
  • sample_responsehandler.cfm

Note: The cart has to be encrypted using HMAC_SHA1.  I accomplished this using the custom tags included in the zip.  There are other ways to accomplish the encryption but for me, this seemed like the easiest to implement.  If you have better ideas, please add a comment below.

 

Checkout.ini.cfm - Configuration File

Get your Merchant ID and Key from the sandbox:

Login to the sandbox, click on the Settings tab.

They are both listed on the right.

 

 

  

Edit components/checkout.ini.cfm

[default]
merchantid=12312
merchantkey=yourKey
continueurl=https://yoursite.com
editcarturl=https://www.yoursite.com/cart
chargetax=false
statetochargetax=AR
taxrate=0.075
chargeshipping=false
allowfreepickup=true
demosite=true

The file is pretty straight forward, the continueurl is the url that the shopper will be returned to after checkout.  The editcarturl is the url to your shopping cart, if the customer wants to make changes.

demosite = true lets the CFC know to use the sandbox instead of production servers.  Change this to false when going live. 

 

Theory of Operation

These steps are required for Google Checkout shopping carts.

  1. Create a checkout shopping cart for the buyer's items as an XML structure.
  2. Create a signature for the shopping cart using the HMAC_SHA1 function.
  3. Base64-encode the cart.
  4. Base64-encode the signature.
  5. Put the cart and signature into a Google Checkout button form.
  6. Charge the order.
  7. Add tracking information to the order.
  8. Mark the order shipped .
  9. Archive the order.

Steps 1 - 5 are handled by the CFC.  Steps 6-9 are handled with the Merchant Center or level 2 integration.

Initialize the cart:

<cfset session.GoogleCart = createObject("component","components.googlecheckout")>

Add items to the cart:

<!--- Just add some items to the cart to get us going --->
   <cfset session.GoogleCart.AddCartItem(item="3432511",description="New Widget",cost="210",quantity="4")>
   <cfset session.GoogleCart.AddCartItem(item="34242",description="Last years Widget",cost="13.70",quantity="1")>
   <cfset session.GoogleCart.AddCartItem(item="191911",description="Accessories for Widget",cost="24.00",quantity="3")>

Create the Checkout Button:

<!--- Output the checkout button --->
<cfoutput>#session.googleCart.CreateForm()#</cfoutput>

The call to session.googleCart.createForm() will output the form with the encrypted cart contents. This is the only required step to output the Checkout button.

If you want to display the contents of your cart, you would need to call getCartItems().

<!--- Get the cart contents ---->
<cfset Cart = session.GoogleCart.GetCartItems()>

Your Cart Contents:
<form action="<cfoutput>#cgi.script_name#</cfoutput>" method="post">
<table width="600" cellpadding=1 cellspacing=1 border=1 class="top_sm_bar" style="border:1px solid #000000; border-collapse: collapse;empty-cells: show;vertical-align:top;margin-left:10px;">
      <tr style="background:#f1f1f1;color:black;">
         <td align="center">Quantity</td>
         <td>Item</td>
         <td align="right">Price</td>
         <td align="right">Total</td>
         <td>Actions</td>
      </tr>   

   <cfoutput query="Cart">
      <tr>
         <td align="center"><input type="text" name="#itemname#" value="#itemquantity#" size="2"></td>
         <td>#itemdesc#</td>
         <td align="right">#dollarformat(itemprice)#</td>
         <td align="right">#dollarformat(total)#</td>
         <td>(<a href="#cgi.script_name#?removeitem=#itemname#">remove</a>)</td>
      </tr>   
   </cfoutput>
</table>
   <cfif cart.recordcount>
      <input type="submit" name="Update" value="Update Quantity">
   </cfif>   
</form>
<br>

 

 

Sample Cart 

 

  

At this point you have created your sandbox account and entered the merchant ID & Key into the configuration file.  You are now ready to test your first cart by browsing to your site/checkoutcfc/sample_checkoutcart.cfm.

 

 

Credit Card numbers that can be used for testing (only in Google Checkout):

Card Type Card Number CVC Expiration Date
American Express 3782 8224 6310 005 any four digits any future date
Discover 6011 1111 1111 1117 any three digits any future date
MasterCard 5555 5555 5555 4444 any three digits any future date
VISA 4111 1111 1111 1111 any three digits any future date

 

Merchant Account

After you (or your customer) completes a checkout, you need to go into the Merchant Center to process the order. 

I'll just let Google explain this one -  Reviewing the Order in the Merchant Center.

 

Wrap Up

We covered the basics of setting up your Google Checkout sandbox account, created a cart, posted the encrypted cart to Google for processing and then processed the order using the Merchant Center. Next time we will cover how-to handle level 2 integration.

 

Feel free to post any comments, suggestions or questions below.

 

 

External Links:

Google Checkout API

Google Checkout XML API Developer's Guide

Production Account

Sandbox Account

Building a .NET App for Google Checkout

 

Sample Coldfusion Code:

CheckoutCFC.RiaForge.com

The readme.txt file included in the zip has some basic getting started tips.

 

Subversion link to code:

http://svn.riaforge.org/checkoutcfc/