Fórum OpenCart Brasil

Por um e-commerce livre, confiável e profissional

Suporte para extensões de Formas de Pagamento
#39005
Olá pessoal.

Vou reportar um erro que parece ser comum do Mercado Pago, porém ainda não encontrei a solução.

Pesquisei muito, tentei consertar, mas infelizmente não tenho conhecimento em PHP.

É o seguinte.

O cliente realiza a compra e tudo ocorre normal, é aberto o light box com os dados para efetuar o login e escolher a forma de pagamento. No caso, foi escolhido boleto bancário. É gerado o boleto e é confirmado a compra.

Nisso, o conteúdo do light box muda e aparece um link para voltar ao site (onde é feito a confirmação). Ao clicar neste link, aparece a mensagem de erro:
Código: Selecionar todos
Notice: Undefined index: order_id in /home/soareste/public_html/apegosedesapegos.com.br/loja/catalog/controller/payment/mercadopago2.php on line 138Warning: Cannot modify header information - headers already sent by (output started at /home/soareste/public_html/apegosedesapegos.com.br/loja/index.php:106) in /home/soareste/public_html/apegosedesapegos.com.br/loja/vqmod/vqcache/vq2-system_engine_controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/soareste/public_html/apegosedesapegos.com.br/loja/index.php:106) in /home/soareste/public_html/apegosedesapegos.com.br/loja/vqmod/vqcache/vq2-system_engine_controller.php on line 29
Meu site é http://www.apegosedesapegos.com.br/loja

Será que alguém pode ajudar?

O suporte do Mercado Pago é horrível..

Qualquer dúvida estou a disposição.

Att,

Alexandre Soares
#39031
RicardoCostaTW escreveu:Não deve estar a mandar a variável do controlador do módulo. Pode colocar o código do controlador e do /mercadopago2.php aqui para eu ver http://pastebin.com/ ?
Segue o mercadopago2.php:
Código: Selecionar todos
<?php




class ControllerPaymentMercadopago2 extends Controller {

	private $error;
        public  $sucess = true;
	private $order_info;
        private $message;

	protected function index() {

                $this->data['button_confirm'] = $this->language->get('button_confirm');
		$this->data['button_back'] = $this->language->get('button_back');
                    
		if ($this->config->get('mercadopago2_country')) {
		    $this->data['action'] = $this->config->get('mercadopago2_country');
		}

		$this->load->model('checkout/order');

		$this->language->load('payment/mercadopago2');

		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

		//Cambio el código ISO-3 de la moneda por el que se les ocurrio poner a los de mercadopago2!!!
		                            
               switch($order_info['currency_code']) {
			case"ARS":
				$currency = 'ARS';
				break;
                        case"ARG":
				$currency = 'ARG';
				break;    
                        case"BRA":
				$currency = 'BRL';
				break;     
			case"BRL":
				$currency = 'BRL';
				break;
                        case"REA":
				$currency = 'BRL';
				break;
			case"MXN":
				$currency = 'MEX';
				break;
			case"CLP":
				$currency = 'CHI';
				break;
			default:
				$currency = 'USD';
				break;
		}
                
                 
            
		$currencies = array('ARS','BRL','MEX','CHI');
		if (!in_array($currency, $currencies)) {
			$currency = '';
			$this->data['error'] = $this->language->get('currency_no_support');
		}

		

		
		$products = '';
		
		foreach ($this->cart->getProducts() as $product) {
    		$products .= $product['quantity'] . ' x ' . $product['name'] . ', ';
                }
                $allproducts = $this->cart->getProducts();
                $firstproduct = reset($allproducts);
                
                // dados 2.0
                
                $totalprice = $order_info['total'] * $order_info['currency_value'];                   
            
              	$this->id = 'payment';

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mercadopago2.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/payment/mercadopago2.tpl';
		} else {
			$this->template = 'default/template/payment/mercadopago2.tpl';
		}
                
                $this->data['server'] = $_SERVER;
                $this->data['debug'] = $this->config->get('mercadopago2_debug');
                
                // get credentials 
                
                $client_id     = $this->config->get('mercadopago2_client_id');
		$client_secret = $this->config->get('mercadopago2_client_secret');
                $url           = $this->config->get('mercadopago2_url');
                // urls
                
                // array to create preference key
                          
               $carrinho = array(
               "external_reference" => $order_info['order_id'] ,// seu codigo de referencia, i.e. Numero do pedido da sua loja 
               "currency" => $currency ,// string Argentina: ARS (peso argentino) ó USD (Dólar estadounidense); Brasil: BRL (Real).
               "title" => $firstproduct['name'],  //string
               "description" => $firstproduct['quantity'] . ' x ' . $firstproduct['name'], // string
               "quantity" =>  1,// int 
               "image" => HTTP_SERVER . 'image/' . $firstproduct['image'],  // Imagem, string
               "amount" => round($totalprice, 2), //decimal
               "payment_firstname" => $order_info['payment_firstname'],// string
               "payment_lastname" =>  $order_info['payment_lastname'],// string
               "email" =>    $order_info['email'],// string
               "pending" =>   $url   . '/index.php?route=payment/mercadopago2/callback', // string
               "approved" =>  $url   . '/index.php?route=payment/mercadopago2/callback'  // string
               );

