Paypal Curl redirecting Issue - php

This is regarding paypal through Curl. I am trying to access paypal by using below code. The code is working fine in one server. After moving this code to live server, getting the below error. Can anybody tell me the solution for this.
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$version = urlencode('76.0');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
Error:
SetExpressCheckout failed: Unknown SSL protocol error in connection to api-3t.sandbox.paypal.com:443 (35)

Can you set curl_setopt($ch, CURLOPT_SSLVERSION, 3);?

curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
I inserted this line in my code
Did you try this alternative ?

Related

CURL function returns Erron Number: 56 Error String:Received HTTP code 406 from proxy after CONNECT

The purpose of this CURL is to generate a token for the user. If the token is returned correctly, then the user can be able to access all the menus. If not, the user will get a logout from the application.
$ch = curl_init();'
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, 'Proxy IP');
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$result = curl_exec($ch);
What I am missing here??
NOTE: The server I am connecting to is in the AWS cloud, and we already have a server which is outside the cloud, and the curl is working fine and the generated token is receiving. I am not sure what the problem here is.

PHPcURL Error (60): SSL certificate issues: unable to get local issuer certificate

I am doing an api call which is seemingly throwing some errors. So basicall my script is doing a SOAP API post call using cURL and it throws an error that (60): SSL certificate problem: unable to get local issuer certificate
I have tried
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
but its not working.
I have also tried the following:
$ch = curl_init(); // initialize curl handle
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, "GeoTrustGlobalCA.crt");
curl_setopt($ch, CURLOPT_URL, $ENDPOINT);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
//curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//curl_setopt($ch, CURLOPT_PORT, 80);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Data received. To complete this transaction, enter your Bonga PIN on your handset. if you don't have one dial *126*5# for instructions\n";
echo $data;
}
curl_close($ch);
Nothing seems to be working. Any workarounds? Btw the $ENDPOINT is https://safaricom.co.ke
The site has several errors, like mismatch of the name (should be www.safaricom.co.ke
not safaricom.co.ke) and also an incomplete certificate chain and additionally a very insecure setup. No wonder the validation fails. Some browsers work when the correct name was used because they work around missing chain certificates. Other clients (like curl) and most mobile browsers will not work because they expect the site to be properly set up.
For detailed information see the SSLabs report.

cURL alternative; cURL not supported and I will not be able to enable it

I've finished my university project from home using a WAMP server. I use a cUrl command when processing a paypal payment. Now I'm copying the project to the university servers I've found that cURL is not supported. Is there a work around for this code?
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);

unable to execute an url through curl

I am unable to execute an URL through curl. But if simply run the query thrugh browser, its working fine. My code is like:
$xmlData = "<Leads><row no='1'><FL val='First Name'>".$new_fname."</FL><FL val='Last Name'>".$new_lname."</FL><FL val='Email'>".$new_email."</FL><FL val='Phone'>".$new_ph_no."</FL></row></Leads>";
$xmlData = htmlentities($xmlData);
$ch = curl_init("https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&authtoken=XXX&scope=crmapi&xmlData=".$xmlData);
curl_setopt($ch, CURLOPT_VERBOSE, 1);//standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);// Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'rsa_rc4_128_sha'); //for godaddy server patch
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, 1);//Regular post
$response = curl_exec($ch);
curl_close($ch);
could you please let me know where is the issue?
Thanks in advance.
The following code should work:
$ch = curl_init("https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&authtoken=XXX&scope=crmapi&xmlData=".$xmlData);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// deactivate certificate checking
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, 1);//Regular post
$response = curl_exec($ch);
if(!$response) {
echo curl_error($ch), PHP_EOL;
}
curl_close($ch);
After discussion comments I realized that the problem is, that you haven't installed the Thawte ssl certificate on your system. You have two options:
Install the certificates
Disable certificate checking using CURLOPT_VERIFYPEER = FALSE
I've used the second approach in my example just to show how to make your code working. For a production system I would advice you to install the certificates.

DoDirectPayment failed: couldn't connect to host(7)

I am using the sample code of paypal in php from
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_code
but whenever i am running this sample code i am getting this error.
"DoDirectPayment failed: couldn't connect to host(7)"
I have no clue what's the problem.
Note: I am using local WAMP server for running this sample.
// Set the curl parameters.
- $ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, " http://username:password#proxyserver.net:port/";);
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // Turn off the server and peer //verification(TrustManager Concept).
curl_setopt($ch,
CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,
CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch,
CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
//The rest of the code from paypal site

Categories