Commit d181adf021 for woocommerce
commit d181adf0210e7c345611c36f257e21ac99c64dde
Author: Mayisha <33387139+Mayisha@users.noreply.github.com>
Date: Fri Jan 30 16:04:27 2026 +0600
PayPal Standard: Use the new classes in the rest controllers (#62790)
* use the new classes in the rest controllers
* Add changefile(s) from automation for the following project(s): woocommerce
* fix phpstan issue
* update baseline
* require the deprecated classes for backward compatibility
diff --git a/plugins/woocommerce/changelog/62790-refactor-use-new-paypal-standard-classes-in-rest-controller b/plugins/woocommerce/changelog/62790-refactor-use-new-paypal-standard-classes-in-rest-controller
new file mode 100644
index 0000000000..65cbe4a317
--- /dev/null
+++ b/plugins/woocommerce/changelog/62790-refactor-use-new-paypal-standard-classes-in-rest-controller
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Update PayPal REST API controllers to use new namespaced classes instead of deprecated WC_Gateway_Paypal_* classes.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
index 4eaa4e86e8..7fe84d1c55 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
@@ -13,7 +13,10 @@ defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Gateways\PayPal\Constants as PayPalConstants;
+use Automattic\WooCommerce\Gateways\PayPal\Request as PayPalRequest;
+// Require the deprecated classes for backward compatibility.
+// This will be removed in 11.0.0.
if ( ! class_exists( 'WC_Gateway_Paypal_Constants' ) ) {
require_once WC_ABSPATH . 'includes/gateways/paypal/includes/class-wc-gateway-paypal-constants.php';
}
@@ -22,7 +25,6 @@ if ( ! class_exists( 'WC_Gateway_Paypal_Request' ) ) {
require_once WC_ABSPATH . 'includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php';
}
-
/**
* REST API PayPal buttons controller class.
*
@@ -114,14 +116,14 @@ class WC_REST_Paypal_Buttons_Controller extends WC_REST_Controller {
}
$payment_source = isset( $data['payment_source'] ) ? sanitize_text_field( $data['payment_source'] ) : '';
- if ( empty( $payment_source ) || ! in_array( $payment_source, WC_Gateway_Paypal_Constants::SUPPORTED_PAYMENT_SOURCES, true ) ) {
+ if ( empty( $payment_source ) || ! in_array( $payment_source, PayPalConstants::SUPPORTED_PAYMENT_SOURCES, true ) ) {
return new WP_REST_Response( array( 'error' => 'Missing/Invalid payment source: ' . esc_html( $payment_source ) ), 400 );
}
$order_id = $data['order_id'];
$order = wc_get_order( $order_id );
- if ( ! $order ) {
+ if ( ! $order || ! ( $order instanceof \WC_Order ) ) {
return new WP_REST_Response( array( 'error' => 'Order not found' ), 404 );
}
@@ -140,7 +142,7 @@ class WC_REST_Paypal_Buttons_Controller extends WC_REST_Controller {
$order->set_payment_method( $gateway->id );
$order->save();
- $paypal_request = new WC_Gateway_Paypal_Request( $gateway );
+ $paypal_request = new PayPalRequest( $gateway );
$paypal_order = $paypal_request->create_paypal_order(
$order,
$payment_source,
@@ -184,7 +186,7 @@ class WC_REST_Paypal_Buttons_Controller extends WC_REST_Controller {
}
$order = wc_get_order( $order_id );
- if ( ! $order ) {
+ if ( ! $order || ! ( $order instanceof \WC_Order ) ) {
return new WP_REST_Response( array( 'error' => 'Order not found' ), 404 );
}
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller.php
index adb9979913..1aca48e526 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-paypal-standard-controller.php
@@ -13,14 +13,15 @@ declare(strict_types=1);
defined( 'ABSPATH' ) || exit;
-if ( ! class_exists( 'WC_Gateway_Paypal_Helper' ) ) {
- require_once WC_ABSPATH . 'includes/gateways/paypal/includes/class-wc-gateway-paypal-helper.php';
-}
+use Automattic\WooCommerce\Gateways\PayPal\Helper as PayPalHelper;
+use Automattic\WooCommerce\Gateways\PayPal\Request as PayPalRequest;
if ( ! class_exists( 'WC_Gateway_Paypal' ) ) {
require_once WC_ABSPATH . 'includes/gateways/paypal/class-wc-gateway-paypal.php';
}
+// Require the deprecated classes for backward compatibility.
+// This will be removed in 11.0.0.
if ( ! class_exists( 'WC_Gateway_Paypal_Request' ) ) {
require_once WC_ABSPATH . 'includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php';
}
@@ -84,7 +85,7 @@ class WC_REST_Paypal_Standard_Controller extends WC_REST_Controller {
}
// Get the WC order.
- $order = WC_Gateway_Paypal_Helper::get_wc_order_from_paypal_custom_id( $purchase_units[0]['custom_id'] ?? '{}' );
+ $order = PayPalHelper::get_wc_order_from_paypal_custom_id( $purchase_units[0]['custom_id'] ?? '{}' );
if ( ! $order ) {
$custom_id = isset( $purchase_units[0]['custom_id'] ) ? $purchase_units[0]['custom_id'] : '{}';
WC_Gateway_Paypal::log( 'Unable to determine WooCommerce order from PayPal custom ID: ' . $custom_id );
@@ -135,7 +136,7 @@ class WC_REST_Paypal_Standard_Controller extends WC_REST_Controller {
// Recompute fees after everything has been updated.
$this->recompute_fees( $order );
- $paypal_request = new WC_Gateway_Paypal_Request( WC_Gateway_Paypal::get_instance() );
+ $paypal_request = new PayPalRequest( WC_Gateway_Paypal::get_instance() );
$updated_amount = $paypal_request->get_paypal_order_purchase_unit_amount( $order );
$response = array(
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index b0dca53332..1a469548c9 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -33192,24 +33192,6 @@ parameters:
count: 1
path: includes/rest-api/Controllers/Version3/class-wc-rest-payment-gateways-controller.php
- -
- message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:get_order_key\(\)\.$#'
- identifier: method.notFound
- count: 1
- path: includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
-
- -
- message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:set_payment_method\(\)\.$#'
- identifier: method.notFound
- count: 1
- path: includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
-
- -
- message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:update_status\(\)\.$#'
- identifier: method.notFound
- count: 2
- path: includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
-
-
message: '#^Method WC_REST_Paypal_Buttons_Controller\:\:cancel_payment\(\) has parameter \$request with generic class WP_REST_Request but does not specify its types\: T$#'
identifier: missingType.generics
@@ -33258,18 +33240,6 @@ parameters:
count: 1
path: includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
- -
- message: '#^Parameter \#1 \$order of method WC_Gateway_Paypal_Request\:\:create_paypal_order\(\) expects WC_Order, WC_Order\|WC_Order_Refund given\.$#'
- identifier: argument.type
- count: 1
- path: includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
-
- -
- message: '#^Parameter \#1 \$order of method WC_Payment_Gateway\:\:get_return_url\(\) expects WC_Order\|null, WC_Order\|WC_Order_Refund given\.$#'
- identifier: argument.type
- count: 1
- path: includes/rest-api/Controllers/Version3/class-wc-rest-paypal-buttons-controller.php
-
-
message: '#^Access to an undefined property WooCommerce\:\:\$checkout\.$#'
identifier: property.notFound