               // methods para excluir
               $exclude = $this->config->get('mercadopago2_methods');  // string
                
               
               $mp = new Shop($client_id,$client_secret);
                       
               if($mp->GetCheckout($carrinho,$exclude) != ''){
                   $this->data['link'] = $mp->GetCheckout($carrinho,$exclude);
               } else {
                   $this->data['error'] = $mp->getError();
               }
                   
                 $this->render();
            
       }
     
   

	public function callback() {
		
              $order_id = $this->request->get['order_id'];
              $this->load->model('checkout/order');		      
              $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('mercadopago2_order_status_id'));
		
	      $this->redirect(HTTP_SERVER . 'index.php?route=checkout/success');
	}
        
        public function retorno() {
            
                 
            if (isset($_REQUEST['id'])) {
            $id = $_REQUEST['id'];
         
            
            $client_id     = $this->config->get('mercadopago2_client_id');
            $client_secret = $this->config->get('mercadopago2_client_secret');

            $checkdata = New Shop($client_id,$client_secret);

            $dados = $checkdata->GetStatus($id);
            
                                 
            $order_id = $dados['collection']['external_reference'];
            $order_status = $dados['collection']['status'];
              
            $this->load->model('checkout/order');
            $order = $this->model_checkout_order->getOrder($order_id);
            
            
            
             if ($order['order_status_id'] == '0') {
	      $this->model_checkout_order->confirm($order_id, $this->config->get('mercadopago_order_status_id'));
             }
             
             switch ($order_status) {
             case 'approved':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_completed'));   
             break;
             case 'pending':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending'));    
             break;    
             case 'in_process':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_process'));       
             break;    
             case 'reject':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_rejected'));      
             break;    
             case 'refunded':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_refunded'));      
             break;    
             case 'cancelled':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_cancelled'));      
             break;    
             case 'in_metiation':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_in_mediation'));    
             break;
             default:
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending'));      
             }
           
           }
      
        }
        
      
}

class mercadopago {

    
     
        public     $accesstoken;
        protected  $client_id;
        protected  $client_secret;
        public     $erro;
        protected  $date;
        protected  $expired;


        
       ///// function just to debug the code if is needed
        
        function debug($error){
               $this->erro = $error ;
        }
        
       
       
         ///// function to post the datas
         public function DoPost($fields,$url,$heads,$codeexpect,$type,$method){
                    
                    // buld the post data follwing the api needs
                 if($type == 'json'){
                 $posts = json_encode($fields);
                             

                    } else if ($type == 'none') {
                    $posts = $fields;
                    } else {
                    $posts = http_build_query($fields);    
                    }
                    
                                    
                  
                    // change the curl method follwing the api needs
                    switch ($method):
                    case 'get':
                    $options = array(
                               CURLOPT_RETURNTRANSFER => '1',
                               CURLOPT_HTTPHEADER => $heads,
                               CURLOPT_SSL_VERIFYPEER => 'false',
                               CURLOPT_URL => $url,
                               CURLOPT_POSTFIELDS => $posts ,
                               CURLOPT_CUSTOMREQUEST => "GET"
                            );
                    break;
                    case 'put':
                      $options = array(
                                CURLOPT_RETURNTRANSFER => 1,
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "PUT",
                                CURLOPT_HEADER => 1
                             );  
                    break;
                    case 'post':
                         $options = array(
                                CURLOPT_RETURNTRANSFER => '1',
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "POST",
                             ); 
                    break;
                    case 'delete':
                        $options = array(
                                CURLOPT_RETURNTRANSFER => '1',
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "DELETE",
                             ); 
                        
                    break;      
                    default:
                            $options = array(
                               CURLOPT_RETURNTRANSFER => '1',
                               CURLOPT_HTTPHEADER => $heads,
                               CURLOPT_SSL_VERIFYPEER => 'false',
                               CURLOPT_URL => $url,
                               CURLOPT_POSTFIELDS => $posts ,
                               CURLOPT_CUSTOMREQUEST => "GET"
                            );
                    break;
                    endswitch;
  
                // do a curl call
                $call = curl_init();
                curl_setopt_array($call,$options);
                // execute the curl call
                $dados = curl_exec($call);
                // get the curl statys
                $status = curl_getinfo($call);
                // close the call
                curl_close($call);
                // check to see if the call was succesful 
                if ($status['http_code'] != $codeexpect){
                $this->debug($dados);
                return false;
                } else {
               // change the json retur to a php array and return it
                return json_decode($dados,true);        
                } 
        
        }
        
