-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdepay-woocommerce-payments.php
180 lines (148 loc) · 5.74 KB
/
depay-woocommerce-payments.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* Plugin Name: DePay for WooCommerce
* Plugin URI: https://depay.com/plugins/woocommerce
* Description: Web3 Payments. Various tokens, blockchains and wallets: MetaMask, Phantom, USDC, USDT, ETH, SOL, BSC, POL, xDAI…
* Author: DePay
* Author URI: https://depay.com
* Text Domain: depay-payments
* Domain Path: /languages
* WC requires at least: 6.2
* WC tested up to: 8.7.0
* Requires at least: 5.8
* Requires PHP: 7.0
* Version: 2.12.19
*
* @package DePay\Payments
*/
defined( 'ABSPATH' ) || exit;
define( 'DEPAY_WC_PLUGIN_FILE', __FILE__ );
define( 'DEPAY_WC_ABSPATH', __DIR__ . '/' );
define( 'DEPAY_MIN_WC_ADMIN_VERSION', '0.23.2' );
define( 'DEPAY_CURRENT_VERSION', '2.12.19' );
require_once DEPAY_WC_ABSPATH . '/vendor/autoload.php';
function depay_run_migration() {
global $wpdb;
$latestDbVersion = 4;
$currentDbVersion = get_option('depay_wc_db_version');
if ( !empty($currentDbVersion) && $currentDbVersion >= $latestDbVersion ) {
return;
}
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta("
CREATE TABLE {$wpdb->prefix}wc_depay_logs (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
log LONGTEXT NOT NULL,
created_at datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
PRIMARY KEY (id)
);
CREATE TABLE {$wpdb->prefix}wc_depay_checkouts (
id VARCHAR(36) NOT NULL,
order_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
accept LONGTEXT NOT NULL,
created_at datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
PRIMARY KEY (id)
);
CREATE TABLE {$wpdb->prefix}wc_depay_transactions (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
order_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
checkout_id VARCHAR(36) NOT NULL,
tracking_uuid TINYTEXT NOT NULL,
blockchain TINYTEXT NOT NULL,
transaction_id TINYTEXT NOT NULL,
sender_id TINYTEXT NOT NULL,
receiver_id TINYTEXT NOT NULL,
token_id TINYTEXT NOT NULL,
amount TINYTEXT NOT NULL,
status TINYTEXT NOT NULL,
failed_reason TINYTEXT NOT NULL,
commitment_required TINYTEXT NOT NULL,
confirmed_by TINYTEXT NOT NULL,
confirmed_at datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
created_at datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
PRIMARY KEY (id),
KEY tracking_uuid_index (tracking_uuid(191))
);
");
$exists = $wpdb->get_col("SHOW COLUMNS FROM wp_wc_depay_transactions LIKE 'confirmations_required'");
if (! empty( $exists ) ) {
$wpdb->query( 'ALTER TABLE wp_wc_depay_transactions DROP COLUMN confirmations_required' );
}
if ( 'wp_' != $wpdb->prefix ) {
// Rename wp_wc_depay_logs to prefix_wc_depay_logs if it exists
if ($wpdb->get_var( $wpdb->prepare('SHOW TABLES LIKE %s', 'wp_wc_depay_logs') ) == 'wp_wc_depay_logs') {
$wpdb->query( $wpdb->prepare('RENAME TABLE %s TO %s', 'wp_wc_depay_logs', $wpdb->prefix . 'wc_depay_logs') );
}
// Rename wp_wc_depay_checkouts to prefix_wc_depay_checkouts if it exists
if ($wpdb->get_var( $wpdb->prepare('SHOW TABLES LIKE %s', 'wp_wc_depay_checkouts') ) == 'wp_wc_depay_checkouts') {
$wpdb->query( $wpdb->prepare('RENAME TABLE %s TO %s', 'wp_wc_depay_checkouts', $wpdb->prefix . 'wc_depay_checkouts') );
}
// Rename wp_wc_depay_transactions to prefix_wc_depay_transactions if it exists
if ($wpdb->get_var( $wpdb->prepare('SHOW TABLES LIKE %s', 'wp_wc_depay_transactions') ) == 'wp_wc_depay_transactions') {
$wpdb->query( $wpdb->prepare('RENAME TABLE %s TO %s', 'wp_wc_depay_transactions', $wpdb->prefix . 'wc_depay_transactions') );
}
}
// Update latest DB version last
update_option( 'depay_wc_db_version', $latestDbVersion );
}
add_action('admin_init', 'depay_run_migration');
function depay_activated() {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return;
}
depay_run_migration();
try {
wp_remote_post( 'https://integrate.depay.com/installs',
array(
'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ),
'body' => json_encode( [
'type' => 'woocommerce',
'host' => get_option( 'siteurl' ),
] ),
'method' => 'POST',
'data_format' => 'body'
)
);
} catch (Exception $e) {
error_log('Reporting install failed');
}
}
register_activation_hook( __FILE__, 'depay_activated' );
function depay_deactivated() {
}
register_deactivation_hook( __FILE__, 'depay_deactivated' );
function depay_init() {
require_once DEPAY_WC_ABSPATH . '/includes/class-depay-wc-payments.php';
DePay_WC_Payments::init();
}
add_action( 'plugins_loaded', 'depay_init', 11 );
function depay_tasks_init() {
}
add_action( 'plugins_loaded', 'depay_tasks_init' );
// HPOS compatible
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
});
function depay_blocks_support() {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
if ( get_option( 'depay_wc_gateway_type' ) == 'multigateway' ) {
$blockchains = json_decode( get_option( 'depay_wc_blockchains' ) );
foreach ($blockchains as $blockchain) {
require_once DEPAY_WC_ABSPATH . 'includes/class-depay-wc-payments-block-' . $blockchain . '.php';
$className = 'DePay_WC_Payments_Block_' . ucfirst($blockchain);
$payment_method_registry->register( new $className() );
}
} else {
require_once DEPAY_WC_ABSPATH . 'includes/class-depay-wc-payments-block.php';
$payment_method_registry->register( new DePay_WC_Payments_Block() );
}
}
);
}
}
add_action( 'woocommerce_blocks_loaded', 'depay_blocks_support' );