<?php

	if (Session::get("tipo_usuario") != "2" or Session::get("usuario_ativo") != "S"){ show_403();} 
	if ($_SERVER["REQUEST_METHOD"] == "GET"){
		import_file(DIR_MODELS."Model.class.php");

		$id_compra = encrypt_decode(filter_input(INPUT_GET, "compra", FILTER_SANITIZE_STRING));
		$transacao = filter_input(INPUT_GET, "transacao", FILTER_SANITIZE_STRING);

		$model = new Model();

		$result = $model->update("compra", [
			"codigo_transacao" => $transacao
		], [
			"id_compra" => $id_compra
		]);

		if ($result > 0) {
			echo "<script>window.location.href='".show_link("/dashboard/?status=true")."'</script>";
			$model->commit();
		}
		else{
			echo "<script>window.location.href='".show_link("/dashboard/?status=false")."'</script>";
			$model->rollback();
		}
	}
	else{
		show_403();
	}

?>