-
Notifications
You must be signed in to change notification settings - Fork 53
/
mollie-payments-for-woocommerce.php
165 lines (150 loc) · 4.51 KB
/
mollie-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
<?php
/**
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 7.9.0-beta
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
* Tested up to: 6.7
* Text Domain: mollie-payments-for-woocommerce
* Domain Path: /languages
* License: GPLv2 or later
* WC requires at least: 3.9
* WC tested up to: 9.3
* Requires PHP: 7.4
* Requires Plugins: woocommerce
*/
declare(strict_types=1);
namespace Mollie\WooCommerce;
use Mollie\WooCommerce\MerchantCapture\MerchantCaptureModule;
use Inpsyde\Modularity\Package;
use Inpsyde\Modularity\Properties\PluginProperties;
use Mollie\WooCommerce\Activation\ActivationModule;
use Mollie\WooCommerce\Activation\ConstraintsChecker;
use Mollie\WooCommerce\Assets\AssetsModule;
use Mollie\WooCommerce\Shared\SharedModule;
use Mollie\WooCommerce\Gateway\GatewayModule;
use Mollie\WooCommerce\Gateway\Voucher\VoucherModule;
use Mollie\WooCommerce\Log\LogModule;
use Mollie\WooCommerce\Notice\NoticeModule;
use Mollie\WooCommerce\Payment\PaymentModule;
use Mollie\WooCommerce\SDK\SDKModule;
use Mollie\WooCommerce\Settings\SettingsModule;
use Mollie\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));
}
function mollie_wc_plugin_autoload()
{
$autoloader = __DIR__ . '/vendor/autoload.php';
$mollieSdkAutoload = __DIR__ . '/vendor/mollie/mollie-api-php/vendor/autoload.php';
if (file_exists($autoloader)) {
/**
* @noinspection PhpIncludeInspection
*
*/
require $autoloader;
}
if (file_exists($mollieSdkAutoload)) {
/**
* @noinspection PhpIncludeInspection
* @psalm-suppress MissingFile
*/
require $mollieSdkAutoload;
}
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.mollie-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 (!mollie_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__, $properties->get('version')),
new NoticeModule(),
new SharedModule(),
new SDKModule(),
new SettingsModule(),
new LogModule('mollie-payments-for-woocommerce-'),
new AssetsModule(),
new GatewayModule(),
new VoucherModule(),
new PaymentModule(),
new MerchantCaptureModule(),
new UninstallModule(),
];
$modules = apply_filters('mollie_wc_plugin_modules', $modules);
foreach ($modules as $module) {
$bootstrap->addModule($module);
}
$bootstrap->boot();
} catch (Throwable $throwable) {
handleException($throwable);
}
}
add_action('plugins_loaded', __NAMESPACE__ . '\\initialize');