PluginProbe
ЮKassa для WooCommerce / 2.8.2
ЮKassa для WooCommerce v2.8.2
2.17.1 2.17.0 2.16.3 2.16.2 2.16.1 trunk 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 All 67 releases
yookassa / yookassa.php

yookassa.php in ЮKassa для WooCommerce 2.8.2, at yookassa.php

119 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.8.2
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 * WC requires at least: 3.7.0
26 * WC tested up to: 8.9.3
27 */
28 // If this file is called directly, abort.
29
30 if (!defined('WPINC')) {
31 die;
32 }
33
34 function yookassa_plugin_activate()
35 {
36 if (!yookassa_check_woocommerce_plugin_status()) {
37 deactivate_plugins(__FILE__);
38 $error_message = __("Плагин ЮKassa для WooCommerce требует, чтобы плагин <a href=\"https://wordpress.org/extend/plugins/woocommerce/\" target=\"_blank\">WooCommerce</a> был активен!", 'yookassa');
39 wp_die($error_message);
40 }
41 require_once plugin_dir_path(__FILE__) . 'includes/YooKassaActivator.php';
42 YooKassaActivator::activate();
43 }
44
45 function yookassa_plugin_deactivate()
46 {
47 require_once plugin_dir_path(__FILE__) . 'includes/YooKassaDeactivator.php';
48 YooKassaDeactivator::deactivate();
49 }
50
51 /**
52 * @return bool
53 */
54 function yookassa_check_woocommerce_plugin_status()
55 {
56 if (defined("RUNNING_CUSTOM_WOOCOMMERCE") && RUNNING_CUSTOM_WOOCOMMERCE === true) {
57 return true;
58 }
59 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
60 return true;
61 }
62 if (!is_multisite()) return false;
63 $plugins = get_site_option('active_sitewide_plugins');
64 return isset($plugins['woocommerce/woocommerce.php']);
65 }
66
67 register_activation_hook(__FILE__, 'yookassa_plugin_activate');
68 register_deactivation_hook(__FILE__, 'yookassa_plugin_deactivate');
69
70 if (yookassa_check_woocommerce_plugin_status()) {
71 require_once plugin_dir_path(__FILE__) . 'includes/YooKassa.php';
72
73 add_action( 'before_woocommerce_init', function() {
74 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
75 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
76 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
77 }
78 } );
79
80 $plugin = new YooKassa();
81
82 define('YOOKASSA_VERSION', $plugin->getVersion());
83
84 $plugin->run();
85 }
86
87 add_action( 'woocommerce_blocks_loaded', 'yookassa_gateway_block_support' );
88 function yookassa_gateway_block_support() {
89
90 if( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
91 return;
92 }
93
94 require_once plugin_dir_path(__FILE__) . 'includes/class-wc-yookassa-blocks-support.php';
95
96 add_action(
97 'woocommerce_blocks_payment_method_type_registration',
98 function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
99 foreach (WC()->payment_gateways()->get_available_payment_gateways() as $gateway) {
100 /** @var YooKassaGateway $gateway */
101 if ($gateway->enabled === 'yes' && property_exists($gateway, 'pluginKey') && $gateway->pluginKey === 'yookassa') {
102 $payment_method_registry->register(new WC_YooKassa_Blocks_Support($gateway->id));
103 }
104 }
105 if (version_compare(WC()->version, '8.0.3', '<') ) { // For old versions of WooCommerce
106 $script_data = [];
107 foreach ($payment_method_registry->get_all_registered() as $payment_method) {
108 $script_data[$payment_method->get_name()] = $payment_method->get_payment_method_data();
109 }
110 $asset_registry = Automattic\WooCommerce\Blocks\Package::container()->get( Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class );
111 if (!empty( $script_data ) && ! $asset_registry->exists( 'paymentMethodData')) {
112 $asset_registry->add('paymentMethodData', $script_data);
113 }
114 }
115 }
116 );
117
118 }
119