| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The plugin bootstrap file |
| 5 |
* |
| 6 |
* This file is read by WordPress to generate the plugin information in the plugin |
| 7 |
* admin area. This file also includes all of the dependencies used by the plugin, |
| 8 |
* registers the activation and deactivation functions, and defines a function |
| 9 |
* that starts the plugin. |
| 10 |
* |
| 11 |
* @since 2.0.0 |
| 12 |
* @package YooKassa |
| 13 |
* |
| 14 |
* @wordpress-plugin |
| 15 |
* Plugin Name: ЮKassa для WooCommerce |
| 16 |
* Plugin URI: https://wordpress.org/plugins/yookassa/ |
| 17 |
* Description: Платежный модуль для работы с сервисом ЮKassa через плагин WooCommerce |
| 18 |
* Version: 2.9.0 |
| 19 |
* Author: YooMoney |
| 20 |
* Author URI: http://yookassa.ru |
| 21 |
* License URI: https://yoomoney.ru/doc.xml?id=527132 |
| 22 |
* Text Domain: yookassa |
| 23 |
* Domain Path: /languages |
| 24 |
* |
| 25 |
* Requires Plugins: woocommerce |
| 26 |
* Requires at least: 5.2 |
| 27 |
* Tested up to: 6.6 |
| 28 |
* WC requires at least: 3.7 |
| 29 |
* WC tested up to: 9.2 |
| 30 |
*/ |
| 31 |
// If this file is called directly, abort. |
| 32 |
|
| 33 |
if (!defined('WPINC')) { |
| 34 |
die; |
| 35 |
} |
| 36 |
|
| 37 |
function yookassa_plugin_activate() |
| 38 |
{ |
| 39 |
if (!yookassa_check_woocommerce_plugin_status()) { |
| 40 |
deactivate_plugins(__FILE__); |
| 41 |
$error_message = __("Плагин ЮKassa для WooCommerce требует, чтобы плагин <a href=\"https://wordpress.org/extend/plugins/woocommerce/\" target=\"_blank\">WooCommerce</a> был активен!", 'yookassa'); |
| 42 |
wp_die($error_message); |
| 43 |
} |
| 44 |
require_once plugin_dir_path(__FILE__) . 'includes/YooKassaActivator.php'; |
| 45 |
YooKassaActivator::activate(); |
| 46 |
} |
| 47 |
|
| 48 |
function yookassa_plugin_deactivate() |
| 49 |
{ |
| 50 |
require_once plugin_dir_path(__FILE__) . 'includes/YooKassaDeactivator.php'; |
| 51 |
YooKassaDeactivator::deactivate(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* @return bool |
| 56 |
*/ |
| 57 |
function yookassa_check_woocommerce_plugin_status() |
| 58 |
{ |
| 59 |
if (defined("RUNNING_CUSTOM_WOOCOMMERCE") && RUNNING_CUSTOM_WOOCOMMERCE === true) { |
| 60 |
return true; |
| 61 |
} |
| 62 |
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { |
| 63 |
return true; |
| 64 |
} |
| 65 |
if (!is_multisite()) return false; |
| 66 |
$plugins = get_site_option('active_sitewide_plugins'); |
| 67 |
return isset($plugins['woocommerce/woocommerce.php']); |
| 68 |
} |
| 69 |
|
| 70 |
register_activation_hook(__FILE__, 'yookassa_plugin_activate'); |
| 71 |
register_deactivation_hook(__FILE__, 'yookassa_plugin_deactivate'); |
| 72 |
|
| 73 |
if (yookassa_check_woocommerce_plugin_status()) { |
| 74 |
require_once plugin_dir_path(__FILE__) . 'includes/YooKassa.php'; |
| 75 |
|
| 76 |
add_action( 'before_woocommerce_init', function() { |
| 77 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 78 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); |
| 79 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true ); |
| 80 |
} |
| 81 |
} ); |
| 82 |
|
| 83 |
$plugin = new YooKassa(); |
| 84 |
|
| 85 |
define('YOOKASSA_VERSION', $plugin->getVersion()); |
| 86 |
|
| 87 |
$plugin->run(); |
| 88 |
} |
| 89 |
|
| 90 |
add_action( 'woocommerce_blocks_loaded', 'yookassa_gateway_block_support' ); |
| 91 |
function yookassa_gateway_block_support() { |
| 92 |
|
| 93 |
if( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
require_once plugin_dir_path(__FILE__) . 'includes/class-wc-yookassa-blocks-support.php'; |
| 98 |
|
| 99 |
add_action( |
| 100 |
'woocommerce_blocks_payment_method_type_registration', |
| 101 |
function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) { |
| 102 |
foreach (WC()->payment_gateways()->get_available_payment_gateways() as $gateway) { |
| 103 |
/** @var YooKassaGateway $gateway */ |
| 104 |
if ($gateway->enabled === 'yes' && property_exists($gateway, 'pluginKey') && $gateway->pluginKey === 'yookassa') { |
| 105 |
$payment_method_registry->register(new WC_YooKassa_Blocks_Support($gateway->id)); |
| 106 |
} |
| 107 |
} |
| 108 |
if (version_compare(WC()->version, '8.0.3', '<') ) { // For old versions of WooCommerce |
| 109 |
$script_data = []; |
| 110 |
foreach ($payment_method_registry->get_all_registered() as $payment_method) { |
| 111 |
$script_data[$payment_method->get_name()] = $payment_method->get_payment_method_data(); |
| 112 |
} |
| 113 |
$asset_registry = Automattic\WooCommerce\Blocks\Package::container()->get( Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class ); |
| 114 |
if (!empty( $script_data ) && ! $asset_registry->exists( 'paymentMethodData')) { |
| 115 |
$asset_registry->add('paymentMethodData', $script_data); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
); |
| 120 |
|
| 121 |
} |
| 122 |
|