<?
require '_system/core.php';
die();
/*
array(2) { ["answer"]=> string(5) "error" ["desc"]=> string(39) "too fast, wait 10sec until next request" }
array(3) { ["answer"]=> string(4) "info" ["desc"]=> string(33) "Заявка отправлена" ["PaymentId"]=> string(7) "5106351" }
*/

$fkp = new FreeKassaHade();
$fileconfig = parse_ini_file($_SERVER['DOCUMENT_ROOT'] .'/_system/_inifiles/freekassa.ini');
$hfile = $_SERVER['DOCUMENT_ROOT'] .'/_system/_inifiles/cron-getTransfer.json';

$merchant_id = $fileconfig['merchant_id'];
$secret_word = $fileconfig['secret_word'];

if (@filectime($hfile) < time() - 1) {
	@unlink($hfile);
}
$balans = 0;
if (!file_exists($hfile)) {
	$s = md5($merchant_id.$secret_word);
	$url = "https://www.free-kassa.ru/api.php?merchant_id={$merchant_id}&s={$s}&action=get_balance";
	$xml = simplexml_load_file($url);
	$balans = $xml->balance;
	sleep(11);
	$balans = abs((int) $balans);
	//$balans = ($balans - 50);
	if ($balans > 50) {
		$re = $fkp->getTransfer($balans);
	}
	var_dump($re);
	file_put_contents($hfile, json_encode(array('time' => time()), true));
}



/*
$array = $sql -> select("SELECT * FROM `users_log` WHERE `id_key` = '' ORDER BY `time` DESC LIMIT 100");
foreach ($array AS $post) {
	$sql->update("UPDATE `users_log` SET `id_key` = '". md5(mt_rand(1,999999).time().mt_rand(1,999999).time().mt_rand(1,999999).$post['id_user'])."' WHERE `time` = '$post[time]'");
}
*/
//die('ssss');

/*
$fkp = new FreeKassaHade();
$fileconfig = parse_ini_file($_SERVER['DOCUMENT_ROOT'] .'/_system/_inifiles/freekassa.ini');
$hfile = $_SERVER['DOCUMENT_ROOT'] .'/_system/_inifiles/cron-getTransfer.json';

$merchant_id = $fileconfig['merchant_id'];
$secret_word = $fileconfig['secret_word'];

if (@filectime($hfile) < time() - 1) {
	@unlink($hfile);
}
$balans = 0;
if (!file_exists($hfile)) {
	$s = md5($merchant_id.$secret_word);
	$url = "https://www.free-kassa.ru/api.php?merchant_id={$merchant_id}&s={$s}&action=get_balance";
	$xml = simplexml_load_file($url);
	$balans = $xml->balance;
	//var_dump($xml);
	sleep(12);
	$balans = abs((int) $balans);
	//$balans = ($balans - 50);
	if ($balans > 104) {
		$re = $fkp->getTransfer($balans);
	}
	//var_dump($re);
	file_put_contents($hfile, json_encode(array('time' => time()), true));
}*/
//echo 'ok-'. $balans;
