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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Gateways / PayPal / Notices.php
woocommerce / src / Gateways / PayPal Last commit date
AddressRequirements.php 8 months ago Buttons.php 5 months ago Constants.php 3 months ago Helper.php 3 months ago Notices.php 5 months ago Request.php 2 months ago TransactAccountManager.php 5 months ago WebhookHandler.php 3 months ago
Notices.php
323 lines
1 <?php
2
3 declare( strict_types=1 );
4
5 namespace Automattic\WooCommerce\Gateways\PayPal;
6
7 use WC_Order;
8 use Automattic\WooCommerce\Gateways\PayPal\Helper as PayPalHelper;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * PayPal Notices Class
14 *
15 * Handles admin notices for PayPal gateway including migration notices,
16 * account restriction warnings, and currency support notifications.
17 *
18 * @since 10.5.0
19 */
20 class Notices {
21 /**
22 * The name of the notice for PayPal migration.
23 *
24 * @since 10.5.0
25 * @var string
26 */
27 private const PAYPAL_MIGRATION_NOTICE = 'paypal_migration_completed';
28
29 /**
30 * The name of the notice for PayPal account restriction.
31 *
32 * @since 10.5.0
33 * @var string
34 */
35 private const PAYPAL_ACCOUNT_RESTRICTED_NOTICE = 'paypal_account_restricted';
36
37 /**
38 * The name of the notice for PayPal unsupported currency.
39 *
40 * @since 10.5.0
41 * @var string
42 */
43 private const PAYPAL_UNSUPPORTED_CURRENCY_NOTICE = 'paypal_unsupported_currency';
44
45 /**
46 * PayPal account restriction issue codes from PayPal API.
47 *
48 * @since 10.5.0
49 * @var array
50 */
51 protected const PAYPAL_ACCOUNT_RESTRICTION_ISSUES = array(
52 Constants::PAYPAL_ISSUE_PAYEE_ACCOUNT_LOCKED_OR_CLOSED,
53 Constants::PAYPAL_ISSUE_PAYEE_ACCOUNT_RESTRICTED,
54 );
55
56 /**
57 * The PayPal gateway instance.
58 *
59 * @var \WC_Gateway_Paypal
60 */
61 private $gateway;
62
63 /**
64 * Constructor.
65 */
66 public function __construct() {
67 $this->gateway = \WC_Gateway_Paypal::get_instance();
68 if ( ! $this->gateway ) {
69 return;
70 }
71
72 // Only register admin notice hooks in the admin area.
73 if ( is_admin() ) {
74 add_action( 'admin_notices', array( $this, 'add_paypal_notices' ) );
75
76 // Use admin_head to inject notice on payments settings page.
77 // This bypasses the suppress_admin_notices() function which removes all admin_notices hooks on the payments page.
78 // This is a workaround to avoid the notice being suppressed by the suppress_admin_notices() function.
79 add_action( 'admin_head', array( $this, 'add_paypal_notices_on_payments_settings_page' ) );
80 }
81 }
82
83 /**
84 * Add PayPal Standard notices.
85 *
86 * @since 10.5.0
87 * @return void
88 */
89 public function add_paypal_notices(): void {
90 // Show only to users who can manage the site.
91 if ( ! current_user_can( 'manage_woocommerce' ) && ! current_user_can( 'manage_options' ) ) {
92 return;
93 }
94
95 // Skip if the gateway is not available or the merchant has not been onboarded.
96 if ( ! PayPalHelper::is_paypal_gateway_available() || ! $this->gateway->should_use_orders_v2() ) {
97 return;
98 }
99
100 $this->add_paypal_migration_notice();
101 $this->add_paypal_account_restricted_notice();
102 $this->add_paypal_unsupported_currency_notice();
103 }
104
105 /**
106 * Add PayPal notices on the payments settings page.
107 *
108 * @since 10.5.0
109 * @return void
110 */
111 public function add_paypal_notices_on_payments_settings_page(): void {
112 global $current_tab, $current_section;
113
114 $screen = get_current_screen();
115 $screen_id = $screen ? $screen->id : '';
116
117 $is_payments_settings_page = 'woocommerce_page_wc-settings' === $screen_id && 'checkout' === $current_tab && empty( $current_section );
118
119 // Only add the notice from this callback on the payments settings page.
120 if ( ! $is_payments_settings_page ) {
121 return;
122 }
123
124 $this->add_paypal_notices();
125 }
126
127 /**
128 * Add notice warning about the migration to PayPal Payments.
129 *
130 * @since 10.5.0
131 * @return void
132 */
133 public function add_paypal_migration_notice(): void {
134 // Skip if the notice has been dismissed.
135 if ( $this->is_notice_dismissed( self::PAYPAL_MIGRATION_NOTICE ) ) {
136 return;
137 }
138
139 $doc_url = 'https://woocommerce.com/document/woocommerce-paypal-payments/paypal-payments-upgrade-guide/';
140 $dismiss_url = $this->get_dismiss_url( self::PAYPAL_MIGRATION_NOTICE );
141 $message = sprintf(
142 /* translators: 1: opening <a> tag, 2: closing </a> tag */
143 esc_html__( 'WooCommerce has upgraded your PayPal integration from PayPal Standard to PayPal Payments (PPCP), for a more reliable and modern checkout experience. If you do not prefer the upgraded integration in WooCommerce, we recommend switching to %1$sPayPal Payments%2$s extension.', 'woocommerce' ),
144 '<a href="' . esc_url( $doc_url ) . '" target="_blank" rel="noopener noreferrer">',
145 '</a>',
146 );
147
148 $notice_html = '<div class="notice notice-warning is-dismissible">'
149 . '<a class="woocommerce-message-close notice-dismiss" style="text-decoration: none;" href="' . esc_url( $dismiss_url ) . '" aria-label="' . esc_attr__( 'Dismiss this notice', 'woocommerce' ) . '"></a>'
150 . '<p>' . $message . '</p>'
151 . '</div>';
152
153 echo wp_kses_post( $notice_html );
154 }
155
156 /**
157 * Add notice warning about PayPal account restriction.
158 *
159 * @since 10.5.0
160 * @return void
161 */
162 private function add_paypal_account_restricted_notice(): void {
163 // Skip if there's no account restriction flag.
164 if ( ! $this->has_account_restriction_flag() ) {
165 return;
166 }
167
168 // Skip if the notice has been dismissed.
169 if ( $this->is_notice_dismissed( self::PAYPAL_ACCOUNT_RESTRICTED_NOTICE ) ) {
170 return;
171 }
172
173 $support_url = 'https://www.paypal.com/smarthelp/contact-us';
174 $dismiss_url = $this->get_dismiss_url( self::PAYPAL_ACCOUNT_RESTRICTED_NOTICE );
175 $message = sprintf(
176 /* translators: 1: opening <a> tag, 2: closing </a> tag */
177 esc_html__( 'Your PayPal account has been restricted by PayPal. This may prevent customers from completing payments. Please %1$scontact PayPal support%2$s to resolve this issue and restore full functionality to your account.', 'woocommerce' ),
178 '<a href="' . esc_url( $support_url ) . '" target="_blank" rel="noopener noreferrer">',
179 '</a>',
180 );
181
182 $notice_html = '<div class="notice notice-error is-dismissible">'
183 . '<a class="woocommerce-message-close notice-dismiss" style="text-decoration: none;" href="' . esc_url( $dismiss_url ) . '" aria-label="' . esc_attr__( 'Dismiss this notice', 'woocommerce' ) . '"></a>'
184 . '<p><strong>' . esc_html__( 'PayPal Account Restricted', 'woocommerce' ) . '</strong></p>'
185 . '<p>' . $message . '</p>'
186 . '</div>';
187
188 echo wp_kses_post( $notice_html );
189 }
190
191 /**
192 * Add notice warning when PayPal does not support the store's currency.
193 *
194 * @since 10.5.0
195 * @return void
196 */
197 private function add_paypal_unsupported_currency_notice(): void {
198 $currency = get_woocommerce_currency();
199
200 // Skip if the currency is supported by PayPal.
201 if ( $this->gateway->is_valid_for_use() ) {
202 return;
203 }
204
205 // Skip if the notice has been dismissed.
206 if ( $this->is_notice_dismissed( self::PAYPAL_UNSUPPORTED_CURRENCY_NOTICE ) ) {
207 return;
208 }
209
210 $dismiss_url = $this->get_dismiss_url( self::PAYPAL_UNSUPPORTED_CURRENCY_NOTICE );
211 $message = sprintf(
212 /* translators: %s: Currency code */
213 esc_html__( 'PayPal Standard does not support your store currency (%s).', 'woocommerce' ),
214 $currency
215 );
216
217 $notice_html = '<div class="notice notice-error is-dismissible">'
218 . '<a class="woocommerce-message-close notice-dismiss" style="text-decoration: none;" href="' . esc_url( $dismiss_url ) . '" aria-label="' . esc_attr__( 'Dismiss this notice', 'woocommerce' ) . '"></a>'
219 . '<p>' . $message . '</p>'
220 . '</div>';
221
222 echo wp_kses_post( $notice_html );
223 }
224
225 /**
226 * Get the dismiss URL for a notice.
227 *
228 * @since 10.5.0
229 * @param string $notice_name The name of the notice.
230 * @return string
231 */
232 private function get_dismiss_url( string $notice_name ): string {
233 return wp_nonce_url(
234 add_query_arg( 'wc-hide-notice', $notice_name ),
235 'woocommerce_hide_notices_nonce',
236 '_wc_notice_nonce'
237 );
238 }
239
240 /**
241 * Check if the notice has been dismissed.
242 *
243 * User meta keys for notice dismissals:
244 * - dismissed_paypal_migration_completed_notice
245 * - dismissed_paypal_account_restricted_notice
246 * - dismissed_paypal_unsupported_currency_notice
247 *
248 * The meta keys are set by WC_Admin_Notices when the notice is dismissed by the user.
249 *
250 * @since 10.5.0
251 * @param string $notice_name The name of the notice.
252 * @return bool
253 */
254 private function is_notice_dismissed( string $notice_name ): bool {
255 return (bool) get_user_meta( get_current_user_id(), 'dismissed_' . $notice_name . '_notice', true );
256 }
257
258 /**
259 * Check if there's a flag indicating PayPal account restriction.
260 *
261 * @since 10.5.0
262 * @return bool
263 */
264 private function has_account_restriction_flag(): bool {
265 return 'yes' === get_option( 'woocommerce_paypal_account_restricted_status', 'no' );
266 }
267
268 /**
269 * Set the flag indicating PayPal account restriction.
270 *
271 * @since 10.5.0
272 * @return void
273 */
274 public static function set_account_restriction_flag(): void {
275 if ( 'no' === get_option( 'woocommerce_paypal_account_restricted_status', 'no' ) ) {
276 update_option( 'woocommerce_paypal_account_restricted_status', 'yes', false );
277 }
278 }
279
280 /**
281 * Clear the flag indicating PayPal account restriction.
282 *
283 * @since 10.5.0
284 * @return void
285 */
286 public static function clear_account_restriction_flag(): void {
287 if ( 'yes' === get_option( 'woocommerce_paypal_account_restricted_status', 'no' ) ) {
288 update_option( 'woocommerce_paypal_account_restricted_status', 'no' );
289 }
290 }
291
292 /**
293 * Handle PayPal order response to manage account restriction notices.
294 *
295 * @since 10.5.0
296 * @param int|string $http_code The HTTP status code from the PayPal API response.
297 * @param array $response_data The decoded response data from the PayPal API.
298 * @param WC_Order $order The WooCommerce order object.
299 * @return void
300 */
301 public static function manage_account_restriction_flag_for_notice( $http_code, array $response_data, WC_Order $order ): void {
302 // Clear the restriction flag on successful responses.
303 if ( in_array( (int) $http_code, array( 200, 201 ), true ) ) {
304 self::clear_account_restriction_flag();
305 return;
306 }
307
308 if ( empty( $response_data ) ) {
309 return;
310 }
311
312 // Set the restriction flag for account-related errors.
313 if ( 422 === (int) $http_code ) {
314 $issue = isset( $response_data['details'][0]['issue'] ) ? $response_data['details'][0]['issue'] : '';
315
316 if ( in_array( $issue, self::PAYPAL_ACCOUNT_RESTRICTION_ISSUES, true ) ) {
317 \WC_Gateway_Paypal::log( 'PayPal account restriction flag set due to issues when handling the order: ' . $order->get_id() );
318 self::set_account_restriction_flag();
319 }
320 }
321 }
322 }
323