| 1 |
<?php |
| 2 |
|
| 3 |
use Robokassa\Payment\Util; |
| 4 |
|
| 5 |
/** |
| 6 |
* Возвращает текущую версию плагина Robokassa. |
| 7 |
* |
| 8 |
* @return string |
| 9 |
*/ |
| 10 |
function robokassa_get_plugin_version() { |
| 11 |
$pluginFile = __DIR__ . '/wp_robokassa.php'; |
| 12 |
|
| 13 |
if (!file_exists($pluginFile)) { |
| 14 |
return 'unknown'; |
| 15 |
} |
| 16 |
|
| 17 |
if (!function_exists('get_file_data')) { |
| 18 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 19 |
} |
| 20 |
|
| 21 |
$pluginData = get_file_data($pluginFile, ['Version' => 'Version']); |
| 22 |
|
| 23 |
if (empty($pluginData['Version'])) { |
| 24 |
return 'unknown'; |
| 25 |
} |
| 26 |
|
| 27 |
return $pluginData['Version']; |
| 28 |
} |
| 29 |
|
| 30 |
register_activation_hook(__DIR__ . '/wp_robokassa.php', 'robokassa_plugin_activated'); |
| 31 |
register_deactivation_hook(__DIR__ . '/wp_robokassa.php', 'robokassa_plugin_deactivated'); |
| 32 |
|
| 33 |
function robokassa_plugin_activated() { |
| 34 |
robokassa_notify_status_change('enabled'); |
| 35 |
} |
| 36 |
|
| 37 |
function robokassa_plugin_deactivated() { |
| 38 |
robokassa_notify_status_change('disabled'); |
| 39 |
} |
| 40 |
|
| 41 |
function robokassa_notify_status_change($status) { |
| 42 |
$apiUrl = 'https://pulse.robokassa.com/api/module-status'; |
| 43 |
$apiKey = 'robokassa-plugin-stat-key-3953'; |
| 44 |
|
| 45 |
$site_url = Util::siteUrl(); |
| 46 |
$merchantId = get_option('robokassa_payment_MerchantLogin'); |
| 47 |
|
| 48 |
$payload = [ |
| 49 |
'cms' => 'wordpress', |
| 50 |
'merchant_id' => $merchantId ?: 'unknown', |
| 51 |
'site_id' => $site_url, |
| 52 |
'status' => $status, |
| 53 |
'reported_at' => current_time('Y-m-d H:i:s'), |
| 54 |
'version' => robokassa_get_plugin_version(), |
| 55 |
]; |
| 56 |
|
| 57 |
wp_remote_post($apiUrl, [ |
| 58 |
'headers' => [ |
| 59 |
'Content-Type' => 'application/json', |
| 60 |
'X-API-KEY' => $apiKey, |
| 61 |
], |
| 62 |
'body' => json_encode($payload), |
| 63 |
'timeout' => 5, |
| 64 |
]); |
| 65 |
|
| 66 |
robokassa_payment_DEBUG("[Robokassa] Статус $status отправлен на $apiUrl"); |
| 67 |
} |
| 68 |
|