From 392bb4f3ea19e99fee517ed798e2958894429a1d Mon Sep 17 00:00:00 2001 From: David Stone Date: Wed, 1 Apr 2026 11:40:47 -0600 Subject: [PATCH] fix(paypal): update disconnect disclaimer and show merchant status banners t523a: Replace generic disconnect confirm with PayPal's required disclaimer text per #727. t523b: Always persist payments_receivable and email_confirmed after OAuth, and display PayPal's exact required error banners in render_oauth_connection() when either flag is false per #728. Closes #727 Closes #728 --- inc/gateways/class-paypal-oauth-handler.php | 36 +++++++++++++---- inc/gateways/class-paypal-rest-gateway.php | 45 +++++++++++++++------ 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/inc/gateways/class-paypal-oauth-handler.php b/inc/gateways/class-paypal-oauth-handler.php index 16df60f5f..82c83941c 100644 --- a/inc/gateways/class-paypal-oauth-handler.php +++ b/inc/gateways/class-paypal-oauth-handler.php @@ -260,23 +260,43 @@ public function handle_oauth_return(): void { wu_save_setting('paypal_rest_connection_mode', $mode_prefix); // Store additional status info if available - if (! empty($merchant_status['paymentsReceivable'])) { - wu_save_setting("paypal_rest_{$mode_prefix}_payments_receivable", $merchant_status['paymentsReceivable']); - } + $payments_receivable = isset($merchant_status['paymentsReceivable']) ? (bool) $merchant_status['paymentsReceivable'] : true; + $email_confirmed = isset($merchant_status['emailConfirmed']) ? (bool) $merchant_status['emailConfirmed'] : true; - if (! empty($merchant_status['emailConfirmed'])) { - wu_save_setting("paypal_rest_{$mode_prefix}_email_confirmed", $merchant_status['emailConfirmed']); - } + wu_save_setting("paypal_rest_{$mode_prefix}_payments_receivable", $payments_receivable); + wu_save_setting("paypal_rest_{$mode_prefix}_email_confirmed", $email_confirmed); // Clean up the tracking transient delete_site_transient('wu_paypal_onboarding_' . $tracking_id); - wu_log_add('paypal', sprintf('PayPal OAuth completed. Merchant ID: %s, Mode: %s', $merchant_id, $mode_prefix)); + wu_log_add( + 'paypal', + sprintf( + 'PayPal OAuth completed. Merchant ID: %s, Mode: %s, payments_receivable: %s, email_confirmed: %s', + $merchant_id, + $mode_prefix, + $payments_receivable ? 'true' : 'false', + $email_confirmed ? 'true' : 'false' + ) + ); // Automatically install webhooks for the connected account $this->install_webhook_after_oauth($mode_prefix); - $this->add_oauth_notice('success', __('PayPal account connected successfully!', 'ultimate-multisite')); + // Show required PayPal error messages when merchant status is incomplete + if (! $payments_receivable) { + $this->add_oauth_notice( + 'error', + __('Your PayPal account is not yet able to receive payments. Please complete your PayPal account setup and try connecting again.', 'ultimate-multisite') + ); + } elseif (! $email_confirmed) { + $this->add_oauth_notice( + 'error', + __('Your PayPal account email address is not confirmed. Please confirm your email with PayPal and try connecting again.', 'ultimate-multisite') + ); + } else { + $this->add_oauth_notice('success', __('PayPal account connected successfully!', 'ultimate-multisite')); + } // Redirect to remove query parameters wp_safe_redirect( diff --git a/inc/gateways/class-paypal-rest-gateway.php b/inc/gateways/class-paypal-rest-gateway.php index e9c482e8f..b11005f33 100644 --- a/inc/gateways/class-paypal-rest-gateway.php +++ b/inc/gateways/class-paypal-rest-gateway.php @@ -1739,6 +1739,27 @@ public function render_oauth_connection(): void { $identifier = $status['details']['merchant_id'] ?? ($status['details']['email'] ?? ($status['details']['client_id'] ?? '')); + $mode_prefix = $this->test_mode ? 'sandbox' : 'live'; + $payments_receivable = (bool) wu_get_setting("paypal_rest_{$mode_prefix}_payments_receivable", true); + $email_confirmed = (bool) wu_get_setting("paypal_rest_{$mode_prefix}_email_confirmed", true); + + // Show required PayPal error banners when merchant status is incomplete + if (! $payments_receivable) { + printf( + '
+

%s

+
', + esc_html__('Attention: You currently cannot receive payments due to restriction on your PayPal account. Please reach out to PayPal Customer Support or connect to https://www.paypal.com for more information.', 'ultimate-multisite') + ); + } elseif (! $email_confirmed) { + printf( + '
+

%s

+
', + esc_html__('Attention: Please confirm your email address on https://www.paypal.com/businessprofile/settings in order to receive payments! You currently cannot receive payments.', 'ultimate-multisite') + ); + } + // Connected state printf( '
@@ -1888,22 +1909,22 @@ function () use ($nonce, $sandbox) { }); }); - $(".wu-paypal-disconnect").on("click", function(e) { - e.preventDefault(); - if (!confirm()) return; + $(".wu-paypal-disconnect").on("click", function(e) { + e.preventDefault(); + if (!confirm()) return; - var $btn = $(this); - $btn.prop("disabled", true); + var $btn = $(this); + $btn.prop("disabled", true); - $.post(ajaxurl, { - action: "wu_paypal_disconnect", - nonce: wuPayPalNonce - }, function(response) { - window.location.reload(); - }); + $.post(ajaxurl, { + action: "wu_paypal_disconnect", + nonce: wuPayPalNonce + }, function(response) { + window.location.reload(); }); }); - + }); +