<?php

/** MODULO CRIADO POR ODLANIER
 * @author Odlanier de Souza Mendes
 * @copyright Dlani
 * @email master_odlanier@hotmail.com
 * @email mends@prestashopbr.com
 * @version 1.0
 **/

/*
$cod_moip			=	$_POST['cod_moip'];
$forma_pagamento	=	$_POST['forma_pagamento'];
$tipo_pagamento		=	$_POST['tipo_pagamento'];
$email_consumidor	=	$_POST['email_consumidor'];
*/

if ( isset($_POST['id_transacao']) AND isset($_POST['status_pagamento'])) {
	
	$id_transacao		=	$_POST['id_transacao'];
	$status_pagamento	=	$_POST['status_pagamento'];
	$valor				= 	$_POST['valor'];
	
	$order 	= new Order(intval($id_transacao));
	$cart 	= Cart::getCartByOrderId( $id_transacao );
	
	$mailVars = array(
	'{bankwire_owner}' 		=> '', 
	'{bankwire_details}' 	=> '', 
	'{bankwire_address}' 	=> '');

	if		($status_pagamento == 1)
		$status 		= Configuration::get('MoIP_STATUS_0');
	
	elseif	($status_pagamento == 2)
		$status 		= Configuration::get('MoIP_STATUS_1');
	
	elseif	($status_pagamento == 3)
		$status 		= Configuration::get('MoIP_STATUS_2');
	
	elseif	($status_pagamento == 4)
		$status 		= Configuration::get('MoIP_STATUS_3');
	
	elseif	($status_pagamento == 5)
		$status 		= Configuration::get('MoIP_STATUS_4');
	
	elseif	($status_pagamento == 6)
		$status 		= Configuration::get('MoIP_STATUS_5');
	
	elseif	($status_pagamento == 7)
		$status 		= Configuration::get('MoIP_STATUS_6');
	
	else
		$status 		= _PS_OS_ERROR_;
	
	$total 				= floatval(number_format($cart->getOrderTotal(true, 3), 2, '.', ''));
	
	
	/** ENVIO DO EMAIL **/
	$MoIP		= new MoIP();	
	$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($status))
	);
	$assunto 	= $MoIP->getStatus($status);
	$MoIP->enviar($mailVars, 'moip', $assunto, $MoIP->displayName, $idCustomer, $idLang, $customer->email, 
	'modules/MoIP/mails/');
	/** /ENVIO DO EMAIL **/
	
	$extraVars 			= array();
	$history 			= new OrderHistory();
	$history->id_order 	= intval($id_transacao);
	$history->changeIdOrderState(intval($status), intval($id_transacao) );
	$history->addWithemail(true, $extraVars);
			
	if ( empty($errors) )
	{
		header("HTTP 200");
	}else{
		header("HTTP 500");
	}
	
	exit;
	
}

?>