-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwc-clickuz-gateway.php
162 lines (119 loc) · 5.65 KB
/
wc-clickuz-gateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*
* Plugin Name: Woocommerce CLICK Payment Method
* Plugin URI: https://click.uz
* Description: CLICK Payment Method Plugin for WooCommerce
* Version: 1.0.4
* Author: OOO "Click"
* Author URI: https://click.uz
* Text Domain: clickuz
* Domain Path: /i18n/languages/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
define( 'CLICK_VERSION', '1.0.6' );
define( 'CLICK_LOGO', plugin_dir_url( __FILE__ ) . 'click-logo.png' );
define( 'CLICK_DELIMITER', '|' );
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
class WC_ClickUz {
public $plugin;
public function __construct() {
$this->plugin = plugin_basename( __FILE__ );
load_plugin_textdomain( 'clickuz', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages/' );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
add_action( 'plugins_loaded', array( $this, 'init' ), 0 );
add_filter( "plugin_action_links_{$this->plugin}", array( $this, 'settings_link' ) );
add_action( 'woocommerce_init', array( $this, 'wc_init' ) );
add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
add_action( 'before_woocommerce_init', array( $this, 'declare_cart_checkout_blocks_compatibility'));
add_action( 'woocommerce_blocks_loaded', array( $this, 'register_order_approval_payment_method_type'));
}
public function init() {
if ( class_exists( 'WC_Payment_Gateway' ) ) {
require_once 'include/class-wc-gateway-clickuz.php';
require_once 'include/class-wc-gateway-clickuz-handlers.php';
new WC_ClickAPI();
}
}
public function wc_init() {
if ( isset( $_GET['click-return'] ) && $_GET['click-return'] == WC()->customer->get_id() ) {
WC()->cart->empty_cart( true );
}
}
public function activate() {
if ( ! function_exists( 'curl_exec' ) ) {
wp_die( '<pre>This plugin requires PHP CURL library installled in order to be activated </pre>' );
}
if ( ! function_exists( 'openssl_verify' ) ) {
wp_die( '<pre>This plugin requires PHP OpenSSL library installled in order to be activated </pre>' );
}
$this->install();
flush_rewrite_rules();
}
public function deactivate() {
flush_rewrite_rules();
}
public function install() {
global $wpdb;
$wpdb->hide_errors();
$collate = '';
if ( $wpdb->has_cap( 'collation' ) ) {
if ( ! empty( $wpdb->charset ) ) {
$collate .= "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$collate .= " COLLATE $wpdb->collate";
}
}
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( "
CREATE TABLE `{$wpdb->prefix}wc_click_transactions` (
`ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`click_trans_id` BIGINT(20) UNSIGNED NOT NULL,
`service_id` BIGINT(20) UNSIGNED NOT NULL,
`click_paydoc_id` BIGINT(20) UNSIGNED NOT NULL,
`merchant_trans_id` BIGINT(20) UNSIGNED NOT NULL,
`amount` DECIMAL(20, 2) NOT NULL,
`error` BIGINT(20) UNSIGNED NOT NULL,
`error_note` NVARCHAR(120),
`status` NVARCHAR(32),
PRIMARY KEY (`ID`)
) $collate; " );
}
public function settings_link( $links ) {
$settings_link = '<a href="admin.php?page=wc-settings&tab=checkout§ion=clickuz">' . __( 'Settings' ) . '</a>';
array_push( $links, $settings_link );
return $links;
}
public function add_gateway( $methods ) {
$methods[] = 'WC_Gateway_Clickuz';
return $methods;
}
function declare_cart_checkout_blocks_compatibility() {
// Check if the required class exists
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
// Declare compatibility for 'cart_checkout_blocks'
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
}
}
function register_order_approval_payment_method_type() {
// Check if the required class exists
if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
return;
}
// Include the custom Blocks Checkout class
require_once plugin_dir_path(__FILE__) . '/integrations/blocks/class-block.php';
// Hook the registration function to the 'woocommerce_blocks_payment_method_type_registration' action
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
// Register an instance of My_Custom_Gateway_Blocks
$payment_method_registry->register( new WC_Clickuz_Gateway_Blocks );
}
);
}
}
new WC_ClickUz();
}