<?php
require ($_SERVER['DOCUMENT_ROOT'].'/core/sys.php');
$id = abs(intval($_POST['ik_pm_no']));
$summa = abs($_POST['MNM_PRICE']);
$time = abs(intval($_POST['MNM_TIME_PAY']));
/*Если платеж успешный*/
if($_POST['ik_inv_st'] == 'success'){
$pay = $db->prepare('SELECT * FROM `pay` WHERE `id` = ?');
$pay -> execute([$id]);
$pay = $pay -> fetch(PDO :: FETCH_ASSOC);
$client = $db->prepare('SELECT * FROM `platform` WHERE `id` = ?');
$client -> execute([$pay['platform']]);
$client = $client -> fetch(PDO :: FETCH_ASSOC);
/*Присваиваем статус */
$sql = $db->prepare('UPDATE `pay` SET `status` = ?,`ot` = ? WHERE `id` = ?');
$sql -> execute(['yes',$out,$id]);
/*Ниже уберем если что....*/
if( $curl = curl_init() ) {
    curl_setopt($curl, CURLOPT_URL, $client['success']);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, "MNM_PAY_ID=$id&MNM_PRICE={$pay['summa']}&MNM_VAR={$pay['var']}&MNM_DATE_PAY={$time}&MNM_PLATFORM={$client['id']}&MNM_COM={$pay['com']}");
    $out = curl_exec($curl);
    curl_close($curl);
}
if($out == 'NO'){
header('location :'.$client['error']);
$sql = $db->prepare('UPDATE `pay` SET `status` = ?,`ot` = ? WHERE `id` = ?');
$sql -> execute(['bad',$out,$id]);
exit();
}else{
$sql = $db->prepare('UPDATE `pay` SET `ot` = ? WHERE `id` = ?');
$sql -> execute([$out,$id]);
}
$time = vremja($pay['value']);
$money = $db->prepare('UPDATE `platform` SET `money` = `money` + ? WHERE `id` = ?');
$money -> execute([$pay['summa'],$client['id']]);
}
/*Перенаправление*/
$pay = $db->prepare('SELECT * FROM `pay` WHERE `id` = ?');
$pay -> execute([$id]);
$pay = $pay -> fetch(PDO :: FETCH_ASSOC);
$client = $db->prepare('SELECT * FROM `platform` WHERE `id` = ?');
$client -> execute([$pay['platform']]);
$client = $client -> fetch(PDO :: FETCH_ASSOC);
if(isset($_GET['url'])) header('Location: '.$client['error']); 
else header('Location: '.$client['url']); 

exit;