My favorites | English | Sign in

Google Checkout

Custom Shopping Cart: XML API

How to Integrate Google Checkout with your Custom Cart

This document is a step-by-step procedure instructing you how to integrate Google Checkout with the custom shopping cart on your website. It assumes that you have an existing custom cart and want to integrate Google Checkout with it using the XML API. As explained below, integrating requires programming skills to modify your server code.

This procedure uses the XML API. If you're unsure whether you should be using the HTML or XML API, see Choosing Between HTML and XML API.

Objective - When you're done, you will have added a Google Checkout button and supporting code to your existing shopping cart on your website so that customers can click to sign up and place orders through Google Checkout.

Buyer experience - When the buyer clicks the Google Checkout button, your site must send to Google a Google Checkout shopping cart with the list of items the buyer has selected, including prices, descriptions, taxes and shipping. Google Checkout then presents a "Place order" page with the provided information to the buyer. After the buyer chooses a credit or debit card and clicks the "Place your order now" button, Google Checkout accepts the order and sends it to the Order Inbox of your Google Checkout account. For a view of this navigation from the buyer's perspective, see Google Checkout Buyer Experience.

Will this procedure work for my site? The easiest way to determine whether this procedure will work for you is to ask the developer of your custom shopping cart if that code can be modified to work with Google Checkout. For this to be possible, your shopping cart must allow programmatic access to the items in it. Your cart contains the buyer's complete order — your developer needs to write server code to copy the buyer's items from the custom cart and write them out to an XML signed cart (client-to-server) or HTTP message (server-to-server) and send it to Google Checkout. Have your developer look at Step 7 for more details.

Custom carts - Typically, only custom carts have that kind of internal access to the shopping cart. Carts built by third parties for general use are typically closed and not customizable by merchants &mdash those carts either come with Google Checkout support built-in (these are the Google Checkout eCommerce partners), or not (in which case you can only ask them to add support for Google Checkout).

Procedure summary:

  • You generate Google Checkout demo code for an XML cart for the products or services you are selling (Step 3).
  • If necessary, you modify the tax rules and shipping settings (Steps 4 - 5).
  • You can optionally include code to help track conversions (Step 6).
  • Then you modify your server code to copy the content of the custom cart and programmatically generate the corresponding request for the Google Checkout server (Step 7).

Technical skills required:

    The programmer responsible for integrating your custom shopping cart with Google Checkout via the API should have a strong working knowledge of:
  • XML
  • HTTP messages (if sending server-to-server)
  • Server-side code that can access items in the custom shopping cart and write out XML. The programming language is dictated by what the rest of your website is written in, such as PHP, Perl, Python, ASP, ASP.NET, Java or equivalent.

This symbol means the link opens up the page in a new window or tab so when you're done with that step, you can close the window or tab and go on to the next step.

