Eldho NewAge
Eldho NewAge

Reputation: 1333

Paypal sandbox CURL execution - " SSL connect error "

I am getting "SSL connection error" as the response of thee below CURL execution for a PHP live website.

$ch     = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');

$header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  
$header .="Connection: close\r\n\r\n";  
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if( !($res = curl_exec($ch)) ) {
    curl_close($ch); // SSL connection Error
}

I tried both Live and sandbox URLs. But the error is same.

I tried by changing the CURL params like this as some forums was saying.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_SSLVERSION, 6); 

But no luck :( .

$req is the result of below code.

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}

POST parameter are correct, I'm sure about it.

curl_getinfo is giving the below result.

[url] => https://www.sandbox.paypal.com/cgi-bin/webscr
[content_type] => 
[http_code] => 0
[header_size] => 0
[request_size] => 1020
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.220374
[namelookup_time] => 1.7E-5
[connect_time] => 0.080843
[pretransfer_time] => 0
[size_upload] => 855
[size_download] => 0
[speed_download] => 0
[speed_upload] => 3879
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0.220472
[certinfo] => Array
    (
    )

[redirect_url] => 

Also, curl_error($ch) is showing "SSL Connection Error". TSL is upgraded already and SSL version is ok.

  curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);

I tried by adding the above line , as this document says .

http://jmsliu.com/3511/paypal-ipn-ssl-connection-error-solution.html

But no luck.

Any help will be appreciated.

Upvotes: 3

Views: 1371

Answers (2)

Eldho NewAge
Eldho NewAge

Reputation: 1333

ISSUE SOLVED!!!

I updated the CURL library and issue has solved .

To check ,

$ php -r '$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://tlstest.paypal.com/"); var_dump(curl_exec($ch));'

On success, PayPal_Connection_OK is printed. On failure, bool(false) will be printed.

Upvotes: 1

Steffen Ullrich
Steffen Ullrich

Reputation: 123260

Site was working perfectly for the last 5 years...

In this case it might be that you are simply running an OpenSSL version which is too old. Paypal requires TLS 1.2 now. TLS 1.2 was added with OpenSSL version 1.0.1 in 03/2012, i.e. about 4 years ago.
For information on how to check which version of OpenSSL you are using see How to check if installed OpenSSL version is >= 0.9.8k.

Upvotes: 1

Related Questions