-
Notifications
You must be signed in to change notification settings - Fork 47
/
woocommerce-paypal-payments.php
235 lines (210 loc) · 7.1 KB
/
woocommerce-paypal-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
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
<?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: 2.9.4
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
* Requires PHP: 7.4
* Requires Plugins: woocommerce
* WC requires at least: 6.9
* WC tested up to: 9.3
* Text Domain: woocommerce-paypal-payments
*
* @package WooCommerce\PayPalCommerce
*/
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
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', '2024-11-05' );
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' );
( function () {
$autoload_filepath = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $autoload_filepath ) && ! class_exists( '\WooCommerce\PayPalCommerce\PluginModule' ) ) {
require $autoload_filepath;
}
/**
* Initialize the plugin and its modules.
*/
function init(): void {
$root_dir = __DIR__;
if ( ! is_woocommerce_activated() ) {
add_action(
'admin_notices',
function() {
/* translators: 1. URL link. */
echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'WooCommerce PayPal Payments requires WooCommerce to be installed and active. You can download %s here.', 'woocommerce-paypal-payments' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
}
);
return;
}
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
add_action(
'admin_notices',
function() {
echo '<div class="error"><p>' . esc_html__( 'WooCommerce PayPal Payments requires PHP 7.4 or above.', 'woocommerce-paypal-payments' ), '</p></div>';
}
);
return;
}
static $initialized;
if ( ! $initialized ) {
$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 );
}
}
add_action(
'plugins_loaded',
function () {
init();
if ( ! function_exists( 'get_plugin_data' ) ) {
/**
* Skip check for WP files.
*
* @psalm-suppress MissingFile
*/
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php', false );
$plugin_version = $plugin_data['Version'] ?? null;
$installed_plugin_version = get_option( 'woocommerce-ppcp-version' );
if ( $installed_plugin_version !== $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' );
}
update_option( 'woocommerce-ppcp-version', $plugin_version );
}
}
);
register_activation_hook(
__FILE__,
function () {
init();
/**
* The hook fired in register_activation_hook.
*/
do_action( 'woocommerce_paypal_payments_gateway_activate' );
}
);
register_deactivation_hook(
__FILE__,
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
* @retun array
*/
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&ppcp-tab=' . Settings::CONNECTION_TAB_ID ),
__( '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
* @retun array
*/
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',
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' );
}
} )();