oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Build a .NET App for Google Checkout
Pages: 1, 2, 3, 4

Order Processing API

You already have a pretty solid integration at this point. The next logical step would be to let your system tell Google when to charge orders that are ready to ship, so that you won't have to log in to Google, look up the order, and click the Charge button.

Make sure your app references GCheckout.dll and that you import the GCheckout, GCheckout.Util, and GCheckout.OrderProcessing namespaces. Then you can simply do this:

ChargeOrderRequest Req = new ChargeOrderRequest(X, Y, "Sandbox", 1234567890, "USD", 100.00m);
GCheckoutResponse R = X.Send();

Once you replace X and Y with your Merchant Id and Key, the code above will charge $100.00 for order number 1234567890. If it fails, you will either get an exception or R.IsGood will be false. If the latter, R.ErrorMessage will contain a human-readable error message.

There are nine other requests you can send to Google in the same way as you would a ChargeOrderRequest:

  • AddMerchantOrderNumberRequest: Mark a Checkout order with an order number from your order system.
  • AddTrackingDataRequest: Set carrier and tracking number for a shipped order, so your customer can track her order.
  • ArchiveOrderRequest: Remove an order from the Order Inbox in your merchant account.
  • CancelOrderRequest: Cancel an order.
  • DeliverOrderRequest: Mark an order as "Shipped."
  • ProcessOrderRequest: Mark an order as "Processing."
  • RefundOrderRequest: Refund an order fully or in part.
  • SendBuyerMessageRequest: Send an email to the customer.
  • UnarchiveOrderRequest: Put a previously archived order back in the Order Inbox.

Tips and Tricks

I hope to have given you a flavor of what it is like integrating with Google Checkout using the .NET sample code. As you move from the examples above to a full integration with your existing web-based store, here are a few lessons from the field:

  • Read up on the APIs in the Dev Guide. Even if the sample code lifts the abstraction level, you must have a solid understanding of the APIs to build a successful integration.
  • You can add your own custom data to a cart with the "merchant-private-data" field. You can, for example, put cart id, affiliate id, user id, and other things in there that your system needs. Google will send the "merchant-private-data" field back to you as part of the new-order-notification. See the Dev Guide for more details.
  • Log all incoming and outgoing XML. This is especially important when your code processes notifications from Google, because that code runs unattended and you can't see the result directly. Even after you have launched, logging all XML can save hours or days of troubleshooting later.
  • When you log in to your merchant account, click the Settings tab, and then click Integration link, you will see a list called Integration Issues. All errors visible to Google will be logged there. Check it often, and don't launch until your code produces no more errors!
  • When users are on the Google Checkout page, they expect that clicking the Back button in their browser will take them back to your store so they can add more items to their cart. But if they come back to your website the day after placing their order with Checkout, they expect an empty cart. If your system persists carts outside user sessions, it's best to destroy the user's cart when you get the new-order-notification.
  • When a new order is placed, parse the new-order-notification to get the order's contents. Don't try to find the existing cart record in your system and assume that's what's in the order. If you do that, a smart user could add items to the cart in your system (with a second browser window) during the Google Checkout process. They could then receive more items than they paid for.

Final Notes

I believe Google Checkout is good for online shoppers, developers, and merchants. The existing sample code reduces the time it takes to integrate with Checkout, compared to starting from scratch. But that is just the beginning. I would encourage you to visit the websites below, ask questions, reply to the questions of others, discuss, and help improve the open source code. To be done with the day's work at 5 p.m., you should not reinvent the wheel.

Martin Omander works at Google where he helps large merchants integrate with Google Checkout.

Return to the Windows DevCenter.