<?php
/**
* 2015 Skrill
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
*  @author    Skrill <contact@skrill.com>
*  @copyright 2015 Skrill
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of Skrill
*/

require_once(dirname(__FILE__).'/../../core/core.php');

class SkrillCancelurlModuleFrontController extends ModuleFrontController
{

    /**
     * this function run when we access the controller.
     */
    public function postProcess()
    {
        $transactionId = $this->context->cookie->skrill_transaction_id;
        $transactions = $this->module->getOrderByTransactionId($transactionId);
        $cartId = $this->context->cookie->id_cart;

        if ($cartId == false
            && $this->context->cart->OrderExists() == false
            && $transactionId == false
            && $transactions == false
        ) {
            Tools::redirect(
                $this->context->cookie->skrill_return_url
            );
        } else {
            Tools::redirect(
                $this->context->link->getPageLink('order', true, null, array('step' => '3'))
            );
        }
    }
}
