Cielo Integration By Page Store

Asked

Viewed 2,408 times

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;
}

3 answers

3

I had already understood this and made this amendment, but it still did not resolve.

Searching a lot on the internet, I found an integration post with Pay Pal that reported, that this line of code:

curl_setopt($sessao_curl, CURLOPT_SSLVERSION, 3);

due to a bug in Poodle (I think this is it), it should be changed to

    curl_setopt($sessao_curl, CURLOPT_SSLVERSION, 4);

I made this change and the problem stopped occurring.

In research on this change reported that there is a bug in the new version of SSL validation, so you should use the value 4, because with this value the system does not use the latest version of the certificate evaluation, but the previous one (I think this is it)

I made this change and now it’s working

This information may help those who have the same problem

Thank you for the reply

Abs

1

I went through the same problem, in my case I decided renaming the SSL file that comes in the Cielo integration kit, because in the Curl definition you are using the format that comes in the example of Cielo, which is:

curl_setopt($sessao_curl, CURLOPT_CAINFO, getcwd() ."/ssl/VeriSignClass3PublicPrimaryCertificationAuthority-G5.CRT");

But in the integration kit this file comes with the name VERISI~1.CRT instead of VeriSignClass3PublicPrimaryCertificationAuthority-G5.CRT

Making this update the connections started to be performed normally in my case. I hope it helps!

0


After a lot of time and research I identified that the problem was on this line

CURLOPT_SSLVERSION, 3

In a statement made by Pay Pal the same informed that people who were using this line of code in this way should change to the line below

CURLOPT_SSLVERSION, 4

From what I understood the code 3 validates your certificate using the last existing validation rule and it seems to me that the new version that was released occurred some kind of problem, that could not validate the certificate and returned as invalid certificate.

Because of this they requested to use the code 4, which makes the check but using the latest stable validation version of the system, ie the previous version of the validation code.

By doing this my system started to work perfectly, without any problem and also went through the Cielo approval without problems.

Hint to anyone who is or has been through this problem.

I hope I’ve helped

Abs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.