-
Notifications
You must be signed in to change notification settings - Fork 9
/
free-kassa.php
83 lines (66 loc) · 2.72 KB
/
free-kassa.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__.'/NewsletterCategoryDB.php';
require_once __DIR__.'/UserDB.php';
require_once __DIR__.'/NewsletterDB.php';
require_once __DIR__.'/SubscriptionDB.php';
require_once __DIR__.'/SubscriberDB.php';
require_once __DIR__.'/NewsletterSendedDB.php';
use Longman\TelegramBot\Request;
use Longman\TelegramBot\DB;
NewsletterCategoryDB::initializeNewsletterCategory();
UserDB::initializeUser();
NewsletterDB::initializeNewsletter();
SubscriptionDB::initializeSubscription();
SubscriberDB::initializeSubscriber();
NewsletterSendedDB::initializeNewsletterSended();
if(!file_exists('config.php')) {
die("Please rename example_config.php to config.php and try again. \n");
} else {
require_once __DIR__.'/config.php';
}
try {
// Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram(BOT_API_KEY, BOT_USERNAME);
// Add commands paths containing your custom commands
$telegram->addCommandsPaths(BOT_COMMANDS_PATH);
$telegram->enableLimiter();
// Enable MySQL
$telegram->enableMySql(MYSQL_CREDENTIALS);
if(!DB::isDbConnected()) {
print date('Y-m-d H:i:s', time()). " - Can't connect to mysql database. \n";
}
if (!in_array(getIP(), array('136.243.38.147', '136.243.38.149', '136.243.38.150', '136.243.38.151', '136.243.38.189', '88.198.88.98'))) {
die("hacking attempt!");
}
$sign = md5(MERCHANT_ID.':'.$_REQUEST['AMOUNT'].':'.MERCHANT_SECRET_RESPONSE.':'.$_REQUEST['MERCHANT_ORDER_ID']);
if ($sign != $_REQUEST['SIGN']) {
die('wrong sign');
}
//Так же, рекомендуется добавить проверку на сумму платежа и не была ли эта заявка уже оплачена или отменена
//Оплата прошла успешно, можно проводить операцию.
$subscribers = SubscriberDB::selectSubscriber($_REQUEST['MERCHANT_ORDER_ID']);
if(count($subscribers)) {
$subscriber = $subscribers[0];
SubscriberDB::updateSubscriber(['paid' => 1], ['id' => $_REQUEST['MERCHANT_ORDER_ID']]);
Request::sendMessage([
'chat_id' => $subscriber['chat_id'],
'text' => 'Вы успешно приобрели подписку! '
]);
print 'YES';
} else {
print 'wrong subscriber_id';
}
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
echo $e->getMessage();
// Log telegram errors
Longman\TelegramBot\TelegramLog::error($e);
} catch (Longman\TelegramBot\Exception\TelegramLogException $e) {
// Catch log initialisation errors
echo $e->getMessage();
}
function getIP() {
if(isset($_SERVER['HTTP_X_REAL_IP'])) return $_SERVER['HTTP_X_REAL_IP'];
return $_SERVER['REMOTE_ADDR'];
}
?>