-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpaypal-point-of-sale.php
More file actions
157 lines (139 loc) · 4.41 KB
/
paypal-point-of-sale.php
File metadata and controls
157 lines (139 loc) · 4.41 KB
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
<?php
//phpcs:disable PSR12.Files.FileHeader.IncorrectOrder
declare(strict_types=1);
/**
* Plugin Name: PayPal Point of Sale
* Plugin URI: https://zettle.inpsyde.com/
* Description: PayPal Point of Sale Integration for WooCommerce
* Version: {VERSION}
* Requires at least: 6.8
* Requires PHP: 8.2
* Requires Plugins: woocommerce
* WC requires at least: 10.2
* WC tested up to: 10.2
* Author: PayPal
* Author URI: https://www.paypal.com/us/business/pos
* License: GPL-2.0
* Text Domain: paypal-point-of-sale
* Domain Path: /languages
*/
/**
* phpcs:disable PSR1.Files.SideEffects
* phpcs:disable Squiz.PHP.CommentedOutCode.Found
*/
namespace Syde\PayPal\PointOfSale;
use Dhii\Validation\Exception\ValidationFailedExceptionInterface;
use Psr\Container\ContainerInterface;
(static function () {
/**
* 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)
);
}
);
}
$requiresAtLeast = '8.2';
if (version_compare(PHP_VERSION, $requiresAtLeast, '<')) {
errorNotice(
sprintf(
/* translators: required PHP version */
esc_html__(
'PayPal Point of Sale requires at least PHP version %s.',
'paypal-point-of-sale'
),
$requiresAtLeast
)
. '<br>' .
sprintf(
/* translators: required PHP version */
esc_html__(
'Please ask your server administrator to update your environment to PHP version %s.',
'paypal-point-of-sale'
),
$requiresAtLeast
)
);
return;
}
if (
!class_exists(PluginModule::class)
&& file_exists(__DIR__ . '/vendor/autoload.php')
) {
include_once __DIR__ . '/vendor/autoload.php';
}
function init(): ?ContainerInterface
{
static $initialized;
static $container;
if (!$initialized) {
try {
$container = (require __DIR__ . '/bootstrap.php')(__DIR__, true);
} catch (ValidationFailedExceptionInterface $exc) {
$messages = array_map(static function ($error): string {
if ($error instanceof ValidationFailedExceptionInterface) {
return $error->getMessage();
}
return (string) $error;
}, $exc->getValidationErrors());
foreach ($messages as $message) {
errorNotice($message);
}
return null;
}
$initialized = true;
}
return $container;
}
add_action(
'plugins_loaded',
static function () {
$container = init();
if (!$container) {
return;
}
// IZET-356, looks like there is no good built-in hook in WP for plugin upgrades
$version = $container->get('paypal-pos.plugin.properties')->version();
$versionOptionName = $container->get('paypal-pos.version-option-key');
if (get_option($versionOptionName) !== $version) {
do_action('paypal-point-of-sale.migrate');
update_option($versionOptionName, $version);
}
}
);
register_activation_hook(
__FILE__,
static function () {
init();
do_action('paypal-point-of-sale.activate');
}
);
register_deactivation_hook(
__FILE__,
static function () {
init();
do_action('paypal-point-of-sale.deactivate');
}
);
add_action(
'before_woocommerce_init',
static function () {
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
}
);
})();