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

$merch_amount = (isset($_REQUEST["amount"])) ? $_REQUEST["amount"] : false;
$merch_tran_id = (isset($_REQUEST["label"])) ? trim($_REQUEST["label"]) : false;
$hash = (isset($_REQUEST["sha1_hash"])) ? strtoupper($_REQUEST["sha1_hash"]) : false;
$site_hash = @strtoupper(sha1($_REQUEST["notification_type"].'&'.$_REQUEST["operation_id"].'&'.$_REQUEST["amount"].'&'.$_REQUEST["currency"].'&'.$_REQUEST["datetime"].'&'.$_REQUEST["sender"].'&'.$_REQUEST["codepro"].'&'.YM_SECRET_KEY.'&'.$_REQUEST["label"]));

$m_orderid = ( isset($merch_tran_id) && preg_match("|^[\d]{1,11}$|", strip_tags(trim($merch_tran_id))) ) ? intval(strip_tags(trim($merch_tran_id))) : false;

$post=false;
if(count($_POST)>0) {
	foreach($_POST as $key => $val) $post.="$key - $val\n";
	mysql_query("INSERT INTO `tb_test` (`text`) VALUES('post-$post\nhash1$hash\nhash2$site_hash\nm-ord-$m_orderid\nID-$merch_tran_id')");
}


if($hash==$site_hash) {
$allsumme = mysql_result(mysql_query("SELECT SUM(price) FROM `b_basket` WHERE `fromid`='$m_orderid'"),0);
$allsumme = number_format(payment_comis_p(3, $allsumme), 2, '.', "");
if($merch_amount >= $allsumme){
require_once($_SERVER['DOCUMENT_ROOT']."/merchant/success-merch.php");
}else{
exit("ERROR");
}
}else{
exit("ERROR");
}

?>