<?php
define('DATALIFEENGINE', true);

require_once @$_SERVER['DOCUMENT_ROOT'] . '/cabinet/config.php';

$request = safedArray($_REQUEST);

$generate = md5($cabinet_config['payment']['freekassa']['id'].':'.$request['AMOUNT'].':'.$cabinet_config['payment']['freekassa']['key2'].':'.$request['MERCHANT_ORDER_ID']);

(!checkArray($request)) ? die('Error REQUEST-data') : '';

($generate != $request['SIGN']) ? die('Error Signature-data') : '';

$operation = $db->super_query("SELECT * FROM `cabinet_pay_logs` WHERE `name`='{$request['MERCHANT_ORDER_ID']}' AND `operation_id`='{$request['intid']}'");

($operation) ? die('Error duble operation!') : '';

$db->query("INSERT INTO `cabinet_logs` (`name`, `description`, `price`, `date`) VALUES ('{$request['MERCHANT_ORDER_ID']}', 'Пополнение баланса', '{$request['AMOUNT']}', '". time() ."')");

$db->query("INSERT INTO `cabinet_pay_logs` VALUES (NULL, '{$request['MERCHANT_ORDER_ID']}', '{$request['AMOUNT']}', '{$request['intid']}', '{$request['SIGN']}')");

$db->query("UPDATE `dle_users` SET `balance`=`balance`+'{$request['AMOUNT']}' WHERE `name`='{$request['MERCHANT_ORDER_ID']}'");

die('YES');
?>