<?php
class ControllerPaymentPagamentoDigitalSuccess extends Controller { 
	public function index() {
		$pedido = "";
		$url_pedidos ="";
		$free = "";

		if(isSet($_POST['id_pedido'])){
			$pedido = $_POST['id_pedido']." ";
		}else if(isSet($_POST['pedido'])){
			$pedido = $_POST['pedido']." ";
		}

		if(isSet($_POST['free'])){
			$free   = $_POST['free'];
		}

		//if(isSet($_POST['url_post'])){
			//$teste_url   = explode("route", $_POST['url_post']);
			//$url_pedidos = $teste_url[0]."route=account/order";
		//}
		$encoding = iconv_get_encoding('input_encoding');

		$mensagem = "O pagamento do pedido ".$pedido."foi finalizado utilizando Bcash, pedimos por gentileza que aguarde a confirmação que lhe será enviada via email.";
		if ($encoding != "UTF-8"){
			$mensagem = utf8_encode($mensagem);
		}
	
		if( isset($this->session->data['order_id']) && ( ! empty($this->session->data['order_id']))  ) {
				$this->session->data['last_order_id'] = $this->session->data['order_id'];
			}
			
			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['order_id']);	
				unset($this->session->data['coupon']);
				unset($this->session->data['reward']);
				unset($this->session->data['voucher']);
				unset($this->session->data['vouchers']);
			}	
		
		
		
		$this->document->setTitle($this->language->get('Bcash'));
		
		$this->data['breadcrumbs'] = array(); 

		if (! empty($this->session->data['last_order_id']) ) {
			$this->data['heading_title'] = sprintf("");
		} else {
    		$this->data['heading_title'] = $this->language->get('heading_title');
		}
			
			if( $free == "" ){
				$this->data['text_message'] = "<html>
			<body marginwidth=\"0\" marginheight=\"0\" topmargin=\"0\" bottommargin=\"0\" leftmargin=\"0\" rightmargin=\"0\">
				<table border=\"0\" width=\"60%\"  align='center' > <br><br>
				<!-- left_navigation //-->
				<td style=\"text-align: center; font-size: 18px; padding-left: 5px; font-family: verdana,serif;\" class=\"main\">
					  <br><img src=\"image/confirmarPagamento.png\" alt=\"ImagemBcash\">
					  <br><br>Pagamento Finalizado<br><br>
					  <tr>
						 <td class=\"main\" align='center' style=\"text-align: center; font-family: verdana,serif;\">$mensagem</td>
						 <tr><td><br><br><div id='return-orders' align='center' style=\"text-align: center; font-size: 18px; padding-left: 5px; font-family: verdana,serif;\"> Acompanhe seus pedidos <a href=\"index.php?route=account/order\" style=\"text-align: center; font-size: 18px; padding-left: 5px; font-family: verdana,serif;\">aqui</a> </div></br></br></td></tr>
						 <tr><td align=\"center\"><br><br><br><br><img src=\"image/marcas.png\" alt=\"MarcasGrupoBuscapeCompany\"></td></tr>
					  </tr></td></table></body><br><br>
			</html>";
			
			$this->data['button_continue'] = $this->language->get('button_continue');

				$this->data['continue'] = $this->url->link('common/home');

				if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
					$this->template = $this->config->get('config_template') . '/template/common/success.tpl';
				} else {
					$this->template = 'default/template/common/success.tpl';
				}
				
				$this->children = array(
					'common/column_left',
					'common/column_right',
					'common/content_top',
					'common/content_bottom',
					'common/footer',
					'common/header'			
				);
			$this->response->setOutput($this->render());
				
			}else{
				echo "<html>
			<body marginwidth=\"0\" marginheight=\"0\" topmargin=\"0\" bottommargin=\"0\" leftmargin=\"0\" rightmargin=\"0\">
				<table border=\"0\" width=\"60%\"  align='center' > <br><br>
				<!-- left_navigation //-->
				<td style=\"text-align: center; font-size: 18px; padding-left: 5px; font-family: verdana,serif;\" class=\"main\">
					  <br><br><br><img src=\"image/confirmarPagamento.png\" alt=\"ImagemBcash\">
					  <br><br>Pagamento Finalizado<br><br>
					  <tr>
						 <td class=\"main\" align='center' style=\"text-align: center; font-family: verdana,serif;\">$mensagem</td>
						 <tr><td align=\"center\"><br><br><br><br><br><br><br><br><img src=\"image/marcas.png\" alt=\"MarcasGrupoBuscapeCompany\"></td></tr>
					  </tr>
					</td>
				</table>
			</body>
			</html>";
			
			}
	}
}
?>