Commit 5468602b183 for woocommerce
commit 5468602b183be7586e9038d702ac1e260d00e4e7
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date: Thu Dec 3 14:17:59 2026 +0200
Send PayPal Standard IPN checks to PayPal's ipnpb host (#71643)
* fix(paypal): Send IPN verification to PayPal's ipnpb host
PayPal Standard checks each incoming IPN by posting it back to PayPal
and waiting for VERIFIED. WooCommerce posted to www.paypal.com and
www.sandbox.paypal.com, but PayPal's IPN listener guide names
ipnpb.paypal.com and ipnpb.sandbox.paypal.com for this call, and its
reference listener uses them. A merchant reported random HTTP 403s on
the old host that left paid orders unverified and later cancelled;
PayPal support traced it to the old URL.
Move the IPN postback to the ipnpb hosts. The System Status "Remote
post" check posts the same _notify-validate command, so move it too,
so a green check tests the host the store really uses. Both hosts
answer that command with 200, as www does.
PDT (_notify-synch), the checkout redirect and transaction links stay
on www: PayPal documents those there. WooCommerce Subscriptions
inherits the fix, since its PayPal Standard handler relies on core's
validate_ipn().
Stores that restrict outgoing requests to the old host must allow
ipnpb.paypal.com and ipnpb.sandbox.paypal.com.
Refs WOOPLUG-282
Refs #28513
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(system-status): Cover the remote post check's PayPal host
No PHP test checked the System Status "Remote post" check: nothing
asserted which URL it posts to or that a 2xx marks it as working.
Mutation testing showed it, since negating the check's guard went
unnoticed, and so would a revert of the host change in the previous
commit.
Request the environment section, record every POST, and assert the
check posts once to ipnpb.paypal.com and reports success. The test
fails against trunk's controller, which still posts to www.paypal.com.
Refs WOOPLUG-282
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(paypal): Name the URL when the IPN check cannot reach PayPal
When the IPN verification postback fails at the transport level, such
as a firewall drop or a DNS failure, WordPress returns only the cURL
error, so the PayPal log never said which host was unreachable. With
verification now on the ipnpb hosts, a store whose outgoing allowlist
has only www.paypal.com would see the check fail with no hint of which
host to allow, while the order waits in pending.
Log the failure at error level with the verification URL. As before,
the PayPal log is written only when the gateway's Debug log setting is
on.
Refs WOOPLUG-282
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/28513-paypal-ipn-verification-urls b/plugins/woocommerce/changelog/28513-paypal-ipn-verification-urls
new file mode 100644
index 00000000000..c2f9730a4e1
--- /dev/null
+++ b/plugins/woocommerce/changelog/28513-paypal-ipn-verification-urls
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Verify PayPal Standard payment notifications on PayPal's ipnpb.paypal.com host. Stores that restrict outgoing requests must allow ipnpb.paypal.com and ipnpb.sandbox.paypal.com.
diff --git a/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php b/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php
index a70d70416e1..9cd32850fe0 100644
--- a/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php
+++ b/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php
@@ -99,7 +99,8 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
);
// Post back to get a response.
- $response = wp_safe_remote_post( $this->sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
+ $validation_url = $this->sandbox ? 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr' : 'https://ipnpb.paypal.com/cgi-bin/webscr';
+ $response = wp_safe_remote_post( $validation_url, $params );
WC_Gateway_Paypal::log( 'IPN Response: ' . wc_print_r( $response, true ) );
@@ -112,7 +113,8 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
WC_Gateway_Paypal::log( 'Received invalid response from PayPal IPN' );
if ( is_wp_error( $response ) ) {
- WC_Gateway_Paypal::log( 'Error response: ' . $response->get_error_message() );
+ // Name the host: a firewall or DNS failure returns only the cURL error, which does not say which host was unreachable.
+ WC_Gateway_Paypal::log( 'Error response from ' . $validation_url . ': ' . $response->get_error_message(), 'error' );
}
return false;
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
index 1d4c81a926d..ae02c96b931 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
@@ -1101,7 +1101,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
if ( false === $post_response_code || is_wp_error( $post_response_code ) ) {
$response = wp_safe_remote_post(
- 'https://www.paypal.com/cgi-bin/webscr',
+ 'https://ipnpb.paypal.com/cgi-bin/webscr',
array(
'timeout' => 10,
'user-agent' => 'WooCommerce/' . WC()->version . '; ' . get_bloginfo( 'url' ),
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/system-status.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/system-status.php
index b09709af3a1..0a9c0039421 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/system-status.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version2/system-status.php
@@ -447,7 +447,7 @@ class WC_Tests_REST_System_Status_V2 extends WC_REST_Unit_Test_Case {
);
}
- if ( 'www.paypal.com' === $host && '/cgi-bin/webscr' === $path && 'POST' === $method ) {
+ if ( 'ipnpb.paypal.com' === $host && '/cgi-bin/webscr' === $path && 'POST' === $method ) {
return array(
'headers' => array(
'cache-for' => '',
diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/system-status.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/system-status.php
index 6c290e4830e..4b8a97de69c 100644
--- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/system-status.php
+++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/system-status.php
@@ -200,6 +200,33 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
$this->assertEquals( $expected_data, $data );
}
+ /**
+ * @testdox Should report remote post as working after posting the IPN check command to PayPal's ipnpb host.
+ */
+ public function test_get_system_status_info_environment_remote_post(): void {
+ delete_transient( 'woocommerce_test_remote_post' );
+ $posted_urls = array();
+ add_filter(
+ 'pre_http_request',
+ function ( $preempt, $args, $url ) use ( &$posted_urls ) {
+ if ( 'POST' === ( $args['method'] ?? '' ) ) {
+ $posted_urls[] = $url;
+ }
+ return $preempt;
+ },
+ 1,
+ 3
+ );
+ wp_set_current_user( self::$administrator_user );
+
+ $request = new WP_REST_Request( 'GET', '/wc/v3/system_status' );
+ $request->set_query_params( array( '_fields' => 'environment' ) );
+ $environment = (array) $this->server->dispatch( $request )->get_data()['environment'];
+
+ $this->assertSame( array( 'https://ipnpb.paypal.com/cgi-bin/webscr' ), $posted_urls, 'The remote post check should post once, to the host the PayPal IPN check uses.' );
+ $this->assertTrue( $environment['remote_post_successful'], 'A 2xx response should mark remote post as working.' );
+ }
+
/**
* Test to make sure database response is correct.
*
@@ -561,7 +588,7 @@ class WC_Tests_REST_System_Status extends WC_REST_Unit_Test_Case {
protected function mock_http_responses( $request, $url ) {
$mocked_response = false;
- if ( in_array( $url, array( 'https://www.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0' ), true ) ) {
+ if ( in_array( $url, array( 'https://ipnpb.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0' ), true ) ) {
$mocked_response = array(
'response' => array( 'code' => 200 ),
);
diff --git a/plugins/woocommerce/tests/php/includes/gateways/paypal/class-wc-gateway-paypal-test.php b/plugins/woocommerce/tests/php/includes/gateways/paypal/class-wc-gateway-paypal-test.php
index 476dd02717c..0a1f72de88a 100644
--- a/plugins/woocommerce/tests/php/includes/gateways/paypal/class-wc-gateway-paypal-test.php
+++ b/plugins/woocommerce/tests/php/includes/gateways/paypal/class-wc-gateway-paypal-test.php
@@ -173,6 +173,93 @@ class WC_Gateway_Paypal_Test extends \WC_Unit_Test_Case {
$this->assertEquals( $order->get_meta( PayPalConstants::PAYPAL_ORDER_META_STATUS ), 'Completed' );
}
+ /**
+ * @testdox Should send the IPN verification postback to PayPal's ipnpb host for the gateway mode.
+ *
+ * @testWith [false, "https://ipnpb.paypal.com/cgi-bin/webscr"]
+ * [true, "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr"]
+ *
+ * @param bool $sandbox Whether the gateway runs in sandbox mode.
+ * @param string $expected_url The URL PayPal documents for IPN verification in that mode.
+ */
+ public function test_validate_ipn_posts_to_ipnpb_host( bool $sandbox, string $expected_url ): void {
+ include_once WC_ABSPATH . 'includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php';
+
+ $requested_url = null;
+ add_filter(
+ 'pre_http_request',
+ function ( $preempt, $args, $url ) use ( &$requested_url ) {
+ $requested_url = $url;
+ return array(
+ 'headers' => array(),
+ 'body' => 'VERIFIED',
+ 'response' => array(
+ 'code' => 200,
+ 'message' => 'OK',
+ ),
+ 'cookies' => array(),
+ 'filename' => null,
+ );
+ },
+ 10,
+ 3
+ );
+
+ $original_post = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Saved only to restore it after the test.
+ $_POST = array( 'txn_id' => $this->transaction_id_26960 );
+ try {
+ $is_valid = ( new WC_Gateway_Paypal_IPN_Handler( $sandbox ) )->validate_ipn();
+ } finally {
+ $_POST = $original_post;
+ }
+
+ $this->assertSame( $expected_url, $requested_url, 'The IPN verification postback should go to the URL PayPal documents for IPN listeners.' );
+ $this->assertTrue( $is_valid, 'A VERIFIED response from PayPal should validate the IPN.' );
+ }
+
+ /**
+ * @testdox Should log a failed IPN verification request as an error that names the PayPal URL.
+ */
+ public function test_validate_ipn_logs_transport_error_with_url(): void {
+ include_once WC_ABSPATH . 'includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php';
+
+ add_filter(
+ 'pre_http_request',
+ function () {
+ return new WP_Error( 'http_request_failed', 'cURL error 7: Failed to connect' );
+ }
+ );
+
+ $logged = array();
+ $logger = $this->createMock( \WC_Logger_Interface::class );
+ $logger->method( 'log' )->willReturnCallback(
+ function ( $level, $message ) use ( &$logged ) {
+ $logged[] = array( $level, $message );
+ }
+ );
+
+ $original_log_enabled = WC_Gateway_Paypal::$log_enabled;
+ $original_log = WC_Gateway_Paypal::$log;
+ $original_post = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Saved only to restore it after the test.
+ WC_Gateway_Paypal::$log_enabled = true;
+ WC_Gateway_Paypal::$log = $logger;
+ $_POST = array( 'txn_id' => $this->transaction_id_26960 );
+ try {
+ $is_valid = ( new WC_Gateway_Paypal_IPN_Handler( false ) )->validate_ipn();
+ } finally {
+ WC_Gateway_Paypal::$log_enabled = $original_log_enabled;
+ WC_Gateway_Paypal::$log = $original_log;
+ $_POST = $original_post;
+ }
+
+ $this->assertFalse( $is_valid, 'A failed verification request should not validate the IPN.' );
+ $this->assertContains(
+ array( 'error', 'Error response from https://ipnpb.paypal.com/cgi-bin/webscr: cURL error 7: Failed to connect' ),
+ $logged,
+ 'The transport error should be logged at error level with the URL it failed to reach.'
+ );
+ }
+
/**
* Test that correct settings are displayed when Orders v2 is enabled.
*/