<?php
class ControllerPaymentPagamentoFidelity extends Controller {

  protected function index(){
    $this->app();

		$this->data['continue']     = $this->url->link('fidelity/success');
		$this->data['back']         = $this->url->link('fidelity/checkout', '', 'SSL');

 		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pagamentofidelity.twig')) {
			$this->template = $this->config->get('config_template') . '/template/payment/pagamentofidelity.twig';
		} else {
			$this->template = 'default/template/payment/pagamentofidelity.twig';
		}

		$this->render();
  }


  public function confirm() {
    $this->load->dmodel('checkout/order');
    $this->dmodel_checkout_order->confirm($this->session->data['order_id'], $this->config->get('fidelity_status_initial'), '');

	if (isset($this->session->data['order_id'])) {
		$this->cart->clear();

		unset($this->session->data['shipping_method']);
		unset($this->session->data['shipping_methods']);
		unset($this->session->data['payment_method']);
		unset($this->session->data['payment_methods']);
		unset($this->session->data['guest']);
		unset($this->session->data['comment']);
		unset($this->session->data['coupon']);
		unset($this->session->data['reward']);
		unset($this->session->data['voucher']);
		unset($this->session->data['vouchers']);

        $this->response->setOutputJson(array("success"=>true));
	}
  }

  public function app(){
		$this->document->addScriptApp(array(
			'catalog/view/theme/appmobile/js/payment.redirect.js'
		));
		$this->data['scriptsApp'] = json_encode($this->document->getScriptsApp());
	}
}
