Google Groups Home
Help | Sign in
Recent pages and files
Sending XML messages quickly to Google Checkout    



You can use curl and/or libcurl to send XML messages over HTTPS by posting to the following URL:

https://sandbox.google.com/checkout/cws/v2/Merchant/1234567890/request

(In the above URL the sequence of numbers 123456789 should be replaced by your Merchant ID)


Explanation

What is Curl?

Curl is an open-source command line tool that implements libcurl to communicate with servers that use HTTP and other popular protocols. You can use curl's -d option to send an XML data to post to Google Checkout.

To see if your server is communicating properly with the Sandbox, you can send the hello command. When you post a command to Google Checkout, you must use HTTP Basic Authentication, using your Merchant ID and Merchant Key as username and password.

In HTTP Basic Authentication, you can specify your username and password directly in the URL. (This technique is not supported by all browsers, but it works in curl.) For example, if your Merchant ID is 1234567890 and your Merchant Key is abcd1234, the command would be:

curl -d '<hello/>'
https://1234567890:abcd1234@sandbox.google.com/checkout/cws/v2/Merchant/1234567890/request

(The curl commands in this section are split across two lines for formatting only; you should type each curl command on one line.) Your Merchant ID and Merchant Key are available on the Settings: Integration Center page of the Merchant Center. When you send this command, you should see an output similar to the following:

<?xml version="1.0" encoding="UTF-8"?>
<bye xmlns="http://checkout.google.com/schema/2" serial-number="c567262a-dd13-4084-b8d3-6ccfbbc69d03" />

If you don't get this response, your message did not reach the Sandbox.

You can use curl to send other API XML messages as well, including posting carts. To make it easier to POST complex XML messages, you can put the XML in a file, then use curl's @ option to post the contents of the file, as in this example:

curl -d '@/home/john/test.xml'
https://1234567890:abcd1234@sandbox.google.com/checkout/cws/v2/Merchant/1234567890/request

After you enter a curl command, you'll see the command's immediate response. If you use curl to post carts with the alternative technique, the immediate response includes a checkout-redirect URL which contains an ampersand character encoded as &. To see the cart in your browser, be sure to change the & to an &, then copy the checkout-redirect URL and paste the URL into a web browser.

For more information on curl, see http://curl.haxx.se/.

What is libcurl?

Libcurl is a multi-protocol file transfer library that can be used to implement server-to-server posts programmatically. In order to use libcurl you will have to set up a development environment that supports it. For a list of available bindings and instructions on obtaining and setting up libcurl with your current environment see http://curl.haxxx.se/libcurl/ .

When using libcurl to communicate with the Google Checkout server, you must:

  1. Specify a header array.
  2. Initiate a curl session.
  3. Set your curl session options.
  4. Execute the session.

The following is an example of how to post an XML message from your server to Google Checkout using pseudocode:

Declare a header array
Set the first element of the header array to "Content-type: application/xml; charset=UTF-8"
Set the second element of the header array to "Accept: application/xml; charset=UTF-8"

Initiate a curl session

Set the CURLOPT_URL option to YOUR POST URL
Set the CURLOPT_RETURNTRANSFER option to 1
Set the CURLOPT_USERPWD option to "MERCHANT_ID:MERCHANT_KEY"
Set the CURLOPT_HTTPHEADER option to THE HEADER ARRAY YOU DEFINED ABOVE
Set the CURLOPT_TIMEOUT option to 4
Set the CURLOPT_SSL_VERIFYPEER option to TRUE
Set the CURLOPT_SSL_VERIFYHOST option to 2
Set the CURLOPT_POST option to 1
Set the CURLOPT_POSTFIELDS option to YOUR XML MESSAGE

Execute the curl session returning the server response

Please review the Google Checkout API sample code for specific examples in our supported languages.

Version: 
Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google