        public function getAccessToken(){
            
            $data = getdate();
            $time = $data[0];
             
            
            // verifica se já existe accesstoken valido, caso exista, retorna o accesstoken
            if(isset($this->accesstoken) && isset($this->date)){          
                $timedifference = $time - $this->date;
                if($timedifference < $this->expired){
                return $this->accesstoken;
                }
           }
            // get the clients variables
                $post = array(
                    'client_id' => $this->client_id,
                    'client_secret' => $this->client_secret,
                    'grant_type' => 'client_credentials'
                 );
                // set the header
                $header = array('Accept: application/json','Content-Type: application/x-www-form-urlencoded');
                // set the url to get the access token
                $url = 'https://api.mercadolibre.com/oauth/token';
                // call the post function. expection 200 as return
                $dados = $this->DoPost($post,$url,$header,'200','post','post');
                // set the access token
                if($dados['access_token']){
                $this->accesstoken = $dados['access_token'];
                }
                 // guarta o hoarario, prazo de expiraç?o e returna o access token
                $this->date = $time;
                $this->expired = $dados['expires_in'];
                return $dados['access_token'];
       }
     
       
    
}
Class Shop extends MercadoPago {
        
       // do the client authentication
      public function __construct($client,$secret){
                   $this->client_id = $client;
                   $this->client_secret = $secret; 
       }
       
       
       
     public function GetMethods($country_id) {
       
        $url = "https://api.mercadolibre.com/sites/" . $country_id .  "/payment_methods";
        $header = null;   
        $methods = $this->DoPost(null,$url,$header,'200','none','get');
        return $methods;
    
          }

      // Generate the botton
      public function GetCheckout($data,$excludes){
                
            if($excludes != ''){
                
                 $methods_excludes = preg_split("/[\s,]+/", $excludes); 
                 foreach ($methods_excludes as $exclude ){
                 $excludemethods[] = array('id' => $exclude);     
                 }
                
                 
                $opt = array(
                "external_reference" => $data['external_reference'],
                "items" => array(
                    array ("id" => $data['external_reference'], // updated
                    "title" => $data['title'],
                    "description" => $data['quantity'] . ' x ' . $data['title'],
                    "quantity" => 1,
                    "unit_price" => round($data['amount'], 2),
                    "currency_id" => $data['currency'],
                    "picture_url"=> $data['image'],
                    )),
                    "payer" => array(
                     "name" => $data['payment_firstname'],
                     "surname" => $data['payment_lastname'],
                     "email" => $data['email']
                    ),
                   "back_urls" => array(
                   "pending" => $data['pending'],
                   "success" => $data['approved']
                   ),           
                   "payment_methods" => array(
                   "excluded_payment_methods" => $excludemethods
                   )
                );
            }else{
                $opt = array(
                "external_reference" => $data['external_reference'],
                "items" => array(
                    array ("id" => $data['external_reference'], // updated
                    "title" => $data['title'],
                    "description" => $data['quantity'] . ' x ' . $data['title'],
                    "quantity" => 1,
                    "unit_price" => round($data['amount'], 2),
                    "currency_id" => $data['currency'],
                    "picture_url"=> $data['image'],
                    )),
                    "payer" => array(
                     "name" => $data['payment_firstname'],
                     "surname" => $data['payment_lastname'],
                     "email" => $data['email']
                    ),
                   "back_urls" => array(
                   "pending" => $data['pending'],
                   "success" => $data['approved']
                   ),  
                );
                
            }
            
             

            $this->getAccessToken(); 
            if(isset($this->accesstoken)){
            $url = 'https://api.mercadolibre.com/checkout/preferences?access_token=' . $this->accesstoken;
            $header = array('Content-Type:application/json','Accept: application/json');
            $dados = $this->DoPost($opt,$url,$header,'201','json','post');
            if(isset($dados['init_point'])){
            $link = $dados['init_point'];
            return $link;
            }
            return false;
            }
            return false;
      }
      
           

      public function GetStatus($id){
          
            $this->getAccessToken(); 
            $url = "https://api.mercadolibre.com/collections/notifications/" . $id . "?access_token=" . $this->accesstoken;
            $header = array('Accept: application/json', 'Content-Type: application/x-www-form-urlencoded');
            $retorno = $this->DoPost($opt=null,$url,$header,'200','none','post');
            return $retorno;
                   
      }
      
      public function getError(){
          if ($this->erro != '' && $this->erro != null){
             return $this->erro;
          }
      }
      

} 


   
?>
Qual seria o controlador?

Muito obrigado pela ajuda!!!
#39054
RicardoCostaTW escreveu:Estive agora a testar na sua loja. Pode por o código do ficheiro .tpl do mercado pago? deve estar em catalog/view/theme/leisure/template/module/

Acho que já sie o erro
Primeiramente, muito obrigado pela ajuda!

Segue o mercadopago2.tpl:
Código: Selecionar todos
<?php  if (isset($error)) { ?>
<div class="warning"><?php
      
      if($debug == 1){
      echo '<strong>MercadoPago fails to connecet, and debug mode is on !!.<br /> Check the erros below and for security reasons turn it off after solve the problem:</strong><br />' ; 
      echo '<pre>'; print_r($error); echo '</pre><br />';
      } else {
      echo '<strong>Sorry...MercadoPago fail to connect.<br /> If you are the store owner, turn on debug mode to get more details about the reason</strong><br />' ; 
      }
      ?>

</div>
<?php  } else {

  // fecha verficação de status da autenticação
?>
         
<div class="right">
<a href="<?php echo $link; ?>" name="MP-payButton" class="blue-l-rn-ar" style="float:right;">Pagar</a>
<script type="text/javascript" src="https://www.mercadopago.com/org-img/jsapi/mptools/buttons/render.js" />
</div>
<?php  ;} ?>
Abs,
#39057
Coloca esse código no controller
Código: Selecionar todos
<?php




class ControllerPaymentMercadopago2 extends Controller {

   private $error;
   public  $sucess = true;
   private $order_info;
   private $message;
   private $order_id;

