<?php

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../header.php');
include(dirname(__FILE__).'/MoIP.php');

	$currency = new Currency
		(intval(isset($_POST['currency_payement']) ? $_POST['currency_payement'] : $cookie->id_currency));

	$total = floatval(number_format($cart->getOrderTotal(true, 3), 2, '.', ''));

	$MoIP = new MoIP();

	$mailVars = array
	(
		'{bankwire_owner}' 		=>	$MoIP->textshowemail, 
		'{bankwire_details}' 	=> 	'',
		'{bankwire_address}' 	=> 	''
	);

	$MoIP->validateOrder
	(
		$cart->id, 
		Configuration::get('MoIP_STATUS_7'), 
		$total, 
		$MoIP->displayName, 
		NULL, $mailVars, 
		$currency->id
	);

	$order 		= new Order($MoIP->currentOrder);
	$idCustomer = $order->id_customer;
	$idLang		= $order->id_lang;
	$customer 	= new Customer(intval($idCustomer));
	$CusMail	= $customer->email;
		
	$mailVars 	= array
	(
		'{email}'			=> Configuration::get('PS_SHOP_EMAIL'),
		'{firstname}' 		=> stripslashes($customer->firstname), 
		'{lastname}' 		=> stripslashes($customer->lastname),
		'{terceiro}'		=> stripslashes($MoIP->displayName),
		'{id_order}'		=> stripslashes($MoIP->currentOrder),
		'{status}'			=> stripslashes($MoIP->getStatus(Configuration::get('MoIP_STATUS_7'))),
		'{link}'			=> $MoIP->getUrlByMyOrder($order)
	);
	
		
	$assunto 	= $MoIP->getStatus(Configuration::get('MoIP_STATUS_7'));
	
	$MoIP->enviar($mailVars, 'moip_first', $assunto, $MoIP->displayName, $idCustomer, $idLang, $customer->email, 'mails/');
	
	Tools::redirectLink(__PS_BASE_URI__.'order-confirmation.php?id_cart='.$cart->id.'&id_module='.$MoIP->id.'&id_order='.$MoIP->currentOrder.'&key='.$order->secure_key);

?>