<?php
include('../inc/conf.php');
include('cpayeer.php');
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(604800000, "/", SITE, false, false);
session_start();
if (!isset($_SESSION["uid"])){
echo "5";
exit;
}
if(isset($_POST['sum'])){
if(!empty($_POST['sum'])){
$uid = intval($_SESSION["uid"]);
$sum = preg_replace("#[^\.\-0-9]+#i",'',mysqli_real_escape_string($connect_db, $_POST["sum"]));
$nb = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT bal,nu FROM t_users WHERE uid='$uid'"));
$nbal = $nb['bal'];
$nu = $nb['nu'];
if (empty($nu)) { echo '7'; exit; }
if ($nbal < 1) { echo '4'; exit; }
if ($nbal < $sum) { echo '3'; exit; }
if ($sum < 1) { echo '2'; exit; }
$dt = time();
$batch = $uid.'_'.$dt;
$accountNumber = $p_out_number;
$apiId = $p_out_id;
$apiKey = $p_out_key;
$payeer = new CPayeer($accountNumber, $apiId, $apiKey);
if ($payeer->isAuth())
{
$arTransfer = $payeer->transfer(array(
'curIn' => 'RUB',
'sum' => $sum,
'curOut' => 'RUB',
'to' => $nu,
'comment' => iconv('windows-1251', 'utf-8', 'Viplata '.SITE)
));
if (empty($arTransfer['errors']))
{
mysqli_query($connect_db, "INSERT INTO `t_ca` (ty,usr,sum,ba,st,dt) VALUES ('0','$uid','$sum','$batch','1','$dt')");
mysqli_query($connect_db, "UPDATE `t_users` SET `bal` = `bal`-'$sum' WHERE uid = '$uid' LIMIT 1");
exit('1');
}
else
{
exit('6');
}
}
else
{
exit('6');
}
exit('1');
} else { echo '0'; }
} else { echo '6'; }
?>