   protected function index() {

                $this->data['button_confirm'] = $this->language->get('button_confirm');
      $this->data['button_back'] = $this->language->get('button_back');
                    
      if ($this->config->get('mercadopago2_country')) {
          $this->data['action'] = $this->config->get('mercadopago2_country');
      }

      $this->load->model('checkout/order');

      $this->language->load('payment/mercadopago2');
		
	  $this->order_id = $this->session->data['order_id'];
		
      $order_info = $this->model_checkout_order->getOrder($this->order_id);
	  

      //Cambio el código ISO-3 de la moneda por el que se les ocurrio poner a los de mercadopago2!!!
                                  
               switch($order_info['currency_code']) {
         case"ARS":
            $currency = 'ARS';
            break;
                        case"ARG":
            $currency = 'ARG';
            break;    
                        case"BRA":
            $currency = 'BRL';
            break;     
         case"BRL":
            $currency = 'BRL';
            break;
                        case"REA":
            $currency = 'BRL';
            break;
         case"MXN":
            $currency = 'MEX';
            break;
         case"CLP":
            $currency = 'CHI';
            break;
         default:
            $currency = 'USD';
            break;
      }
                
                 
            
      $currencies = array('ARS','BRL','MEX','CHI');
      if (!in_array($currency, $currencies)) {
         $currency = '';
         $this->data['error'] = $this->language->get('currency_no_support');
      }

      

      
      $products = '';
      
      foreach ($this->cart->getProducts() as $product) {
          $products .= $product['quantity'] . ' x ' . $product['name'] . ', ';
                }
                $allproducts = $this->cart->getProducts();
                $firstproduct = reset($allproducts);
                
                // dados 2.0
                
                $totalprice = $order_info['total'] * $order_info['currency_value'];                   
            
                 $this->id = 'payment';

      if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mercadopago2.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/payment/mercadopago2.tpl';
      } else {
         $this->template = 'default/template/payment/mercadopago2.tpl';
      }
                
                $this->data['server'] = $_SERVER;
                $this->data['debug'] = $this->config->get('mercadopago2_debug');
                
                // get credentials 
                
                $client_id     = $this->config->get('mercadopago2_client_id');
      $client_secret = $this->config->get('mercadopago2_client_secret');
                $url           = $this->config->get('mercadopago2_url');
                // urls
                
                // array to create preference key
                          
               $carrinho = array(
               "external_reference" => $order_info['order_id'] ,// seu codigo de referencia, i.e. Numero do pedido da sua loja 
               "currency" => $currency ,// string Argentina: ARS (peso argentino) ó USD (Dólar estadounidense); Brasil: BRL (Real).
               "title" => $firstproduct['name'],  //string
               "description" => $firstproduct['quantity'] . ' x ' . $firstproduct['name'], // string
               "quantity" =>  1,// int 
               "image" => HTTP_SERVER . 'image/' . $firstproduct['image'],  // Imagem, string
               "amount" => round($totalprice, 2), //decimal
               "payment_firstname" => $order_info['payment_firstname'],// string
               "payment_lastname" =>  $order_info['payment_lastname'],// string
               "email" =>    $order_info['email'],// string
               "pending" =>   $url   . '/index.php?route=payment/mercadopago2/callback', // string
               "approved" =>  $url   . '/index.php?route=payment/mercadopago2/callback'  // string
               );

               // methods para excluir
               $exclude = $this->config->get('mercadopago2_methods');  // string
                
               
               $mp = new Shop($client_id,$client_secret);
                       
               if($mp->GetCheckout($carrinho,$exclude) != ''){
                   $this->data['link'] = $mp->GetCheckout($carrinho,$exclude);
               } else {
                   $this->data['error'] = $mp->getError();
               }
                   
                 $this->render();
            
       }
     
   

   public function callback() {
      
              $order_id = $this->request->get['order_id'];
              $this->load->model('checkout/order');            
              $this->model_checkout_order->confirm($this->order_id, $this->config->get('mercadopago2_order_status_id'));
      
         $this->redirect(HTTP_SERVER . 'index.php?route=checkout/success');
   }
        
        public function retorno() {
            
                 
            if (isset($_REQUEST['id'])) {
            $id = $_REQUEST['id'];
         
            
            $client_id     = $this->config->get('mercadopago2_client_id');
            $client_secret = $this->config->get('mercadopago2_client_secret');

            $checkdata = New Shop($client_id,$client_secret);

            $dados = $checkdata->GetStatus($id);
            
                                 
            $order_id = $dados['collection']['external_reference'];
            $order_status = $dados['collection']['status'];
              
            $this->load->model('checkout/order');
            $order = $this->model_checkout_order->getOrder($order_id);
            
            
            
             if ($order['order_status_id'] == '0') {
         $this->model_checkout_order->confirm($order_id, $this->config->get('mercadopago_order_status_id'));
             }
             
             switch ($order_status) {
             case 'approved':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_completed'));   
             break;
             case 'pending':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending'));    
             break;    
             case 'in_process':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_process'));       
             break;    
             case 'reject':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_rejected'));      
             break;    
             case 'refunded':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_refunded'));      
             break;    
             case 'cancelled':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_cancelled'));      
             break;    
             case 'in_metiation':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_in_mediation'));    
             break;
             default:
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending'));      
             }
           
           }
      
        }
        
      
}

