Order Processing API

Unlike the Notification API, Checkout's Order Processing API is not initiated by requests from the Checkout system. Instead it is available as a method of updating Checkout order information by making secure HTTP calls to the Checkout servers. It allows your application to issue three types of commands: financial, fulfillment, and archiving.

Financial commands are those that modify an order's financial status. This includes things such as charging an order, refunding all or part of an order, cancelling an order, and reauthorizing a customer's credit card (in cases where it failed initially).

Fulfillment commands include information about an order's fulfillment state, particularly with regard to shipping status. It can also include problems such as backorders and returned items.

Archiving commands are simply housekeeping tools to manage the list of orders displayed in the Google Checkout Merchant Center. This is useful for removing old orders that no longer need your attention. It can also unarchive orders that were previously complete, but now need to be reopened to make changes (for example when an item is returned).

All Order Processing API requests must be sent over SSL connections and use HTTP Basic authentication. The endpoints for Order Processing requests are documented in the Checkout API, but as of this writing they exist at the following URLs (for sandbox and live data, respectively):

https://sandbox.google.com/checkout/api/checkout/v2/request/Merchant/MERCH_ID.

https://checkout.google.com/api/checkout/v2/request/Merchant/MERCH_ID.

The messages you send to these endpoints are represented as XML documents in the format appropriate to the specific command you want to issue. The schemas for these XML documents are well documented and include many customizable tags. It is convenient to use Django's template system to define XML templates for the commands you wish to implement. A full implementation of all the possible Order Processing commands is a very significant undertaking. Here we will demonstrate just the basics of how to get started.

First, it is necessary to discuss how we will make these API calls using SSL and Basic authentication. Python's urllib2 module provides convenient tools to accomplish this task. However, the Order Processing API requires the use of a client-side SSL certificate to secure the API transaction. For this purpose we'll need to build a special urllib2 handler. There are various ways to achieve this, but the easiest is to subclass the default urllib2HTTPSHandler. An example of this approach is demonstrated on the Three Pillars Software blog at http://www.threepillarsoftware.com/soap_client_auth.

You will use the same SSL certificate for these requests that your secure web server uses to secure incoming connections. Securing your e-commerce application is a subject worthy of a book in itself, and it is highly recommended that you research this subject if you're planning to build a Checkout integration to this depth.

Using a custom handler we can create a URL opener like so:

>>> mykey = '/path/to/ssl_key_file'
>>> mycert = '/path/to/ssl_cert_file'
>>> opener = urllib2.build_opener(HTTPSClientAuthHandler(mykey, mycert))
>>> opener.add_handler(urllib2.HTTPBasicAuthHandler())
# add our HTTP Basic Authentication information...
>>> opener.add_password(user=settings.GOOGLE_MERCHANT_ID,
                        passwd=settings.GOOGLE_MERCHANT_KEY)

We can use this opener to send our requests to the Order Processing API. This would generally work by rendering an XML template specific to the command we want to issue, including context data pertaining to the order we want to modify, and then opening a request using our opener object.

# T and C are Django Template and Context objects 
>>> xml_cmd_document = T.render(C)
>>> api_endpoint_url =  'https://checkout.google.com/api/checkout/v2/request/Merchant/ID'
>>> response = opener.open(api_endpoint_url, xml_cmd_document)

As you can see, integrating your e-commerce application to this level with Google Checkout (or any payment system) is a very complex endeavor. It requires knowledge of secure HTTP transactions as well as the Order Processing API and XML. Google provides ample documentation for the entire process in their online documentation. If interested, we recommend starting with the XML API Developer's Guide for checkout processing:

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

One potential implementation strategy for these APIs is to use the web-based Merchant Center for charging and shipping orders, but implement a notification callback so that your application becomes aware of the order status as it moves through the fulfillment process. This way your web application can update the customer as to the status of their order, without any additional work on your part. Your e-commerce tools will know the status of any order because of the Notification API. This avoids the complexity involved in integrating charging and shipping features directly into your application, but still allows you to empower your customers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset