Esempio n. 1
0
 function testRunFunction()
 {
     $post = $this->post();
     $file = 'file_write_by_test_function';
     @unlink($file);
     RetornoPagSeguro::verifica($post, array('curl', url('/verificar.php')));
     $this->assertTrue(file_exists($file), 'Foi chamada a funcao de retorno automatico');
 }
Esempio n. 2
0
 /**
  * Retorno dos dados feito pelo PagSeguro
  */
 public function obrigadoAction()
 {
     $standard = $this->getStandard();
     # É um $_GET, trate normalmente
     if (!$this->getRequest()->isPost()) {
         $session = Mage::getSingleton('checkout/session');
         $session->setQuoteId($session->getPaypalStandardQuoteId(true));
         /**
          * set the quote as inactive after back from pagseguro
          */
         Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
         /**
          * send confirmation email to customer
          */
         $order = Mage::getModel('sales/order');
         $order->load(Mage::getSingleton('checkout/session')->getLastOrderId());
         if ($order->getId()) {
             $order->sendNewOrderEmail();
         }
         $url = $standard->getConfigData('retorno');
         $this->_redirect($url);
     } else {
         // Vamos ao retorno automático
         if (!defined('RETORNOPAGSEGURO_NOT_AUTORUN')) {
             define('RETORNOPAGSEGURO_NOT_AUTORUN', true);
             define('PAGSEGURO_AMBIENTE_DE_TESTE', true);
         }
         // Incluindo a biblioteca escrita pela Visie
         include_once dirname(__FILE__) . '/retorno.php';
         // Brincanco com a biblioteca
         RetornoPagSeguro::verifica($_POST, false, array($this, 'retornoPagSeguro'));
     }
 }
Esempio n. 3
0
 /**
  * verifica
  *
  * Verifica o tipo de conexão aberta e envia os dados vindos
  * do post
  *
  * @access public
  *
  * @use RetornoPagSeguro::_tipoenvio()
  * @global string $_retPagSeguroErrNo   Numero de erro do pagseguro
  * @global string $_retPagSeguroErrStr  Texto descritivo do erro do pagseguro
  * @param array $post         Array contendo os posts do pagseguro
  * @param bool $tipoEnvio     (opcional) Verifica o tipo de envio do post
  * @return bool
  */
 function verifica($post, $tipoEnvio = false)
 {
     global $_retPagSeguroErrNo, $_retPagSeguroErrStr;
     if ('array' !== gettype($tipoEnvio)) {
         $tipoEnvio = RetornoPagSeguro::_tipoEnvio();
     }
     $spost = RetornoPagSeguro::_preparaDados($post);
     if (!in_array($tipoEnvio[0], array('curl', 'fsocket'))) {
         return false;
     }
     $confirma = false;
     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);
         $resp = curl_exec($ch);
         if (!RetornoPagSeguro::not_null($resp)) {
             curl_setopt($ch, CURLOPT_URL, $tipoEnvio[1]);
             $resp = curl_exec($ch);
         }
         curl_close($ch);
         $confirma = strcmp($resp, 'VERIFICADO') == 0;
     } 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 = strcmp($resp, 'VERIFICADO') == 0;
                     $confirma = true;
                     break;
                 }
             }
             fclose($tipoEnvio[2]);
         }
     }
     if ($confirma && function_exists('retorno_automatico')) {
         $itens = array('VendedorEmail', 'TransacaoID', 'Referencia', 'TipoFrete', 'ValorFrete', 'Anotacao', 'DataTransacao', 'TipoPagamento', 'StatusTransacao', 'CliNome', 'CliEmail', 'CliEndereco', 'CliNumero', 'CliComplemento', 'CliBairro', 'CliCidade', 'CliEstado', 'CliCEP', 'CliTelefone', 'NumItens');
         foreach ($itens as $item) {
             if (!isset($post[$item])) {
                 $post[$item] = '';
             }
             if ($item == 'ValorFrete') {
                 $post[$item] = str_replace(',', '.', $post[$item]);
             }
         }
         $produtos = array();
         for ($i = 1; isset($post["ProdID_{$i}"]); $i++) {
             $produtos[] = array('ProdID' => $post["ProdID_{$i}"], 'ProdDescricao' => $post["ProdDescricao_{$i}"], 'ProdValor' => (double) str_replace(',', '.', $post["ProdValor_{$i}"]), 'ProdQuantidade' => $post["ProdQuantidade_{$i}"], 'ProdFrete' => (double) str_replace(',', '.', $post["ProdFrete_{$i}"]), 'ProdExtras' => (double) str_replace(',', '.', $post["ProdExtras_{$i}"]));
         }
         retorno_automatico($post['VendedorEmail'], $post['TransacaoID'], $post['Referencia'], $post['TipoFrete'], $post['ValorFrete'], $post['Anotacao'], $post['DataTransacao'], $post['TipoPagamento'], $post['StatusTransacao'], $post['CliNome'], $post['CliEmail'], $post['CliEndereco'], $post['CliNumero'], $post['CliComplemento'], $post['CliBairro'], $post['CliCidade'], $post['CliEstado'], $post['CliCEP'], $post['CliTelefone'], $produtos, $post['NumItens']);
     }
     return $confirma;
 }
Esempio n. 4
0
 /**
  * verifica
  *
  * Verifica o tipo de conexão aberta e envia os dados vindos
  * do post
  *
  * @param array $post      Array contendo os posts do pagseguro
  * @param bool  $tipoEnvio (opcional) Verifica o tipo de envio do post
  *
  * @access static
  * @use RetornoPagSeguro::_tipoenvio()
  * @use RetornoPagSeguro::_confirma()
  * @return bool
  */
 static function verifica($post, $tipoEnvio = false, $function = null)
 {
     if ('array' !== gettype($tipoEnvio)) {
         $tipoEnvio = RetornoPagSeguro::_tipoEnvio();
     }
     if (!in_array($tipoEnvio[0], array('curl', 'fsocket'))) {
         return false;
     }
     $confirma = RetornoPagSeguro::_confirma($tipoEnvio, $post);
     if ($confirma) {
         $itens = array('VendedorEmail', 'TransacaoID', 'Referencia', 'TipoFrete', 'ValorFrete', 'Anotacao', 'DataTransacao', 'TipoPagamento', 'StatusTransacao', 'CliNome', 'CliEmail', 'CliEndereco', 'CliNumero', 'CliComplemento', 'CliBairro', 'CliCidade', 'CliEstado', 'CliCEP', 'CliTelefone', 'NumItens');
         foreach ($itens as $item) {
             if (!isset($post[$item])) {
                 $post[$item] = '';
             }
             if ($item == 'ValorFrete') {
                 $post[$item] = str_replace(',', '.', $post[$item]);
             }
         }
         $produtos = array();
         $total = 0;
         for ($i = 1; isset($post["ProdID_{$i}"]); $i++) {
             $produto = self::makeProd($post, $i);
             $produtos[] = $produto;
             unset($produto['ProdID'], $produto['ProdDescricao']);
             // Hack apenas para o Módulo Magento
             $total += $produto['ProdValor'] * $produto['ProdQuantidade'];
         }
         $total += self::convertNumber($post['ValorFrete']);
         if (function_exists('retorno_automatico') and !$function) {
             $function = 'retorno_automatico';
         }
         if ($function) {
             call_user_func($function, $post['Referencia'], $post['StatusTransacao'], $total, $produtos, (object) $post);
         }
     }
     return $confirma;
 }
Esempio n. 5
0
 /**
  * verifica
  *
  * Verifica o tipo de conexão aberta e envia os dados vindos
  * do post
  *
  * @param array $post      Array contendo os posts do pagseguro
  * @param bool  $tipoEnvio (opcional) Verifica o tipo de envio do post
  *
  * @access public
  * @use RetornoPagSeguro::_tipoenvio()
  * @use RetornoPagSeguro::_confirma()
  * @return bool
  */
 function verifica($post, $tipoEnvio = false)
 {
     if ('array' !== gettype($tipoEnvio)) {
         $tipoEnvio = RetornoPagSeguro::_tipoEnvio();
     }
     if (!in_array($tipoEnvio[0], array('curl', 'fsocket'))) {
         return false;
     }
     $confirma = RetornoPagSeguro::_confirma($tipoEnvio, $post);
     if ($confirma && function_exists('retorno_automatico')) {
         $itens = array('VendedorEmail', 'TransacaoID', 'Referencia', 'TipoFrete', 'ValorFrete', 'Anotacao', 'DataTransacao', 'TipoPagamento', 'StatusTransacao', 'CliNome', 'CliEmail', 'CliEndereco', 'CliNumero', 'CliComplemento', 'CliBairro', 'CliCidade', 'CliEstado', 'CliCEP', 'CliTelefone', 'NumItens');
         foreach ($itens as $item) {
             if (!isset($post[$item])) {
                 $post[$item] = '';
             }
             if ($item == 'ValorFrete') {
                 $post[$item] = str_replace(',', '.', $post[$item]);
             }
         }
         $produtos = array();
         for ($i = 1; isset($post["ProdID_{$i}"]); $i++) {
             $produtos[] = self::makeProd($post, $i);
         }
         retorno_automatico($post['Referencia'], $post['StatusTransacao'], (object) $post);
     }
     return $confirma;
 }