class mercadopago {

    
     
        public     $accesstoken;
        protected  $client_id;
        protected  $client_secret;
        public     $erro;
        protected  $date;
        protected  $expired;


        
       ///// function just to debug the code if is needed
        
        function debug($error){
               $this->erro = $error ;
        }
        
       
       
         ///// function to post the datas
         public function DoPost($fields,$url,$heads,$codeexpect,$type,$method){
                    
                    // buld the post data follwing the api needs
                 if($type == 'json'){
                 $posts = json_encode($fields);
                             

                    } else if ($type == 'none') {
                    $posts = $fields;
                    } else {
                    $posts = http_build_query($fields);    
                    }
                    
                                    
                  
                    // change the curl method follwing the api needs
                    switch ($method):
                    case 'get':
                    $options = array(
                               CURLOPT_RETURNTRANSFER => '1',
                               CURLOPT_HTTPHEADER => $heads,
                               CURLOPT_SSL_VERIFYPEER => 'false',
                               CURLOPT_URL => $url,
                               CURLOPT_POSTFIELDS => $posts ,
                               CURLOPT_CUSTOMREQUEST => "GET"
                            );
                    break;
                    case 'put':
                      $options = array(
                                CURLOPT_RETURNTRANSFER => 1,
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "PUT",
                                CURLOPT_HEADER => 1
                             );  
                    break;
                    case 'post':
                         $options = array(
                                CURLOPT_RETURNTRANSFER => '1',
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "POST",
                             ); 
                    break;
                    case 'delete':
                        $options = array(
                                CURLOPT_RETURNTRANSFER => '1',
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "DELETE",
                             ); 
                        
                    break;      
                    default:
                            $options = array(
                               CURLOPT_RETURNTRANSFER => '1',
                               CURLOPT_HTTPHEADER => $heads,
                               CURLOPT_SSL_VERIFYPEER => 'false',
                               CURLOPT_URL => $url,
                               CURLOPT_POSTFIELDS => $posts ,
                               CURLOPT_CUSTOMREQUEST => "GET"
                            );
                    break;
                    endswitch;
  
                // do a curl call
                $call = curl_init();
                curl_setopt_array($call,$options);
                // execute the curl call
                $dados = curl_exec($call);
                // get the curl statys
                $status = curl_getinfo($call);
                // close the call
                curl_close($call);
                // check to see if the call was succesful 
                if ($status['http_code'] != $codeexpect){
                $this->debug($dados);
                return false;
                } else {
               // change the json retur to a php array and return it
                return json_decode($dados,true);        
                } 
        
        }
        
        public function getAccessToken(){
            
            $data = getdate();
            $time = $data[0];
             
            
            // verifica se já existe accesstoken valido, caso exista, retorna o accesstoken
            if(isset($this->accesstoken) && isset($this->date)){          
                $timedifference = $time - $this->date;
                if($timedifference < $this->expired){
                return $this->accesstoken;
                }
           }
            // get the clients variables
                $post = array(
                    'client_id' => $this->client_id,
                    'client_secret' => $this->client_secret,
                    'grant_type' => 'client_credentials'
                 );
                // set the header
                $header = array('Accept: application/json','Content-Type: application/x-www-form-urlencoded');
                // set the url to get the access token
                $url = 'https://api.mercadolibre.com/oauth/token';
                // call the post function. expection 200 as return
                $dados = $this->DoPost($post,$url,$header,'200','post','post');
                // set the access token
                if($dados['access_token']){
                $this->accesstoken = $dados['access_token'];
                }
                 // guarta o hoarario, prazo de expiraç?o e returna o access token
                $this->date = $time;
                $this->expired = $dados['expires_in'];
                return $dados['access_token'];
       }
     
       
    
}
Class Shop extends MercadoPago {
        
       // do the client authentication
      public function __construct($client,$secret){
                   $this->client_id = $client;
                   $this->client_secret = $secret; 
       }
       
       
       
     public function GetMethods($country_id) {
       
        $url = "https://api.mercadolibre.com/sites/" . $country_id .  "/payment_methods";
        $header = null;   
        $methods = $this->DoPost(null,$url,$header,'200','none','get');
        return $methods;
    
          }

      // Generate the botton
      public function GetCheckout($data,$excludes){
                
            if($excludes != ''){
                
                 $methods_excludes = preg_split("/[\s,]+/", $excludes); 
                 foreach ($methods_excludes as $exclude ){
                 $excludemethods[] = array('id' => $exclude);     
                 }
                
                 
                $opt = array(
                "external_reference" => $data['external_reference'],
                "items" => array(
                    array ("id" => $data['external_reference'], // updated
                    "title" => $data['title'],
                    "description" => $data['quantity'] . ' x ' . $data['title'],
                    "quantity" => 1,
                    "unit_price" => round($data['amount'], 2),
                    "currency_id" => $data['currency'],
                    "picture_url"=> $data['image'],
                    )),
                    "payer" => array(
                     "name" => $data['payment_firstname'],
                     "surname" => $data['payment_lastname'],
                     "email" => $data['email']
                    ),
                   "back_urls" => array(
                   "pending" => $data['pending'],
                   "success" => $data['approved']
                   ),           
                   "payment_methods" => array(
                   "excluded_payment_methods" => $excludemethods
                   )
                );
            }else{
                $opt = array(
                "external_reference" => $data['external_reference'],
                "items" => array(
                    array ("id" => $data['external_reference'], // updated
                    "title" => $data['title'],
                    "description" => $data['quantity'] . ' x ' . $data['title'],
                    "quantity" => 1,
                    "unit_price" => round($data['amount'], 2),
                    "currency_id" => $data['currency'],
                    "picture_url"=> $data['image'],
                    )),
                    "payer" => array(
                     "name" => $data['payment_firstname'],
                     "surname" => $data['payment_lastname'],
                     "email" => $data['email']
                    ),
                   "back_urls" => array(
                   "pending" => $data['pending'],
                   "success" => $data['approved']
                   ),  
                );
                
            }
            
             

            $this->getAccessToken(); 
            if(isset($this->accesstoken)){
            $url = 'https://api.mercadolibre.com/checkout/preferences?access_token=' . $this->accesstoken;
            $header = array('Content-Type:application/json','Accept: application/json');
            $dados = $this->DoPost($opt,$url,$header,'201','json','post');
            if(isset($dados['init_point'])){
            $link = $dados['init_point'];
            return $link;
            }
            return false;
            }
            return false;
      }
      
           

      public function GetStatus($id){
          
            $this->getAccessToken(); 
            $url = "https://api.mercadolibre.com/collections/notifications/" . $id . "?access_token=" . $this->accesstoken;
            $header = array('Accept: application/json', 'Content-Type: application/x-www-form-urlencoded');
            $retorno = $this->DoPost($opt=null,$url,$header,'200','none','post');
            return $retorno;
                   
      }
      
      public function getError(){
          if ($this->erro != '' && $this->erro != null){
             return $this->erro;
          }
      }
      

} 


   
?>
#39075
valdeir2000 escreveu:Coloca esse código no controller
Código: Selecionar todos
<?php




class ControllerPaymentMercadopago2 extends Controller {

   private $error;
   public  $sucess = true;
   private $order_info;
   private $message;
   private $order_id;

   protected function index() {

                $this->data['button_confirm'] = $this->language->get('button_confirm');
      $this->data['button_back'] = $this->language->get('button_back');
                    
      if ($this->config->get('mercadopago2_country')) {
          $this->data['action'] = $this->config->get('mercadopago2_country');
      }

      $this->load->model('checkout/order');

      $this->language->load('payment/mercadopago2');
		
	  $this->order_id = $this->session->data['order_id'];
		
      $order_info = $this->model_checkout_order->getOrder($this->order_id);
	  

      //Cambio el código ISO-3 de la moneda por el que se les ocurrio poner a los de mercadopago2!!!
                                  
               switch($order_info['currency_code']) {
         case"ARS":
            $currency = 'ARS';
            break;
                        case"ARG":
            $currency = 'ARG';
            break;    
                        case"BRA":
            $currency = 'BRL';
            break;     
         case"BRL":
            $currency = 'BRL';
            break;
                        case"REA":
            $currency = 'BRL';
            break;
         case"MXN":
            $currency = 'MEX';
            break;
         case"CLP":
            $currency = 'CHI';
            break;
         default:
            $currency = 'USD';
            break;
      }
                
                 
            
      $currencies = array('ARS','BRL','MEX','CHI');
      if (!in_array($currency, $currencies)) {
         $currency = '';
         $this->data['error'] = $this->language->get('currency_no_support');
      }

      

      
      $products = '';
      
      foreach ($this->cart->getProducts() as $product) {
          $products .= $product['quantity'] . ' x ' . $product['name'] . ', ';
                }
                $allproducts = $this->cart->getProducts();
                $firstproduct = reset($allproducts);
                
                // dados 2.0
                
                $totalprice = $order_info['total'] * $order_info['currency_value'];                   
            
                 $this->id = 'payment';

      if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/mercadopago2.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/payment/mercadopago2.tpl';
      } else {
         $this->template = 'default/template/payment/mercadopago2.tpl';
      }
                
                $this->data['server'] = $_SERVER;
                $this->data['debug'] = $this->config->get('mercadopago2_debug');
                
                // get credentials 
                
                $client_id     = $this->config->get('mercadopago2_client_id');
      $client_secret = $this->config->get('mercadopago2_client_secret');
                $url           = $this->config->get('mercadopago2_url');
                // urls
                
                // array to create preference key
                          
               $carrinho = array(
               "external_reference" => $order_info['order_id'] ,// seu codigo de referencia, i.e. Numero do pedido da sua loja 
               "currency" => $currency ,// string Argentina: ARS (peso argentino) ó USD (Dólar estadounidense); Brasil: BRL (Real).
               "title" => $firstproduct['name'],  //string
               "description" => $firstproduct['quantity'] . ' x ' . $firstproduct['name'], // string
               "quantity" =>  1,// int 
               "image" => HTTP_SERVER . 'image/' . $firstproduct['image'],  // Imagem, string
               "amount" => round($totalprice, 2), //decimal
               "payment_firstname" => $order_info['payment_firstname'],// string
               "payment_lastname" =>  $order_info['payment_lastname'],// string
               "email" =>    $order_info['email'],// string
               "pending" =>   $url   . '/index.php?route=payment/mercadopago2/callback', // string
               "approved" =>  $url   . '/index.php?route=payment/mercadopago2/callback'  // string
               );

               // methods para excluir
               $exclude = $this->config->get('mercadopago2_methods');  // string
                
               
               $mp = new Shop($client_id,$client_secret);
                       
               if($mp->GetCheckout($carrinho,$exclude) != ''){
                   $this->data['link'] = $mp->GetCheckout($carrinho,$exclude);
               } else {
                   $this->data['error'] = $mp->getError();
               }
                   
                 $this->render();
            
       }
     
   

   public function callback() {
      
              $order_id = $this->request->get['order_id'];
              $this->load->model('checkout/order');            
              $this->model_checkout_order->confirm($this->order_id, $this->config->get('mercadopago2_order_status_id'));
      
         $this->redirect(HTTP_SERVER . 'index.php?route=checkout/success');
   }
        
        public function retorno() {
            
                 
            if (isset($_REQUEST['id'])) {
            $id = $_REQUEST['id'];
         
            
            $client_id     = $this->config->get('mercadopago2_client_id');
            $client_secret = $this->config->get('mercadopago2_client_secret');

            $checkdata = New Shop($client_id,$client_secret);

            $dados = $checkdata->GetStatus($id);
            
                                 
            $order_id = $dados['collection']['external_reference'];
            $order_status = $dados['collection']['status'];
              
            $this->load->model('checkout/order');
            $order = $this->model_checkout_order->getOrder($order_id);
            
            
            
             if ($order['order_status_id'] == '0') {
         $this->model_checkout_order->confirm($order_id, $this->config->get('mercadopago_order_status_id'));
             }
             
             switch ($order_status) {
             case 'approved':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_completed'));   
             break;
             case 'pending':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending'));    
             break;    
             case 'in_process':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_process'));       
             break;    
             case 'reject':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_rejected'));      
             break;    
             case 'refunded':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_refunded'));      
             break;    
             case 'cancelled':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_cancelled'));      
             break;    
             case 'in_metiation':
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_in_mediation'));    
             break;
             default:
             $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending'));      
             }
           
           }
      
        }
        
      
}

class mercadopago {

    
     
        public     $accesstoken;
        protected  $client_id;
        protected  $client_secret;
        public     $erro;
        protected  $date;
        protected  $expired;


        
       ///// function just to debug the code if is needed
        
        function debug($error){
               $this->erro = $error ;
        }
        
       
       
         ///// function to post the datas
         public function DoPost($fields,$url,$heads,$codeexpect,$type,$method){
                    
                    // buld the post data follwing the api needs
                 if($type == 'json'){
                 $posts = json_encode($fields);
                             

                    } else if ($type == 'none') {
                    $posts = $fields;
                    } else {
                    $posts = http_build_query($fields);    
                    }
                    
                                    
                  
                    // change the curl method follwing the api needs
                    switch ($method):
                    case 'get':
                    $options = array(
                               CURLOPT_RETURNTRANSFER => '1',
                               CURLOPT_HTTPHEADER => $heads,
                               CURLOPT_SSL_VERIFYPEER => 'false',
                               CURLOPT_URL => $url,
                               CURLOPT_POSTFIELDS => $posts ,
                               CURLOPT_CUSTOMREQUEST => "GET"
                            );
                    break;
                    case 'put':
                      $options = array(
                                CURLOPT_RETURNTRANSFER => 1,
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "PUT",
                                CURLOPT_HEADER => 1
                             );  
                    break;
                    case 'post':
                         $options = array(
                                CURLOPT_RETURNTRANSFER => '1',
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "POST",
                             ); 
                    break;
                    case 'delete':
                        $options = array(
                                CURLOPT_RETURNTRANSFER => '1',
                                CURLOPT_HTTPHEADER => $heads,
                                CURLOPT_SSL_VERIFYPEER => 'false',
                                CURLOPT_URL => $url,
                                CURLOPT_POSTFIELDS => $posts,    
                                CURLOPT_CUSTOMREQUEST => "DELETE",
                             ); 
                        
                    break;      
                    default:
                            $options = array(
                               CURLOPT_RETURNTRANSFER => '1',
                               CURLOPT_HTTPHEADER => $heads,
                               CURLOPT_SSL_VERIFYPEER => 'false',
                               CURLOPT_URL => $url,
                               CURLOPT_POSTFIELDS => $posts ,
                               CURLOPT_CUSTOMREQUEST => "GET"
                            );
                    break;
                    endswitch;
  
                // do a curl call
                $call = curl_init();
                curl_setopt_array($call,$options);
                // execute the curl call
                $dados = curl_exec($call);
                // get the curl statys
                $status = curl_getinfo($call);
                // close the call
                curl_close($call);
                // check to see if the call was succesful 
                if ($status['http_code'] != $codeexpect){
                $this->debug($dados);
                return false;
                } else {
               // change the json retur to a php array and return it
                return json_decode($dados,true);        
                } 
        
        }
        
        public function getAccessToken(){
            
            $data = getdate();
            $time = $data[0];
             
            
            // verifica se já existe accesstoken valido, caso exista, retorna o accesstoken
            if(isset($this->accesstoken) && isset($this->date)){          
                $timedifference = $time - $this->date;
                if($timedifference < $this->expired){
                return $this->accesstoken;
                }
           }
            // get the clients variables
                $post = array(
                    'client_id' => $this->client_id,
                    'client_secret' => $this->client_secret,
                    'grant_type' => 'client_credentials'
                 );
                // set the header
                $header = array('Accept: application/json','Content-Type: application/x-www-form-urlencoded');
                // set the url to get the access token
                $url = 'https://api.mercadolibre.com/oauth/token';
                // call the post function. expection 200 as return
                $dados = $this->DoPost($post,$url,$header,'200','post','post');
                // set the access token
                if($dados['access_token']){
                $this->accesstoken = $dados['access_token'];
                }
                 // guarta o hoarario, prazo de expiraç?o e returna o access token
                $this->date = $time;
                $this->expired = $dados['expires_in'];
                return $dados['access_token'];
       }
     
       
    
}
Class Shop extends MercadoPago {
        
       // do the client authentication
      public function __construct($client,$secret){
                   $this->client_id = $client;
                   $this->client_secret = $secret; 
       }
       
       
       
     public function GetMethods($country_id) {
       
        $url = "https://api.mercadolibre.com/sites/" . $country_id .  "/payment_methods";
        $header = null;   
        $methods = $this->DoPost(null,$url,$header,'200','none','get');
        return $methods;
    
          }

      // Generate the botton
      public function GetCheckout($data,$excludes){
                
            if($excludes != ''){
                
                 $methods_excludes = preg_split("/[\s,]+/", $excludes); 
                 foreach ($methods_excludes as $exclude ){
                 $excludemethods[] = array('id' => $exclude);     
                 }
                
                 
                $opt = array(
                "external_reference" => $data['external_reference'],
                "items" => array(
                    array ("id" => $data['external_reference'], // updated
                    "title" => $data['title'],
                    "description" => $data['quantity'] . ' x ' . $data['title'],
                    "quantity" => 1,
                    "unit_price" => round($data['amount'], 2),
                    "currency_id" => $data['currency'],
                    "picture_url"=> $data['image'],
                    )),
                    "payer" => array(
                     "name" => $data['payment_firstname'],
                     "surname" => $data['payment_lastname'],
                     "email" => $data['email']
                    ),
                   "back_urls" => array(
                   "pending" => $data['pending'],
                   "success" => $data['approved']
                   ),           
                   "payment_methods" => array(
                   "excluded_payment_methods" => $excludemethods
                   )
                );
            }else{
                $opt = array(
                "external_reference" => $data['external_reference'],
                "items" => array(
                    array ("id" => $data['external_reference'], // updated
                    "title" => $data['title'],
                    "description" => $data['quantity'] . ' x ' . $data['title'],
                    "quantity" => 1,
                    "unit_price" => round($data['amount'], 2),
                    "currency_id" => $data['currency'],
                    "picture_url"=> $data['image'],
                    )),
                    "payer" => array(
                     "name" => $data['payment_firstname'],
                     "surname" => $data['payment_lastname'],
                     "email" => $data['email']
                    ),
                   "back_urls" => array(
                   "pending" => $data['pending'],
                   "success" => $data['approved']
                   ),  
                );
                
            }
            
             

            $this->getAccessToken(); 
            if(isset($this->accesstoken)){
            $url = 'https://api.mercadolibre.com/checkout/preferences?access_token=' . $this->accesstoken;
            $header = array('Content-Type:application/json','Accept: application/json');
            $dados = $this->DoPost($opt,$url,$header,'201','json','post');
            if(isset($dados['init_point'])){
            $link = $dados['init_point'];
            return $link;
            }
            return false;
            }
            return false;
      }
      
           

      public function GetStatus($id){
          
            $this->getAccessToken(); 
            $url = "https://api.mercadolibre.com/collections/notifications/" . $id . "?access_token=" . $this->accesstoken;
            $header = array('Accept: application/json', 'Content-Type: application/x-www-form-urlencoded');
            $retorno = $this->DoPost($opt=null,$url,$header,'200','none','post');
            return $retorno;
                   
      }
      
      public function getError(){
          if ($this->erro != '' && $this->erro != null){
             return $this->erro;
          }
      }
      

} 


   
?>
Valdeir,

Infelizmente não deu certo...

Retornou o mesmo erro (mas em linha diferente).
Código: Selecionar todos
Notice: Undefined index: order_id in /home/soareste/public_html/apegosedesapegos.com.br/loja/catalog/controller/payment/mercadopago2.php on line 139Warning: Cannot modify header information - headers already sent by (output started at /home/soareste/public_html/apegosedesapegos.com.br/loja/index.php:106) in /home/soareste/public_html/apegosedesapegos.com.br/loja/vqmod/vqcache/vq2-system_engine_controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/soareste/public_html/apegosedesapegos.com.br/loja/index.php:106) in /home/soareste/public_html/apegosedesapegos.com.br/loja/vqmod/vqcache/vq2-system_engine_controller.php on line 29
#39087
RicardoCostaTW escreveu:Mas ele regista a compra na Base de Dados?
Então... isso também está estranho. Recebo o e-mail de confirmação do pedido, tanto como cliente, como administrador. Mas quando entro no admin, não acusa a venda.