Hi,

I'm trying to set up a sandbox environment to implement the google checkout, however it says run this code using telnet.

Command 1:
curl -d '<hello xmlns="http://checkout.google.com/schema/2"/>'
  https://MERCHANT_ID:MERCHANT_KEY@sandbox.google.com/checkout/api/checkout/v2/request/Merchant/MERCHANT_ID

Command 2:
curl -d '<hello xmlns="http://checkout.google.com/schema/2"/>'
  https://MERCHANT_ID:MERCHANT_KEY@checkout.google.com/api/checkout/v2/request/Merchant/MERCHANT_ID

taken from http://code.google.com/apis/checkout/developer/index.html

From what I can see my server does not have telnet so I tried to do it using the cURL functions built into php.

I was unsure how exactly cURL worked so I googled to find a sample script and managed to find one that fits the description perfectly.

<?php
define("MERCHANTID", "0000"); // taken out for security
define("MERCHANTKEY", "0000"); // taken out for security

// production URL
////$strURL = "https://checkout.google.com";
// dev URL
$strURL = "https://sandbox.google.com/checkout";

function GetAuthenticationHeaders(){
        $headers = array();
        $headers[] = "Content-Type: application/xml; charset=UTF-8";
        $headers[] = "Accept: application/xml; charset=UTF-8";
        return $headers;

} 

// cURL ENGINE
$ch = curl_init(); // initialize a cURL session
curl_setopt ($ch, CURLOPT_URL, $strURL . "/api/checkout/v2/request/
Merchant/" . MERCHANTID );
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_HTTPHEADER, GetAuthenticationHeaders());
curl_setopt ($ch, CURLOPT_USERPWD, MERCHANTID . ':' . MERCHANTKEY);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$xyz = curl_exec ($ch);
echo "<pre>" . $xyz . "</pre>";
echo curl_error($ch);
curl_close ($ch);

?> 

according to the integration guide if everything has worked I should get a response similar to this

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

however the output I get after loading the page is
SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Is this an issue with my host (i.e. I dont have a SSL cerificate), a problem with my code, or something I have over looked?

If any one has worked with the google checkout and could advise on this issue it would be much appreciated,

Thanks in advance,
Jon

    Try adding this to your cURL options:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    

      Well that got rid of SSL Certificate Problem now it's kicking this out

      Missing URL component: expected agent:

        I've never run into that error. However, looking at where you set the URL in your curl_setopt() statements, it looks like you have a newline in the middle of the URL (before "Merchant"). If it's not just a copy-and-paste error here, you might want to get rid of that newline.

          Excellent, that got rid of that problem, however I now get

          Error parsing XML; message from parser is: Premature end of file.

            Are you supposed to be sending some XML data as part of your request (e.g.: as POST data)?

              i'm not exactly sure what i'm meant to be sending, the integration guide says the following

              You can use curl (or a similar tool) to verify that your server communicates properly with Google Checkout. To complete this test, enter the following commands on one line each in your terminal window. Replace the MERCHANT_ID and MERCHANT_KEY strings with the Merchant ID and Merchant Key for your Sandbox account. Replace the same strings in command 2 with the Merchant ID and Merchant Key for your Google Checkout merchant account.
              
              Command 1:
              curl -d '<hello xmlns="http://checkout.google.com/schema/2"/>'
                https://MERCHANT_ID:MERCHANT_KEY@sandbox.google.com/checkout/api/checkout/v2/request/Merchant/MERCHANT_ID
              
              Command 2:
              curl -d '<hello xmlns="http://checkout.google.com/schema/2"/>'
                https://MERCHANT_ID:MERCHANT_KEY@checkout.google.com/api/checkout/v2/request/Merchant/MERCHANT_ID
              
              Google Checkout will respond to each command with the <bye> response. If you do not receive this type of response, then Google Checkout did not properly process your request. For example, if you receive an error response, that response should specify the reason that your request failed. If you do not receive a response at all, then your server may be unable to communicate with Google Checkout. The following XML excerpt shows a sample <bye> response:
              
              <?xml version="1.0" encoding="UTF-8"?>
              <bye xmlns="http://checkout.google.com/schema/2"
                 serial-number="c567262a-dd13-4084-b8d3-6ccfbbc69d03" />
              

              like I said, I couldn't find telnet on my host so I just googled to try and find an alternative solution, and this is what I found.

              I may be going about it all the wrong way.

                See if this works, adding these to your curl options:

                $xml = '<hello xmlns="http://checkout.google.com/schema/2"/>';
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($xml));
                

                  Yep, something different every time, lol. Now i'm getting this

                  Error parsing XML; message from parser is: Content is not allowed in prolog.

                    How about...

                    $xml = '<?xml version="1.0"?><hello xmlns="http://checkout.google.com/schema/2"/>';
                    

                      I put it in the middle of the code like this,

                      <?php
                      // cURL ENGINE
                      $ch = curl_init(); // initialize a cURL session
                      
                      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                      curl_setopt ($ch, CURLOPT_URL, $strURL . "/api/checkout/v2/request/Merchant/" . MERCHANTID );
                      curl_setopt ($ch, CURLOPT_HEADER, 0);
                      curl_setopt ($ch, CURLOPT_HTTPHEADER, GetAuthenticationHeaders());
                      
                      $xml = '<?xml version="1.0"?><hello xmlns="http://checkout.google.com/schema/2"/>';
                      curl_setopt($ch, CURLOPT_POST, 1);
                      curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($xml)); 
                      
                      curl_setopt ($ch, CURLOPT_USERPWD, MERCHANTID . ':' . MERCHANTKEY);
                      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                      $xyz = curl_exec ($ch);
                      echo "<pre>" . $xyz . "</pre>";
                      echo curl_error($ch);
                      curl_close ($ch);
                      
                      ?>
                      

                      but I still get the same error, is this correct or does it need to be placed elsewhere?

                        That's what I intended. At this point, if it were me, I'd be downloading the PHP sample code and see if I can either use it directly, or at least find out exactly how they do it.

                          I shall have a look and get back to you with the results.

                          Thanks for your help so far 🙂

                            Write a Reply...