4
I have a problem that I have tried to solve in several ways, but so far nothing and so I decided to come here.
I am implementing the Gateway Cielo’s payment solution, the By Page Store, where the user performs the insertion of payment data in my own store, and then an XML is generated for Cielo, and the whole process takes place.
I downloaded the Cielo Integration Kit, where it comes with a model store, and activated it in my development environment, and it worked perfectly, I just had to change the following lines:
curl_setopt($sessao_curl, CURLOPT_CAINFO, getcwd() ."/ssl/VeriSignClass3PublicPrimaryCertificationAuthority-G5.CRT");
curl_setopt($sessao_curl, CURLOPT_SSLVERSION, 1);
The first line informs where the certificate, provided by Cielo, is in my directory and the second line the version of the certificate.
Situation
When I run the system on my machine, calling the Cielo type-approval environment, the whole process takes place correctly and without any problem.
However, when I put this code in the client’s approval environment, and I try to process, the system creates XML correctly, but at the moment of making the connection to the Cielo environment, returns the following error
Operation timed out after 0 milliseconds with 0 out of 0 bytes received
That is, the system can not establish the connection with the Cielo server to send XML, the problem is that I do not know if it is at the time of sending or returning XML.
I wonder if anyone has ever been through this problem, if there is any kind of release required to do on the server, PHP version, etc.
Below is the code that connects to the Cielo server.
require 'errorHandling.php';
require_once 'pedido.php';
require_once 'logger.php';
define('VERSAO', "1.1.0");
session_start();
if(!isset($_SESSION["pedidos"]))
{
$_SESSION["pedidos"] = new ArrayObject();
}
// CONSTANTES
define("ENDERECO_BASE", "https://qasecommerce.cielo.com.br");
define("ENDERECO", ENDERECO_BASE."/servicos/ecommwsec.do");
define("LOJA", "0000000");
define("LOJA_CHAVE", "xxxxxxxxx");
define("CIELO", "0000000");
define("CIELO_CHAVE", "xxxxxxxxx");
// Envia requisição
function httprequest($paEndereco, $paPost){
$sessao_curl = curl_init();
curl_setopt($sessao_curl, CURLOPT_URL, $paEndereco);
curl_setopt($sessao_curl, CURLOPT_FAILONERROR, true);
// CURLOPT_SSL_VERIFYPEER
// verifica a validade do certificado
curl_setopt($sessao_curl, CURLOPT_SSL_VERIFYPEER, true);
// CURLOPPT_SSL_VERIFYHOST
// verifica se a identidade do servidor bate com aquela informada no certificado
curl_setopt($sessao_curl, CURLOPT_SSL_VERIFYHOST, 2);
// CURLOPT_SSL_CAINFO
// informa a localização do certificado para verificação com o peer
curl_setopt($sessao_curl, CURLOPT_CAINFO, getcwd() ."/ssl/VeriSignClass3PublicPrimaryCertificationAuthority-G5.CRT");
curl_setopt($sessao_curl, CURLOPT_SSLVERSION, 1);
// CURLOPT_CONNECTTIMEOUT
// o tempo em segundos de espera para obter uma conexão
curl_setopt($sessao_curl, CURLOPT_CONNECTTIMEOUT, 10);
// CURLOPT_TIMEOUT
// o tempo máximo em segundos de espera para a execução da requisição (curl_exec)
curl_setopt($sessao_curl, CURLOPT_TIMEOUT, 40);
// CURLOPT_RETURNTRANSFER
// TRUE para curl_exec retornar uma string de resultado em caso de sucesso, ao
// invés de imprimir o resultado na tela. Retorna FALSE se há problemas na requisição
curl_setopt($sessao_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($sessao_curl, CURLOPT_POST, true);
curl_setopt($sessao_curl, CURLOPT_POSTFIELDS, $paPost );
$resultado = curl_exec($sessao_curl);
if (!$resultado)
$curl_error = curl_error($sessao_curl); // Capturo o erro ANTES de fechar
curl_close($sessao_curl);
if (!$resultado)
echo "<br><font size=6>" . $curl_error ;
if ($resultado)
{
return $resultado;
}
else
{
return curl_error($sessao_curl);
}
}
// Monta URL de retorno
function ReturnURL()
{
$pageURL = 'http';
if ($_SERVER["SERVER_PORT"] == 443) // protocolo https
{
$pageURL .= 's';
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"]. substr($_SERVER["REQUEST_URI"], 0);
}
// ALTERNATIVA PARA SERVER_NAME -> HOST_HTTP
$file = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
$ReturnURL = str_replace($file, "retorno.php", $pageURL);
return $ReturnURL;
}