Exemple #1
0
 /**
  * _confirma
  *
  * Faz a parte Server-Side, verificando os dados junto ao PagSeguro
  *
  * @param array $tipoEnvio Array com a configuração gerada
  *                         por {@see Retorno::_tipoEnvio()}
  * @param array $post      Dados vindos no POST do PagSeguro para serem
  *                         verificados
  *
  * @return bool
  * @global string $_retPagSeguroErrNo   Numero de erro do pagseguro
  * @global string $_retPagSeguroErrStr  Texto descritivo do erro do pagseguro
  */
 static function _confirma($tipoEnvio, $post)
 {
     global $_retPagSeguroErrNo, $_retPagSeguroErrStr;
     $spost = RetornoPagSeguro::_preparaDados($post);
     $confirma = false;
     // Usando a biblioteca cURL
     if ($tipoEnvio[0] === 'curl') {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $tipoEnvio[1]);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $spost);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         // Deve funcionar apenas em teste
         if (defined('PAGSEGURO_AMBIENTE_DE_TESTE')) {
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         }
         $resp = curl_exec($ch);
         if (!RetornoPagSeguro::notNull($resp)) {
             curl_setopt($ch, CURLOPT_URL, $tipoEnvio[1]);
             $resp = curl_exec($ch);
         }
         curl_close($ch);
         $confirma = strcmp($resp, 'VERIFICADO') == 0;
         // Usando fsocket
     } elseif ($tipoEnvio[0] === 'fsocket') {
         if (!$tipoEnvio[2]) {
             die("{$_retPagSeguroErrStr} ({$_retPagSeguroErrNo})");
         } else {
             $cabecalho = "POST {$tipoEnvio[1]} HTTP/1.0\r\n";
             $cabecalho .= "Content-Type: application/x-www-form-urlencoded\r\n";
             $cabecalho .= "Content-Length: " . strlen($spost) . "\r\n\r\n";
             $resp = '';
             fwrite($tipoEnvio[2], "{$cabecalho}{$spost}");
             while (!feof($tipoEnvio[2])) {
                 $resp = fgets($tipoEnvio[2], 1024);
                 if (strcmp($resp, 'VERIFICADO') == 0) {
                     $confirma = true;
                     break;
                 }
             }
             fclose($tipoEnvio[2]);
         }
     }
     return $confirma;
 }