Step 1. Sign up for a Google Checkout merchant account

  1. Sign up now (http://checkout.google.com/sell/signup) for a Google Checkout merchant account if you don't already have one.

    This is a production (http://code.google.com/apis/checkout/Google_Checkout_Glossary.html#production) account, for processing real world financial transactions. You will need to supply your email address, to which you will be sent an email to confirm. You will also need to supply information that personally identifies you or your business — depending on the country, this might include a credit or debit card number, tax number, registration number or other forms of identification.

  2. Specify a bank account

    Follow the instructions Bank account set up and verification (http://checkout.google.com/support/sell/bin/answer.py?hl=en&answer=113730) to get paid once you start bringing in orders.

    When you sell through Google Checkout, buyers pay Google Checkout, who then pays you. Before you can get paid, you need to specify a bank account so that you'll be eligible for payouts. This setup can take a few days, so it's good to set it up early.

  3. Locate and write down your Merchant ID

    Write down your Merchant ID, located on the same Integration Settings (https://checkout.google.com/sell/settings?section=Integration) page. This is your production (http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#production) Merchant ID, to be used for actual sales. You will need to specify your Merchant ID in the cart post URL when you go live.

    Note: Your Merchant ID is public, but your Merchant Key is not. You should keep your Merchant Key strictly private and never share it anyone. No Google representative will ever ask you for your Merchant Key. Someone who obtains your Merchant Key could tamper with prices in an order and fraudulently purchase items at a steep discount.

Step 2. Sign up for Google Checkout sandbox accounts (Optional)

    The sandbox(http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#sandbox) is a Google Checkout environment that lets you test placing an order without executing real world financial transactions. This step is recommended if you wish to test your order total calculation (i.e., correct item price, tax, and shipping) and shipping availability.

    Also, it will assist in helping you implement your order processing system because it allows you to test an end-to-end order without any real world payments.

  • Using Sandbox for Testing(http://code.google.com/apis/checkout/developer/Google_Checkout_Basic_HTML_Sandbox.html)

Step 3. Create the initial XML cart

    Note: You don't need to be signed in to any Google Checkout account (sandbox or production) for the rest of these setup steps, except (1) for testing when you place orders from your sandbox buyer account, and (2) to view orders (in your sandbox merchant account).

    In this step you create the initial XML cart, which contains the cart information: item names, item prices, item descriptions, tax rules, shipping rates, and the Google Checkout Button.

  • Use the Interactive Code Demo (http://code.google.com/apis/checkout/developer/interactive_demo.html) to generate an example XML cart, following these instructions. Content within the tags are merely placeholders to be replaced when you write server code.

    • Product - Choose the type of product you are selling.
    • Tax - Choose the appropriate tax method. The first radio button is the easiest choice, as you set tax once in the Merchant Center (http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#merchant_center) for all transactions, rather than adding tax rules to the XML cart. If that choice isn't suitable, choose one from the drop-down menu. If those aren't suitable, other tax options are available with the tax rules below.

      Note: If you specify default-tax-table attributes in the XML cart (such as rate(http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Tag_Reference.html#tag_rate)), then your Merchant Center tax settings will be ignored.

    • Shipping - Choose the shipping charges that you prefer. Like for taxes, the first radio button is the easiest choice. You can also configure shipping in the Merchant Center for all transactions, rather than adding shipping rules to the XML cart. Other shipping options are available in the shipping settings below.

      Note: If you specify shipping attributes in the XML cart, then your Merchant Center shipping settings will be ignored.

    • Markup - Choose XML.
    • Server - Choose Sandbox (http://code.google.com/apis/checkout/developer/Google_Checkout_Basic_HTML_Sandbox.html) if you're testing (see Step 2), or Production (http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#production) if you're going live.
    • Merchant ID - Paste or type your Merchant ID for the Server choice you just made (Sandbox or Production).
  • Note: Writing Code - You can start writing and testing server code to generate the above code now, as described in Step 7, before proceeding with the next steps.

Step 4. Modify tax rules, if necessary

    If the previous step did not provide you with the tax rules you need, look for other tax rules in XML Examples for Tax Tables(http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Taxes.html). You can add these rules to the XML cart you created in the previous step. All XML Parameter Definitions(http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Taxes.html#XML_Tag_Definitions) related to tax rules are listed on that page. You will be writing code to generate these rules in Step 7.

    The following tax examples are not covered by the interactive code demo:
    Example 4: Alternate tax rules (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Taxes.html#Alternate_Tax_Rules_1)
    Example 5: Alternate tax rules for items that are always tax-exempt (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Taxes.html#Alternate_Tax_Rules_Tax_Exempt)
    Example 7: Alternate tax tables for U.K. merchants (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Taxes.html#Alternate_Tax_Tables_for_UK)

Step 5. Modify shipping settings, if necessary

    If the interactive demo did not provide you with the shipping settings you need, look for other shipping rules in Shipping and Digital Delivery (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API.html#shipping_xsd).

    The following shipping examples are not covered by the interactive code demo of Step 3:
    Carrier-Calculated Shipping (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Carrier_Calculated_Shipping.html)
    Merchant-Calculated Shipping (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Merchant_Calculated_Shipping.html)

    Note: Digital delivery - Digital goods are delivered by sending download instructions. Three examples of email, URL and description-based delivery of download instructions are included under "Product" in the interactive demo (http://code.google.com/apis/checkout/developer/interactive_demo.html).

Step 6. Include conversion tracking (Optional)

    By adding tags to define the pixel URLs to include and the parameters for Google Checkout to provide, you can track your percentage of sales/conversions(http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#conversion). In addition, conversion tracking is useful for affiliate sales.

    Google Analytics allows you to track users on your site to help determine where the drop offs are.

    • Third-Party Tracking - Go to Google Checkout Support for Third-Party Conversion Tracking (http://code.google.com/apis/checkout/developer/checkout_analytics_integration.html). You can track conversions from your website by adding code to your pages that relays page view information.

    • Google Analytics - Add Google Analytics tracking code to each page on your site that you wish to track using Using Google Analytics to Track Google Checkout Orders(http://code.google.com/apis/checkout/developer/checkout_analytics_integration.html). Google Analytics let you see how visitors interact with your website, enabling you to optimize ad campaigns and website content for increased sales. Requires straight-forward pasting of HTML and Javascript into your web pages.

Step 7. Write server code to generate the XML cart and request

    Note: In the previous four steps you have created a sample of the XML cart you need for Google Checkout. The purpose of this step is for you to copy the content of the custom cart and write it out to the required XML cart or HTTP request.

    You need to write server code to copy the buyer's items from the custom cart and write them out to an XML signed cart (http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#xml_cart) (client-to-server) or HTTP message (http://code.google.com/apis/checkout/developer/Google_Checkout_Glossary.html#http_request) (server-to-server) and send it to Google Checkout.

    • Client-to-server - Slightly less secure. When the buyer clicks the Google Checkout button, the HTML form goes from the buyer's browser directly to the Google Checkout servers. The base64 encoded cart can be unencoded, so you'll need to be careful with digital goods.
    • Server-to-server - More secure. When the buyer clicks the Google Checkout button, it submits to the merchant's server, which builds an HTTP request and sends it using basic authentication to the Google Checkout servers. Because the cart is sent from the merchant's servers, the client cannot view the contents, increasing security for digital goods.
    • Note: The interactive code demo in Step 3 lets you switch between the client-to-server and server-to-server options.

      Note: You can leverage the Client libraries and sample code (http://code.google.com/apis/checkout/developer/samplecode.html) page to perform server-to-server posts. Code samples in ASP, Java, .NET, PHP, Perl and Ruby can help you with your integration.

    Perform one of the following two instructions:

  • Client-to-server: Configure your form to submit directly from browser to Google Checkout

    1. Write server code to generate the XML cart - With this option you write server code to copy the order information from your custom cart to the XML API cart containing the input tags built in the previous steps. You'll need to generate your signature using the HMAC-SHA-1 algorithm on your XML Cart with your Merchant Key as the hash key. Then, you'll need to base 64 encode the XML cart and signature. These two items will be placed in a HTML form which will be sent to Google Checkout when your customer clicks on the Google Checkout button. For more information, review the Developer Guide instructions.
    2. Sandbox - To send your request to the sandbox, you'll need to change the references from https://checkout.google.com to https://sandbox.google.com/checkout in both the form action and button image. You'll also need to update the Merchant_ID portion of the URLs(http://code.google.com/apis/checkout/developer/interactive_demo.html#markup). If you're using the client libraries, you'll need to specify that you wish to use the sandbox and the sandbox Merchant Id and Key.

      Note: The client libraries will automatically update the URLs and buttons appropriately.

  • Server-to-server: Submit a server-to-server Checkout API request

    When you submit a server-to-server Checkout API request, the form on your page that displays the Google Checkout button (http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API.html#google_checkout_buttons) will submit to a web service running on your site. That service will then create the Checkout API HTTP request to contain product, taxes and shipping information about your buyer's order. Your application will then send the Checkout API HTTP request to Google using HTTP POST. In response, Google will return to you a Google Checkout URL that you will redirect your buyer to for completing the order.

    The basic steps for submitting server-to-server requests follow:

    1. Write an application that creates an HTTP request - Write server code that generates an HTTP request with name/value pairs based on the XML cart created in the earlier steps, replacing the placeholder values in the tags with the actual buyer-selected product, tax and shipping information. The names should be from element names in the XML API.

      Note: The client libraries can handle XML cart generation.

    2. Configure the Google Checkout button to submit to your site - Configure the forms on your site that display Google Checkout buttons to submit to a URL on your site that runs the application created in Step i. When the buyer clicks a Google Checkout button, your server will receive an HTTP request at that URL. Your application should then build the Checkout API request for the buyer's order.

    3. Send the request to the Google Checkout server - Send the HTTP request to Google using an HTTP POST request. Please select the appropriate URL for your request from the two choices below.

      • Sandbox - To send your request to the sandbox, send it to the following URL. You must replace the string MERCHANT_ID with the Merchant ID for your sandbox merchant account (http://code.google.com/apis/checkout/developer/Google_Checkout_Basic_HTML_Sandbox.html#Locate_ID_and_Key).

        https://sandbox.google.com/checkout/api/checkout/v2/merchantCheckout/Merchant/MERCHANT_ID
        
      • Production - To send your request to the production environment, send it to the following URL. You must replace the string MERCHANT_ID with the Merchant ID for your production account.

        https://checkout.google.com/api/checkout/v2/merchantCheckout/Merchant/MERCHANT_ID
        
    4. Extract the Google Checkout URL that Google returns to you - If your request contains valid XML, Google will return a checkout-redirect response. This message identifies the Google Checkout URL where the buyer can complete the order. The following XML shows a sample checkout-redirect response.

      <?xml version="1.0" encoding="UTF-8"?>
      <checkout-redirect xmlns="http://checkout.google.com/schema/2"
         serial-number="981283ea-c324-44bb-a10c-fc3b2eba5707">
        <redirect-url>
          https://checkout.google.com/view/buy?o=shoppingcart&shoppingcart=8572098456
        </redirect-url>
      </checkout-redirect>
      

      Note: The URL may include an ampersand (&) character, encoded as &amp;. Your code should properly decode this character so that the URL to which you redirect the buyer contains only the text "&" and not "&amp;".

    5. Redirect the buyer to the Google Checkout URL - Send a HTTP 302 response to the HTTP request that you received when the buyer clicked the Google Checkout button. The response needs to redirect the buyer to the HTML-decoded URL that you received in Step iv.

Step 8. Test your implementation

  1. To test your Google Checkout implementation, send requests using the sandbox settings specified in Step 7.

  2. Log into your sandbox buyer account (http://code.google.com/apis/checkout/developer/Google_Checkout_Basic_HTML_Sandbox.html#Create_Sandbox_Accounts) and place a complete, end-to-end order. Then log into your sandbox merchant account (http://code.google.com/apis/checkout/developer/Google_Checkout_Basic_HTML_Sandbox.html#Create_Sandbox_Accounts) and view the order in the Merchant Center.

  3. Checklist:
    • You can successfully post a cart
    • Your prices are correct
    • Your quantities are correct
    • Your items' names and descriptions are correct
    • Your taxes are calculated correctly
    • Your shipping is calculated correctly
    • Review the information you entered in your merchant account to ensure it is correct, such as the contact email address (which is not confirmed)
    • Check that Google Checkout-hosted coupons are calculated correctly
    • Your Google Checkout integration must allow the buyer to use the browser's Back button during the Google Checkout process, which is a requirement of the Google Checkout program (see Google Checkout Program Policies and Guidelines (http://checkout.google.com/seller/policies.html#4), section 4e)
  4. Note: If you are signed in as a buyer to a production Google Checkout account (not a sandbox account), you should test only up to clicking the Google Checkout Button and viewing the "Place order" page. Clicking the "Place Order" button in production will create a real order. We recommend that you use the sandbox testing environment to place any and all test orders.

    Also, please note that merchants are not permitted to make test purchases from themselves using their own accounts. Rather, you'll need to create a separate buyer account from the merchant account created.

Step 9. Review the policy checklist

    To ensure a positive, consistent experience for your customers, please ensure that your site complies with the Google Checkout API integration checklist (https://checkout.google.com/support/sell/bin/answer.py?answer=72125&query=integration&topic=&type=). EXTRA: Google Checkout Launch Checklist (http://code.google.com/apis/checkout/developer/Google_Checkout_Basic_HTML_Launch_Checklist.html) The checklist provides guidelines for Google Checkout button placement, the checkout order flow and branding.

Step 10. Push Checkout live

  1. If you've been using the sandbox, you need to make the following changes (as shown in the interactive code demo of Step 3):

    1. Change sandbox URL "https://sandbox.google.com/checkout" to production URL "https://checkout.google.com" in these places:

      • For all forms: <form action=URL>
      • For all POST URLs
      • For Google Checkout Buttons (such as <input src=URL>)
    2. Change the sandbox Merchant ID to your production Merchant ID from Step 1D.

      • In HTML forms: <form action=URL>
      • For all POST URLs
      • In all Google Checkout button URLs.
  2. Once you're sure you can fulfill orders, go ahead and push your site live.

    Note: Google Checkout buttons will remain on your website unless you edit your website's HTML to remove them. To avoid buyer confusion, please ensure you can fulfill orders before placing Google Checkout buttons on your website, and remove Google Checkout buttons from your site if you don't intend to fulfill orders any longer.

You're done integrating Google Checkout with your custom cart!

    Congratulations!  You have finished Part I. Now you can quickly and easily sell items!

    Next you can move on to Part II, where you receive, charge, ship, and get paid for those orders.

Part II: Start processing orders

    You have two options, which you can compare at Checkout Order Processing: Which Option Is Best for Me? (http://code.google.com/apis/checkout/developer/Google_Checkout_Comparison_Part_II.html):

    • Checkout Merchant Center (http://code.google.com/apis/checkout/developer/Google_Checkout_Merchant_Center.html) — use to start receiving orders, charging them against credit and debit cards, shipping orders, and marking them as shipped.
    • Custom Order Processing (http://code.google.com/apis/checkout/developer/Google_Checkout_Comparison_Part_II.html#custom_processing) — use if you already have an order processing system that you would like to integrate Google Checkout with.

Getting paid

    After a buyer has placed an order, you have shipped it to them and charged their card, Google then pays you that amount minus a transaction fee. To find out about payment prerequisites and schedules, see: