<?php
/**
* Captura retorno de MercadoPago
*
* @author    Kijam.com <info@kijam.com>
* @copyright 2014 Kijam.com
* @license   Comercial
*/

include(dirname(__FILE__).'/../../config/config.inc.php');
include(_PS_ROOT_DIR_.'/init.php');
include(dirname(__FILE__).'/paymentskrill.php');

PaymentSkrill::log('RETURN: '.print_r($_GET, true).print_r($_POST, true));

if ((int)Tools::getValue('id_cart') > 0)
{
	$id_cart = (int)Tools::getValue('id_cart');
	$cart = new Cart($id_cart);
	$id_order = Order::getOrderByCartId($id_cart);
	if ($id_order > 0)
	{
		$order = new Order($id_order);
		$payment = new PaymentSkrill();
		$customer = new Customer((int)$cart->id_customer);
		if (_PS_VERSION_ >= '1.5')
			Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$payment->id.'&id_order='.$order->id.'&key='.$customer->secure_key);
		else
			Tools::redirect('order-confirmation.php?id_cart='.$cart->id.'&id_module='.$payment->id.'&id_order='.$order->id.'&key='.$customer->secure_key);
		exit;
	}
}

if (_PS_VERSION_ >= '1.5')
	Tools::redirect('index.php?controller=cart');
else
	Tools::redirect('cart.php');
