<?php
$title = 'Оплата Payeer';
require ($_SERVER['DOCUMENT_ROOT'].'/core/sys.php');
require ($_SERVER['DOCUMENT_ROOT'].'/core/head.php');
echo '<div class="top">'.$title.'</div>';
$id = abs(intval($_GET['pay']));
$_SESSION['worldkassa'] = $id;
$pay = $db->prepare('SELECT * FROM `pay` WHERE `id` = ?');
$pay -> execute([$id]);
$pay = $pay -> fetch(PDO :: FETCH_ASSOC);
$amount = $pay['summa']+$pay['summa']*0.05;
if(!isset($pay['id'])){
echo '<div id="error" class="message" style="text-align:center;"><b> Для дальнейшей работы вам стоит пройти авторизацию в данном сервисе, если хотите оплатить с личного счета.. </b></div>';
require ($_SERVER['DOCUMENT_ROOT'].'/core/foot.php');
exit;
}
if($pay['status'] == 'yes'){
echo '<div id="error" class="message" style="text-align:center;"><b> Данный счет уже был оплачен... </b></div>';
require ($_SERVER['DOCUMENT_ROOT'].'/core/foot.php');
exit;
}
if(!is_numeric($amount)){
header('Location: /');
exit;
}
if($pay['type'] == 0){
header('Location: /');
exit;
}
$client = $db->prepare('SELECT * FROM `platform` WHERE `id` = ?');
$client -> execute([$pay['platform']]);
$client = $client -> fetch(PDO :: FETCH_ASSOC);
if(!isset($client['id'])){
header('Location: /');
exit;
}
$hash = md5($client['key']);
if($hash != $pay['hash']){
header('Location: '.$client['error']);
exit;
}
if($pay['check'] != md5($summa.$pay['platform'].
$time)){
header('Location: '.$client['error']); 
exit;
} 

if($pay['status'] == 'yes'){
exit(header('location :'.$client['result']));
}

$m_shop = '965179768';
$m_orderid = $pay['id'];
$m_amount = number_format($amount, 2, '.', '');
$m_curr = 'RUB';
$m_desc = base64_encode(base64_decode($pay['com']));
$m_key = 'QUU-tKN-Mhc-C2V';

$arHash = array(
	$m_shop,
	$m_orderid,
	$m_amount,
	$m_curr,
	$m_desc
);
$arParams = array(
   'submerchant' => 'mail.com',
);
$key = md5('QUU-tKN-Mhc-C2V'.$m_orderid);
$m_params = @urlencode(base64_encode(openssl_encrypt(json_encode($arParams), 'AES-256-CBC', $key, OPENSSL_RAW_DATA)));
$arHash[] = $m_params;
$arHash[] = $m_key;
$sign = strtoupper(hash('sha256', implode(':', $arHash)));
$_SESSION['payeer'] = $pay['id'];

 echo '<tr class="table-pay-tr">
                    <td class="table-pay-td-left"><img src="/design/payeer.png"/></td>
                    <td class="table-pay-td-right"><b>Payeer</b><br/>Онлайн оплата в автоматическом режиме<br/>
        <form method="post" action="https://payeer.com/merchant/">
<input type="hidden" name="m_shop" value="'.$m_shop.'">
<input type="hidden" name="m_orderid" value="'.$m_orderid.'">
<input type="hidden" name="m_amount" value="'.$m_amount.'">
<input type="hidden" name="m_curr" value="'.$m_curr.'">
<input type="hidden" name="m_desc" value="'.$m_desc.'">
<input type="hidden" name="m_sign" value="'.$sign.'">
<input type="hidden" name="m_params" value="'.$m_params.'">
<input type="hidden" name="m_cipher_method" value="AES-256-CBC">
<input type="submit" name="m_process" value="Оплатить '.$out_summ.' руб."/>
</form>

                        </td>
                </tr>';




require ($_SERVER['DOCUMENT_ROOT'].'/core/foot.php');
?>