<?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");

$m_operation_id = (isset($_REQUEST["m_operation_id"])) ? strip_tags(trim($_REQUEST["m_operation_id"])) : false;
$m_operation_ps = (isset($_REQUEST["m_operation_ps"])) ? strip_tags(trim($_REQUEST["m_operation_ps"])) : false;
$m_operation_date = (isset($_REQUEST["m_operation_date"])) ? strip_tags(trim($_REQUEST["m_operation_date"])) : false;
$m_operation_pay_date = (isset($_REQUEST["m_operation_pay_date"])) ? strip_tags(trim($_REQUEST["m_operation_pay_date"])) : false;
$m_shop = (isset($_REQUEST["m_shop"])) ? strip_tags(trim($_REQUEST["m_shop"])) : false;
$m_orderid = (isset($_REQUEST["m_orderid"])) ? strip_tags(trim($_REQUEST["m_orderid"])) : false;
$merch_amount = (isset($_REQUEST["m_amount"])) ? strip_tags(trim($_REQUEST["m_amount"])) : false;
$m_curr = (isset($_REQUEST["m_curr"])) ? strip_tags(trim($_REQUEST["m_curr"])) : false;
$m_desc = (isset($_REQUEST["m_desc"])) ? strip_tags(trim($_REQUEST["m_desc"])) : false;
$m_status = (isset($_REQUEST["m_status"])) ? strip_tags(trim($_REQUEST["m_status"])) : false;
$m_sign = (isset($_REQUEST["m_sign"])) ? strtoupper(strip_tags(trim($_REQUEST["m_sign"]))) : false;
$arHash = array($m_operation_id,$m_operation_ps,$m_operation_date,$m_operation_pay_date,$m_shop,$m_orderid,$merch_amount,$m_curr,$m_desc,$m_status,PY_M_KEY);
$sign = strtoupper(hash('sha256', implode(":", $arHash)));

if($sign==$m_sign && $m_status=="success") {
$allsumme = mysql_result(mysql_query("SELECT SUM(price) FROM `b_basket` WHERE `fromid`='$m_orderid'"),0);
$allsumme = number_format(payment_comis_p(6, $allsumme), 2, '.', "");
if($merch_amount >= $allsumme){
require_once($_SERVER['DOCUMENT_ROOT']."/merchant/success-merch.php");
}else{
exit("$m_orderid|error");
}
}else{
exit("$m_orderid|error");
}
?>