-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathwoocommerce-paypal-payments.php
More file actions
294 lines (265 loc) · 9.11 KB
/
woocommerce-paypal-payments.php
File metadata and controls
294 lines (265 loc) · 9.11 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
/**
* Plugin Name: WooCommerce PayPal Payments
* Plugin URI: https://woocommerce.com/products/woocommerce-paypal-payments/
* Description: PayPal's latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts. Turn on only PayPal options or process a full suite of payment methods. Enable global transaction with extensive currency and country coverage.
* Version: 4.0.2
* Author: PayPal
* Author URI: https://paypal.com/
* License: GPL-2.0
* Requires PHP: 7.4
* Requires Plugins: woocommerce
* Requires at least: 6.5
* WC requires at least: 9.6
* WC tested up to: 10.6
* Text Domain: woocommerce-paypal-payments
*
* @package WooCommerce\PayPalCommerce
*/
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce;
define( 'PAYPAL_API_URL', 'https://api-m.paypal.com' );
define( 'PAYPAL_URL', 'https://www.paypal.com' );
define( 'PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com' );
define( 'PAYPAL_SANDBOX_URL', 'https://www.sandbox.paypal.com' );
define( 'PAYPAL_INTEGRATION_DATE', '2026-04-01' );
define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' );
! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' );
! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' );
! defined( 'CONNECT_WOO_MERCHANT_ID' ) && define( 'CONNECT_WOO_MERCHANT_ID', 'K8SKZ36LQBWXJ' );
! defined( 'CONNECT_WOO_SANDBOX_MERCHANT_ID' ) && define( 'CONNECT_WOO_SANDBOX_MERCHANT_ID', 'MPMFHQTVMBZ6G' );
! defined( 'CONNECT_WOO_URL' ) && define( 'CONNECT_WOO_URL', 'https://api.woocommerce.com/integrations/ppc' );
! defined( 'CONNECT_WOO_SANDBOX_URL' ) && define( 'CONNECT_WOO_SANDBOX_URL', 'https://api.woocommerce.com/integrations/ppcsandbox' );
( static function () {
$autoload_filepath = __DIR__ . '/vendor/autoload.php';
if ( ! class_exists( '\WooCommerce\PayPalCommerce\PluginModule' ) && file_exists( $autoload_filepath ) ) {
require $autoload_filepath;
}
/**
* Displays an admin notice and optionally deactivates the current plugin.
*
* This function registers a callback to display administrative notices on both
* single-site and network admin areas. It's typically used to show error messages
* when plugin requirements are not met, followed by automatic plugin deactivation.
*
* @param callable $notice_callback The callback function that outputs the admin notice HTML.
* Should echo/print the notice markup directly.
* @param bool $auto_deactivate Optional. Whether to automatically deactivate the plugin
* after displaying the notice. Default true.
*/
function show_admin_notice_and_deactivate( callable $notice_callback, bool $auto_deactivate = true ): void {
$admin_notice_hooks = array( 'admin_notices', 'network_admin_notices' );
foreach ( $admin_notice_hooks as $hook ) {
add_action(
$hook,
static function () use ( $notice_callback, $auto_deactivate ) {
$notice_callback();
if ( $auto_deactivate ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
}
);
}
}
/**
* Initialize the plugin and its modules.
*/
function init(): bool {
static $initialized = false;
if ( ! is_woocommerce_activated() ) {
show_admin_notice_and_deactivate(
static fn() => printf(
'<div class="notice notice-error"><span class="notice-title">%1$s</span><p>%2$s</p></div>',
esc_html__(
'The plugin WooCommerce PayPal Payments has been deactivated',
'woocommerce-paypal-payments'
),
wp_kses(
sprintf(
// translators: %s is a link to install WooCommerce.
esc_html__( 'WooCommerce PayPal Payments requires WooCommerce to be installed and active. %s', 'woocommerce-paypal-payments' ),
sprintf(
'<a href="%s">%s</a>',
esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=woocommerce' ) ),
esc_html__( 'You can download WooCommerce here.', 'woocommerce-paypal-payments' )
)
),
array(
'a' => array(
'href' => array(),
'target' => array(),
),
)
)
)
);
return $initialized;
}
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
show_admin_notice_and_deactivate(
static fn() => printf(
'<div class="notice notice-error"><span class="notice-title">%1$s</span><p>%2$s</p></div>',
esc_html__(
'The plugin WooCommerce PayPal Payments has been deactivated',
'woocommerce-paypal-payments'
),
esc_html__( 'WooCommerce PayPal Payments requires PHP 7.4 or above.', 'woocommerce-paypal-payments' )
)
);
return $initialized;
}
if ( ! $initialized ) {
$root_dir = __DIR__;
$bootstrap = require "$root_dir/bootstrap.php";
$app_container = $bootstrap( $root_dir );
PPCP::init( $app_container );
$initialized = true;
/**
* The hook fired after the plugin bootstrap with the app services container as parameter.
*/
do_action( 'woocommerce_paypal_payments_built_container', $app_container );
}
return $initialized;
}
add_action(
'plugins_loaded',
static function () {
// Skip full bootstrap during manual plugin updates to prevent class-mismatch
// fatals when old in-memory code autoloads new files from disk.
if ( 'update.php' === ( $GLOBALS['pagenow'] ?? '' ) ) {
return;
}
if ( ! init() ) {
return;
}
add_action(
'init',
static function () {
$current_plugin_version = PPCP::container()->get( 'ppcp.plugin-version' );
$installed_plugin_version = get_option( 'woocommerce-ppcp-version' );
if ( $installed_plugin_version !== $current_plugin_version ) {
update_option( 'woocommerce-ppcp-version', $current_plugin_version );
/**
* The hook fired when the plugin is installed or updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate', $installed_plugin_version );
if ( $installed_plugin_version ) {
/**
* The hook fired when the plugin is updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate_on_update' );
}
}
},
-1
);
}
);
register_activation_hook(
__FILE__,
static function () {
init();
/**
* The hook fired in register_activation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_activate' );
}
);
register_deactivation_hook(
__FILE__,
static function () {
init();
/**
* The hook fired in register_deactivation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_deactivate' );
}
);
add_filter(
'plugin_action_links_' . plugin_basename( __FILE__ ),
/**
* Add "Settings" link to Plugins screen.
*
* @param array $links
* @return array
*/
static function ( $links ) {
if ( ! is_woocommerce_activated() ) {
return $links;
}
array_unshift(
$links,
sprintf(
'<a href="%1$s">%2$s</a>',
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' ),
__( 'Settings', 'woocommerce-paypal-payments' )
)
);
return $links;
}
);
add_filter(
'plugin_row_meta',
/**
* Add links below the description on the Plugins page.
*
* @param array $links
* @param string $file
* @return array
*/
static function ( $links, $file ) {
if ( plugin_basename( __FILE__ ) !== $file ) {
return $links;
}
return array_merge(
$links,
array(
sprintf(
'<a target="_blank" href="%1$s">%2$s</a>',
'https://woocommerce.com/document/woocommerce-paypal-payments/',
__( 'Documentation', 'woocommerce-paypal-payments' )
),
sprintf(
'<a target="_blank" href="%1$s">%2$s</a>',
'https://woocommerce.com/document/woocommerce-paypal-payments/#get-help',
__( 'Get help', 'woocommerce-paypal-payments' )
),
sprintf(
'<a target="_blank" href="%1$s">%2$s</a>',
'https://woocommerce.com/feature-requests/woocommerce-paypal-payments/',
__( 'Request a feature', 'woocommerce-paypal-payments' )
),
sprintf(
'<a target="_blank" href="%1$s">%2$s</a>',
'https://github.com/woocommerce/woocommerce-paypal-payments/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md',
__( 'Submit a bug', 'woocommerce-paypal-payments' )
),
)
);
},
10,
2
);
add_action(
'before_woocommerce_init',
static function () {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
/**
* Skip WC class check.
*
* @psalm-suppress UndefinedClass
*/
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);
/**
* Check if WooCommerce is active.
*
* @return bool true if WooCommerce is active, otherwise false.
*/
function is_woocommerce_activated(): bool {
return class_exists( 'woocommerce' );
}
} )();