| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: PayKeeper |
| 4 |
* Plugin URI: https://docs.paykeeper.ru/cms/ |
| 5 |
* Description: Легко добавляет платежный шлюз PayKeeper в плагин WooCommerce для приема платежей через платформу PayKeeper. |
| 6 |
* Version: 2.0 |
| 7 |
* Author: PayKeeper development department |
| 8 |
* Author URI: https://paykeeper.ru/ |
| 9 |
* Requires at least: 4.2 |
| 10 |
* License: GPL2 or Later |
| 11 |
*/ |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
//Exit if accessed directly |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if (!class_exists('WC_PayKeeper_Gateway_Addon')){ |
| 19 |
|
| 20 |
class WC_PayKeeper_Gateway_Addon { |
| 21 |
|
| 22 |
var $version = '2.0'; |
| 23 |
var $db_version = '2.0'; |
| 24 |
var $plugin_url; |
| 25 |
var $plugin_path; |
| 26 |
|
| 27 |
function __construct() { |
| 28 |
$this->define_constants(); |
| 29 |
$this->loader_operations(); |
| 30 |
add_action('init', array(&$this, 'plugin_init'), 0); |
| 31 |
} |
| 32 |
|
| 33 |
function define_constants() { |
| 34 |
define('WC_PK_ADDON_VERSION', $this->version); |
| 35 |
define('WC_PK_ADDON_URL', $this->plugin_url()); |
| 36 |
define('WC_PK_ADDON_PATH', $this->plugin_path()); |
| 37 |
} |
| 38 |
|
| 39 |
function includes() { |
| 40 |
include_once('paykeeper-gateway-class.php'); |
| 41 |
} |
| 42 |
|
| 43 |
function loader_operations() { |
| 44 |
add_action('plugins_loaded', array(&$this, 'plugins_loaded_handler')); //plugins loaded hook |
| 45 |
} |
| 46 |
|
| 47 |
function plugins_loaded_handler() { |
| 48 |
//Runs when plugins_loaded action gets fired |
| 49 |
include_once('paykeeper-gateway-class.php'); |
| 50 |
add_filter('woocommerce_payment_gateways', array(&$this, 'init_paykeeper_gateway')); |
| 51 |
} |
| 52 |
|
| 53 |
function do_db_upgrade_check() { |
| 54 |
//NOP |
| 55 |
} |
| 56 |
|
| 57 |
function plugin_url() { |
| 58 |
if ($this->plugin_url) |
| 59 |
return $this->plugin_url; |
| 60 |
return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)); |
| 61 |
} |
| 62 |
|
| 63 |
function plugin_path() { |
| 64 |
if ($this->plugin_path) |
| 65 |
return $this->plugin_path; |
| 66 |
return $this->plugin_path = untrailingslashit(plugin_dir_path(__FILE__)); |
| 67 |
} |
| 68 |
|
| 69 |
function plugin_init() { |
| 70 |
//NOP |
| 71 |
} |
| 72 |
|
| 73 |
function init_paykeeper_gateway($methods) { |
| 74 |
array_push($methods, 'WC_PK_Gateway'); |
| 75 |
return $methods; |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
$GLOBALS['WC_PayKeeper_Gateway_Addon'] = new WC_PayKeeper_Gateway_Addon(); |
| 81 |
|
| 82 |
add_action('plugins_loaded', 'woocommerce_paykeeper_plugin', 0); |
| 83 |
function woocommerce_paykeeper_plugin(){ |
| 84 |
if (!class_exists('WC_Payment_Gateway')) |
| 85 |
return; // if the WC payment gateway class |
| 86 |
|
| 87 |
include(plugin_dir_path(__FILE__) . 'paykeeper-gateway-class.php'); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
add_filter('woocommerce_payment_gateways', 'add_paykeeper'); |
| 92 |
|
| 93 |
function add_paykeeper($gateways) { |
| 94 |
$gateways[] = 'WC_PK_Gateway'; |
| 95 |
return $gateways; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Custom function to declare compatibility with cart_checkout_blocks feature |
| 100 |
*/ |
| 101 |
function paykeeper_declare_cart_checkout_blocks_compatibility() { |
| 102 |
// Check if the required class exists |
| 103 |
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) { |
| 104 |
// Declare compatibility for 'cart_checkout_blocks' |
| 105 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); |
| 106 |
} |
| 107 |
} |
| 108 |
// Hook the custom function to the 'before_woocommerce_init' action |
| 109 |
add_action('before_woocommerce_init', 'paykeeper_declare_cart_checkout_blocks_compatibility'); |
| 110 |
|
| 111 |
// Hook the custom function to the 'woocommerce_blocks_loaded' action |
| 112 |
add_action( 'woocommerce_blocks_loaded', 'paykeeper_oawoo_register_order_approval_payment_method_type' ); |
| 113 |
|
| 114 |
/** |
| 115 |
* Custom function to register a payment method type |
| 116 |
*/ |
| 117 |
function paykeeper_oawoo_register_order_approval_payment_method_type() { |
| 118 |
// Check if the required class exists |
| 119 |
if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
// Include the custom Blocks Checkout class |
| 124 |
require_once plugin_dir_path(__FILE__) . 'class-block.php'; |
| 125 |
|
| 126 |
// Hook the registration function to the 'woocommerce_blocks_payment_method_type_registration' action |
| 127 |
add_action( |
| 128 |
'woocommerce_blocks_payment_method_type_registration', |
| 129 |
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { |
| 130 |
// Register an instance of My_Custom_Gateway_Blocks |
| 131 |
$payment_method_registry->register( new Paykeeper_Blocks ); |
| 132 |
} |
| 133 |
); |
| 134 |
} |