<?php
header("Content-type: text/html; charset=windows-1251");
require_once($_SERVER['DOCUMENT_ROOT']."/merchant/payment_config.php");
require_once($_SERVER['DOCUMENT_ROOT']."/funciones.php");
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
define('PATH_TO_LOG', dirname(__FILE__).'/');

$merch_amount = (isset($_REQUEST["OutSum"])) ? $_REQUEST["OutSum"] : false;
$m_orderid = (isset($_REQUEST["InvId"])) ? intval(trim($_REQUEST["InvId"])) : false;
$crc = (isset($_REQUEST["SignatureValue"])) ? strtoupper($_REQUEST["SignatureValue"]) : false;
$my_crc = strtoupper(md5($merch_amount.":".$m_orderid.":".RK_PASS2));

#запись в файл информации о прведенной операции
$f=@fopen(PATH_TO_LOG."rk_order.txt","a+") or die("error");
@fputs($f,"order_num: $m_orderid; Summ: $merch_amount; Date: ".DATE("d.m.Y H:i")."\n");
fclose($f);


if($my_crc!=$crc) {
	exit("ERROR!");
}else{
	echo "OK$m_orderid\n";
	
$allsumme = mysql_result(mysql_query("SELECT SUM(price) FROM `b_basket` WHERE `fromid`='$m_orderid'"),0);
$allsumme = number_format(payment_comis_p(7, $allsumme), 2, '.', "");
if($merch_amount >= $allsumme){
include($_SERVER['DOCUMENT_ROOT']."/merchant/success-merch.php");
}else{
exit("ERROR!");
}

}
?>