Google Checkout Custom Control

Google recently introduce 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. Once they do, you can use Google Checkout to charge their credit cards, process their orders, and receive payment in your bank account."

 

They currently have no ASP.NET examples posted on their site so I have created an ASP.NET 2.0 Custom Web Control that will allow you to easily integrated with their service by simply dropping a control on the page a specifying a few parameters.  So here it is...

 

Step 1: Modify the Web.Config file

Add the following entry to the web.config file.  This will allow you to use the control on any page with out having to add the control directive to each page.  Also, don't for get to add the dll to the bin directory of your website.

 

<system.web>

    <pages maintainScrollPositionOnPostBack="true">

          <controls>

            <add tagPrefix="Google" namespace="Google.Web.UI.WebControls"

 assembly="Google.Web"/>

          </controls>

    </pages>

 

Step 2: Add the control to the page.

This is pretty simple, but just make sure you add it outside to the form tags on the page.  Specify your MerchantId and MerchantKey that you received for Google and tell the control if it should use the sandbox (test) or the production service.  You will need to register for both through Google.

 


<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

       Place info here...

    </div>

    </form>

    <Google:CheckoutButton MerchantId="101156456465"    
           
MerchantKey="234lk4j53452lkj34" UseSandBox="true"
           
runat="server" ID="btnGoogleCheckout"/>

</body>

</html>

 

Step 3: Set the Shopping Cart XML Property

In the code behind for the page set the ShoppingCartXml property. For testing purpose I simply Desearlized there sample xml in to a ShoppingCart object. Here is a great article on how to do that.


http://www.netomatix.com/Products/Ecomm/GoogleCheckOut.aspx

 

protected void Page_Load(object sender, EventArgs e)

{

    btnGoogleCheckout.CartXml = GetCartXML();

}

 

private string GetCartXML()

{

    string xmlFile = "checkout-shopping-cart-SIMPLE.xml";

 

    XmlDocument xml = new XmlDocument();

    xml.Load(Server.MapPath(xmlFile));

 

    return xml.InnerXml;

}

You are all set. Just click the button and you will see the shopping cart appear on the Google site. Let me know if you have any questions or problems with the control.

For more information visit the following link to the developers guide.

http://code.google.com/apis/checkout/developer/index.html 


Similar Articles