Файл: app/merchant/sub_callback.php
Строк: 27
<?php
$payList = $db->prepare('SELECT * FROM `subscriptions` WHERE `time_next` < ? AND `status` = ?');
$payList -> execute([time(),1]);
$payList = $payList -> fetchAll();
foreach($payList as $res){
$shop = $db->prepare('SELECT * FROM `shop` WHERE `id` = ?');
$shop ->execute([$res['shop']]);
$shop = $shop -> fetch(PDO :: FETCH_OBJ);
$ya = new Ya($res['access_token']);
if($ya->balance() < $res->amount){
$error = ['error' => 'There is not enough means','type' => 'subscriptions'];
}
if($ya -> send(YandexNum,$sub->amount,'Оплата подписки на сайте '.$shop->url) == 0 and empty($error)){
$error = ['error' => 'An error occurred while signing up','type' => 'subscriptions'];
}
if(empty($error)){
$hash = hash('sha256', $shop->id.$res['amount'].$shop->hash2.$res['purse']);
$postArray = [
'type' => 'subscriptions',
'time' => $res['time'],
'shop_id' => $shop['id'],
'amount' => $res['amount'],
'hash' => $hash
];
$post = http_build_query($postArray);
$update = $db->prepare('UPDATE `subscriptions` SET `time_next` = ? WHERE `id` = ?');
$update -> execute([time()+86400*$res['time'],$res['id']]);
}else{
$post = http_build_query($error);
$update = $db->prepare('UPDATE `subscriptions` SET `status` = ? WHERE `id` = ?');
$update -> execute([3,$res['id']]);
}
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, $shop->result);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$out = curl_exec($curl);
echo $out;
curl_close($curl);
}
}