<?php

class ControllerPaymentErede extends Controller 
{
	protected function index() {
		$this->language->load('payment/erede');
 
		$this->data['button_confirm'] = $this->language->get('button_confirm');
		$this->data['text_error'] = $this->language->get('text_error');
		$this->data['text_support'] = $this->language->get('text_support');
		$this->data['button_orders'] = $this->language->get('button_orders');
		$this->data['button_place_order'] = $this->language->get('button_place_order');
		$this->data['action'] = HTTPS_SERVER."index.php?route=payment/erede_redirect";
 
		$this->load->model('checkout/order');
		$this->load->model('payment/erede'); 
 
		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
		//$this->order = $order_info;
 
		if (!empty($order_info)) {

			switch($this->session->data['language']) {
				case 'pt':
					 $this->data['language'] = 'pt-pt';
					 break;
				default:
					 $this->data['language'] = 'en-us';
		    }

			$this->data['currency'] = $this->order['currency_code'];
            $allowed_cur = array('USD', 'EUR', 'BRL');
			$currency = $_SESSION['currency'];
			if ( !in_array($currency, $allowed_cur)) {
				$currency = 'BRL';
			}

			$this->data['orderamount'] = $this->currency->format($order_info['total'], $this->order['currency_code'] , false, false);
			$this->template = 'default/template/payment/erede.tpl';
 			
 			//$this->cart->clear();
			$this->render();
		}
	}

 
	/*public function callback() {
		if (isset($this->request->post['orderid'])) {
			$order_id = trim(substr(($this->request->post['orderid']), 6));
		} else {
			die('Illegal Access');
		}
 
		$this->load->model('checkout/order');
 
		$order_info = $this->model_checkout_order->getOrder($order_id);
 
		if ($order_info) {
		    $data = array_merge($this->request->post,$this->request->get);
			foreach ($data as $key => $value) {
				${$k} = $value;
			}
 
			$product='';
			for($i=1;$i<=10;$i++) {
				if(!isset($data['productname'.$i]) || $data['productname'.$i] == '') {
					break;
				}
				$product = $product . $data['productname'.$i] . $data['productsn'.$i] . $data['quantity'.$i] . $data['unit'.$i];
			}
 
			$cert = $this->config->get('moneybrace_cert');
			$strSource = $cert . $version . $encoding . $lang . $merchantid . $transtype . $orderid .
            $orderdate . $currency. $orderamount . $paycurrency . $payamount .$remark1 . $remark2 .
            $remark3 .  $product . $shippingfee . $deliveryname . $deliveryaddress . $deliverycountry .$deliveryprovince.
            $deliverycity . $deliveryemail . $deliveryphone . $deliverypost . $transid . $transdate . $status;
 
			if ($this->config->get('moneybrace_debug')) {
				$this->log->write('Return source string:' . $strSource);
			}
 
			$getsignature=md5($strSource);l
			if ( $getsignature != $signature) {
			    $order_status_id = $this->config->get('moneybrace_pending_status_id');
			    $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));
			    die('Data validate failed');
			}
 
			//payment was made succ
			if ($status == 'Y' || $status == 'y') {
			    $order_status_id = $this->config->get('moneybrace_processed_status_id');
				if (!$order_info['order_status_id'] || $order_info['order_status_id'] != $order_status_id) {
					$this->model_checkout_order->confirm($order_id, $order_status_id);
				} else {
					$this->model_checkout_order->update($order_id, $order_status_id);
				}
			}
		}
	}*/
}
?>