<?php
require ($_SERVER['DOCUMENT_ROOT'].'/core/sys.php');

$key = 'test75wmr'; // Secret Key:
$wmr_k = 'R123456789'; // Кошелек
$wmr_koch = $_POST['LMI_PAYEE_PURSE']; // Кошелек
$summa = $_POST['LMI_PAYMENT_AMOUNT']; // Входящая сумма
$wmidpokupatela = $_POST['LMI_PAYER_WM']; // WMID
$tel = $_POST['LMI_WMCHECK_NUMBER']; // Телефон
$email = $_POST['LMI_PAYMER_EMAIL']; // Email

if (isset($_POST['LMI_PREREQUEST'])) 
{
echo 'YES';
exit;
}

$chkstring = 
	$wmr_k
	.$_POST['LMI_PAYMENT_AMOUNT']
	.$_POST['LMI_PAYMENT_NO']
	.$_POST['LMI_MODE']
	.$_POST['LMI_SYS_INVS_NO']
	.$_POST['LMI_SYS_TRANS_NO']
	.$_POST['LMI_SYS_TRANS_DATE']
	.$key
	.$_POST['LMI_PAYER_PURSE']
	.$_POST['LMI_PAYER_WM'];
			
$md5sum = strtoupper(hash("sha256", $chkstring));

if($md5sum != $_POST['LMI_HASH'])
{
	die('Ошибка');
	exit;
}

$id = intval($_POST['idd']);
if(empty($id)) die('No');
$pay = $db->prepare('SELECT * FROM `pay` WHERE `key` = ?');
$pay -> execute([$id]);
$pay = $pay -> fetch(PDO :: FETCH_ASSOC);
/*Присваиваем статус */
$sql = $db->prepare('UPDATE `pay` SET `status` = ? WHERE `id` = ?');
$sql -> execute(['success',$pay['id']]);