| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WooCommerce PayKeeper |
| 4 |
* Plugin URI: https://docs.paykeeper.ru/cms/ |
| 5 |
* Description: Легко добавляет платежный шлюз PayKeeper в плагин WooCommerce для приема платежей через платформу PayKeeper. |
| 6 |
* Version: 2.2.7 |
| 7 |
* Author: PayKeeper |
| 8 |
* Author URI: https://paykeeper.ru/ |
| 9 |
* Requires at least: 4.2 |
| 10 |
* Requires Plugins: woocommerce |
| 11 |
* License: GPL2 or Later |
| 12 |
*/ |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
add_filter('plugin_row_meta', 'paykeeper_register_plugin_links', 10, 2); |
| 19 |
|
| 20 |
/** |
| 21 |
* Adds a link to the documentation for a specific plugin. |
| 22 |
* |
| 23 |
* @param $links |
| 24 |
* @param $file |
| 25 |
* @return mixed |
| 26 |
*/ |
| 27 |
function paykeeper_register_plugin_links($links, $file) |
| 28 |
{ |
| 29 |
$base = plugin_basename(__FILE__); |
| 30 |
if ($file == $base) { |
| 31 |
$links[] = '<a href="' . esc_url('https://docs.paykeeper.ru/cms/modul-oplaty-dlya-woocommerce/') . '" target="_blank">' . __('Docs', 'woocommerce') . '</a>'; |
| 32 |
} |
| 33 |
return $links; |
| 34 |
} |
| 35 |
|
| 36 |
add_action('plugins_loaded', 'woocommerce_paykeeper_init'); |
| 37 |
function woocommerce_paykeeper_init() { |
| 38 |
if ( !class_exists( 'WC_Payment_Gateway' ) ) return; |
| 39 |
|
| 40 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'paykeeper_action_plugin_links' ); |
| 41 |
add_action( 'before_woocommerce_init', 'declare_custom_function_compatibility' ); |
| 42 |
|
| 43 |
/** |
| 44 |
* Adds a settings link to the plugin actions on the Plugins page in the WordPress admin. |
| 45 |
* |
| 46 |
* @param array $links An array of plugin action links. |
| 47 |
* |
| 48 |
* @return array The modified array of plugin action links with the added settings link. |
| 49 |
*/ |
| 50 |
function paykeeper_action_plugin_links( $links ) { |
| 51 |
$settings_link = '<a href="' . admin_url('admin.php?page=wc-settings&tab=checkout§ion=paykeeper') . '">' . __('Settings', 'woocommerce') . '</a>'; |
| 52 |
array_unshift( $links, $settings_link ); |
| 53 |
return $links; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Custom function to declare compatibility with cart_checkout_blocks and custom_order_tables feature |
| 58 |
*/ |
| 59 |
function declare_custom_function_compatibility() { |
| 60 |
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) { |
| 61 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); |
| 62 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Localisation |
| 68 |
*/ |
| 69 |
load_plugin_textdomain('paykeeper', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/'); |
| 70 |
|
| 71 |
/** |
| 72 |
* WC PayKeeper Payment gateway plugin class. |
| 73 |
* |
| 74 |
* @class WC_PayKeeper_Addon |
| 75 |
*/ |
| 76 |
class WC_PayKeeper_Addon { |
| 77 |
|
| 78 |
static $version = '2.2.7'; |
| 79 |
static $plugin_url; |
| 80 |
static $plugin_path; |
| 81 |
|
| 82 |
/** |
| 83 |
* Initializes the PayKeeper payment gateway integration for WooCommerce. |
| 84 |
* |
| 85 |
* This method defines constants for the plugin version, URL, and path. It also includes |
| 86 |
* necessary files for the PayKeeper functionality and ensures the required classes are |
| 87 |
* loaded, such as `PaykeeperPayment` and the gateway class (`paykeeper-gateway-class.php`). |
| 88 |
* Additionally, it registers the PayKeeper payment gateway with WooCommerce by hooking |
| 89 |
* into the 'woocommerce_payment_gateways' filter and sets up a custom order approval |
| 90 |
* payment method type via the 'woocommerce_blocks_loaded' action. |
| 91 |
* |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public static function init() { |
| 95 |
define('WC_PK_ADDON_VERSION', self::$version); |
| 96 |
define('WC_PK_ADDON_URL', self::plugin_url()); |
| 97 |
define('WC_PK_ADDON_PATH', self::plugin_path()); |
| 98 |
|
| 99 |
if ( !class_exists( 'PaykeeperPayment' ) ) { |
| 100 |
require_once 'paykeeper_common_class/paykeeper.class.php'; |
| 101 |
} |
| 102 |
|
| 103 |
require_once 'paykeeper-gateway-class.php'; |
| 104 |
|
| 105 |
add_filter('woocommerce_payment_gateways', array(__CLASS__, 'woocommerce_add_paykeeper_gateway')); |
| 106 |
add_action('woocommerce_blocks_loaded', array(__CLASS__, 'register_order_approval_payment_method_type')); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Retrieves the URL to the plugin's directory. |
| 111 |
* |
| 112 |
* @return string The URL to the plugin's directory. |
| 113 |
*/ |
| 114 |
public static function plugin_url() { |
| 115 |
if (self::$plugin_url) { |
| 116 |
return self::$plugin_url; |
| 117 |
} |
| 118 |
return self::$plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Retrieves the file system path to the plugin's directory. |
| 123 |
* |
| 124 |
* @return string The file system path to the plugin's directory. |
| 125 |
*/ |
| 126 |
public static function plugin_path() { |
| 127 |
if (self::$plugin_path) { |
| 128 |
return self::$plugin_path; |
| 129 |
} |
| 130 |
return self::$plugin_path = untrailingslashit(plugin_dir_path(__FILE__)); |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Adds the PayKeeper payment gateway to the list of available WooCommerce gateways. |
| 135 |
* |
| 136 |
* @param array $methods The existing list of payment gateway methods. |
| 137 |
* @return array The updated list of payment gateway methods, including PayKeeper. |
| 138 |
*/ |
| 139 |
public static function woocommerce_add_paykeeper_gateway($methods) { |
| 140 |
$methods[] = 'WC_PK_Gateway'; |
| 141 |
return $methods; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Custom function to register a payment method type. |
| 146 |
* Registers the PayKeeper payment method type with WooCommerce Blocks. |
| 147 |
* |
| 148 |
* @return void |
| 149 |
*/ |
| 150 |
public static function register_order_approval_payment_method_type() { |
| 151 |
// Check if the required class exists |
| 152 |
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { |
| 153 |
// Include the custom Blocks Checkout class |
| 154 |
require_once 'class-block.php'; |
| 155 |
|
| 156 |
// Hook the registration function to the 'woocommerce_blocks_payment_method_type_registration' action |
| 157 |
add_action( |
| 158 |
'woocommerce_blocks_payment_method_type_registration', |
| 159 |
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { |
| 160 |
// Register an instance of My_Custom_Gateway_Blocks |
| 161 |
$payment_method_registry->register( new WC_Paykeeper_Blocks ); |
| 162 |
} |
| 163 |
); |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
WC_PayKeeper_Addon::init(); |
| 169 |
} |