forked from mollie/WooCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquichain-payments-for-woocommerce.php
169 lines (150 loc) · 4.63 KB
/
liquichain-payments-for-woocommerce.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
<?php
/**
* Plugin Name: Liquichain Payments for WooCommerce
* Plugin URI: https://www.liquichain.io
* Description: Accept payments in WooCommerce with the official Liquichain plugin
* Version: 7.1.0-beta1
* Author: Liquichain
* Author URI: https://www.liquichain.io
* Requires at least: 5.0
* Tested up to: 5.9
* Text Domain: liquichain-payments-for-woocommerce
* Domain Path: /languages
* License: GPLv2 or later
* WC requires at least: 3.0
* WC tested up to: 6.3
* Requires PHP: 7.2
*/
declare(strict_types=1);
namespace Liquichain\WooCommerce;
use Inpsyde\Modularity\Package;
use Inpsyde\Modularity\Properties\PluginProperties;
use Liquichain\WooCommerce\Activation\ActivationModule;
use Liquichain\WooCommerce\Activation\ConstraintsChecker;
use Liquichain\WooCommerce\Assets\AssetsModule;
use Liquichain\WooCommerce\Shared\SharedModule;
use Liquichain\WooCommerce\Gateway\GatewayModule;
use Liquichain\WooCommerce\Gateway\Voucher\VoucherModule;
use Liquichain\WooCommerce\Log\LogModule;
use Liquichain\WooCommerce\Notice\NoticeModule;
use Liquichain\WooCommerce\Payment\PaymentModule;
use Liquichain\WooCommerce\SDK\SDKModule;
use Liquichain\WooCommerce\Settings\SettingsModule;
use Liquichain\WooCommerce\Uninstall\UninstallModule;
use Throwable;
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
define('M4W_FILE', __FILE__);
define('M4W_PLUGIN_DIR', dirname(M4W_FILE));
// Plugin folder URL.
if (!defined('M4W_PLUGIN_URL')) {
define('M4W_PLUGIN_URL', plugin_dir_url(M4W_FILE));
}
/**
* Called when plugin is activated
*/
function liquichain_wc_plugin_activation_hook()
{
require_once __DIR__ . '/inc/functions.php';
if (!liquichain_wc_plugin_autoload()) {
return;
}
liquichainDeleteWPTranslationFiles();
}
function liquichain_wc_plugin_autoload()
{
$autoloader = __DIR__ . '/vendor/autoload.php';
$liquichainSdkAutoload = __DIR__ . '/vendor/liquichain/liquichain-api-php/vendor/autoload.php';
if (file_exists($autoloader)) {
/** @noinspection PhpIncludeInspection */
require $autoloader;
}
if (file_exists($liquichainSdkAutoload)) {
/** @noinspection PhpIncludeInspection */
require $liquichainSdkAutoload;
}
return true;
}
/**
* Display an error message in the WP admin.
*
* @param string $message The message content
*
* @return void
*/
function errorNotice(string $message)
{
add_action(
'all_admin_notices',
static function () use ($message) {
$class = 'notice notice-error';
printf(
'<div class="%1$s"><p>%2$s</p></div>',
esc_attr($class),
wp_kses_post($message)
);
}
);
}
/**
* Handle any exception that might occur during plugin setup.
*
* @param Throwable $throwable The Exception
*
* @return void
*/
function handleException(Throwable $throwable)
{
do_action('inpsyde.liquichain-woocommerce.critical', $throwable);
errorNotice(
sprintf(
'<strong>Error:</strong> %s <br><pre>%s</pre>',
$throwable->getMessage(),
$throwable->getTraceAsString()
)
);
}
/**
* Initialize all the plugin things.
*
* @throws Throwable
*/
function initialize()
{
try {
require_once __DIR__ . '/inc/functions.php';
if (!liquichain_wc_plugin_autoload()) {
return;
}
$checker = new ConstraintsChecker();
$meetRequirements = $checker->handleActivation();
if (!$meetRequirements) {
$nextScheduledTime = wp_next_scheduled('pending_payment_confirmation_check');
if ($nextScheduledTime) {
wp_unschedule_event($nextScheduledTime, 'pending_payment_confirmation_check');
}
return;
}
// Initialize plugin.
$properties = PluginProperties::new(__FILE__);
$bootstrap = Package::new($properties);
$modules = [
new ActivationModule(__FILE__),
new LogModule('liquichain-payments-for-woocommerce-'),
new NoticeModule(),
new SharedModule(),
new SDKModule(),
new SettingsModule(),
new AssetsModule(),
new GatewayModule(),
new VoucherModule(),
new PaymentModule(),
new UninstallModule()
];
$modules = apply_filters('liquichain_wc_plugin_modules', $modules);
$bootstrap->boot(...$modules);
} catch (Throwable $throwable) {
handleException($throwable);
}
}
add_action('plugins_loaded', __NAMESPACE__ . '\\initialize');
register_activation_hook(M4W_FILE, __NAMESPACE__ . '\liquichain_wc_plugin_activation_hook');