0

I'm using Big Commerce as an off-the-shelf shopping cart product. In other words, I don't have access to any server-side code for the shopping cart. To integrate it with Google Checkout, it provides the following URL to use as the API Callback URL for Google Checkout:

https://store.example.com/googlecheckout/xml.php

However, I need to provide my own API Callback URL: https://www.example.com/order/preprocess.php

So, the idea is to receive the request myself at the second URL, do the things I need to do with the data received, and then pass on that original request to my shopping cart so that it can be alerted to the new Google Checkout order. Here's my code:

    $rawPostData = file_get_contents("php://input");

$headers = array(

    'Content-Type: application/xml; charset=UTF-8',
    'HTTPS: on',
    'HTTP_USER_AGENT: Google Checkout Notification Agent 1.0',
    'HTTP_ACCEPT_ENCODING: gzip',
    'Authorization: Basic myBase64MerchantIdColonKey',
    'Accept: application/xml;charset=UTF-8'

);
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,            "https://store.example.com/googlecheckout/xml.php" );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($ch, CURLOPT_POST,           1 );
    curl_setopt($ch, CURLOPT_POSTFIELDS,     $rawPostData ); 
    curl_setopt($ch, CURLOPT_HTTPHEADER,     $headers); 

    $result = curl_exec ($ch);

I have confirmed that $rawPostData does indeed cointain the XML data I expect. However, the $result of curl_exec is false. The curl code I'm using comes from RAW POST using cURL in PHP.

Any idea why curl_exec is failing? Might there be other parameters in the original request from Google Checkout that I need to include in my curl request? If so, how would I find those?

Community
  • 1
  • 1
maxedison
  • 17,243
  • 14
  • 67
  • 114
  • You might want to try using correct `Content-type` for `XML` as the first step and see what `curl_getinfo();` returns for details of the request failure. – Ranty Dec 10 '12 at 21:19
  • **Disclaimer**: Not a php dev. How about the (basic) authentication details (headers)? If your shopping cart is implementing `XML Notifications`, then it must [authenticate the POST from Google](https://developers.google.com/checkout/developer/Google_Checkout_XML_API_Notification_API_pre25#Receiving_and_Processing_Notifications). – EdSF Dec 10 '12 at 23:31
  • @EdSF - not really relevant. I'm testing right now. I don't need to worry about authenticating the requests yet. I know they're legit. – maxedison Dec 11 '12 at 16:34
  • @maxedison It's not that - I meant if the shopping cart software is *expecting* auth headers and you're *not* forwarding them, then it (should) fail - assuming it (the shopping cart software) is implementing `XML Notifications` correctly.... – EdSF Dec 11 '12 at 17:15
  • @EdSF Thanks! However, curl_exec() is still failing. I have updated my code to show the headers I'm setting. Does it look correct to you (even if you're not a php dev)? – maxedison Dec 11 '12 at 17:53
  • I'll defer the header settings in php to you :) Assuming they're correctly set, yes. Check @Ranty comment on `curl_getinfo()` - am assuming that's how you get more detail on the failure. The only other thing I can think of is that SSL connection is also checked by your shopping cart (that in fact the connection is from Google - aka, it's a Google server talking to it - by verifying the cert details of the SSL connection). – EdSF Dec 11 '12 at 20:28

0 Answers0