Commit 1677515c13 for woocommerce
commit 1677515c13987a385bce20fea871f373bd524b6a
Author: Mayisha <33387139+Mayisha@users.noreply.github.com>
Date: Fri Dec 26 17:52:46 2025 +0600
PayPal Standard Refactor 1: Move constant file under src folder (#62595)
* create paypal standard constants class under includes
* deprecate old constant class
* Add changefile(s) from automation for the following project(s): woocommerce
* update version to remove deprecated file
* update version
* use constant from new class
diff --git a/plugins/woocommerce/changelog/62595-refactor-paypal-standard-1-constant-file b/plugins/woocommerce/changelog/62595-refactor-paypal-standard-1-constant-file
new file mode 100644
index 0000000000..e6155cb866
--- /dev/null
+++ b/plugins/woocommerce/changelog/62595-refactor-paypal-standard-1-constant-file
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Deprecate WC_Gateway_Paypal_Constants class in favor of Automattic\WooCommerce\Gateways\PayPal\Constants.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php b/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
index dd07241b8c..ca222b51d5 100644
--- a/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
+++ b/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
@@ -13,15 +13,12 @@
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Enums\PaymentGatewayFeature;
use Automattic\Jetpack\Connection\Manager as Jetpack_Connection_Manager;
+use Automattic\WooCommerce\Gateways\PayPal\Constants as PayPalConstants;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
-if ( ! class_exists( 'WC_Gateway_Paypal_Constants' ) ) {
- require_once __DIR__ . '/includes/class-wc-gateway-paypal-constants.php';
-}
-
if ( ! class_exists( 'WC_Gateway_Paypal_Helper' ) ) {
require_once __DIR__ . '/includes/class-wc-gateway-paypal-helper.php';
}
@@ -520,7 +517,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
*/
public function is_valid_for_use() {
if ( $this->should_use_orders_v2() ) {
- $valid_currencies = WC_Gateway_Paypal_Constants::SUPPORTED_CURRENCIES;
+ $valid_currencies = PayPalConstants::SUPPORTED_CURRENCIES;
} else {
$valid_currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
}
diff --git a/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-constants.php b/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-constants.php
index a607ec3ce8..e677da891e 100644
--- a/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-constants.php
+++ b/plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-constants.php
@@ -4,8 +4,9 @@
*
* Provides constants for PayPal payment statuses, intents, and other PayPal-related values.
*
- * @version 10.3.0
- * @package WooCommerce\Gateways
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants instead. This class will be removed in 11.0.0.
+ * @version 10.3.0
+ * @package WooCommerce\Gateways
*/
declare(strict_types=1);
@@ -14,118 +15,102 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
+use Automattic\WooCommerce\Gateways\PayPal\Constants as PayPalConstants;
+
/**
* WC_Gateway_Paypal_Constants Class.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants instead. This class will be removed in 11.0.0.
*/
class WC_Gateway_Paypal_Constants {
/**
* PayPal proxy request timeout.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::WPCOM_PROXY_REQUEST_TIMEOUT instead.
*/
- const WPCOM_PROXY_REQUEST_TIMEOUT = 60;
+ const WPCOM_PROXY_REQUEST_TIMEOUT = PayPalConstants::WPCOM_PROXY_REQUEST_TIMEOUT;
/**
* PayPal payment statuses.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::STATUS_* instead.
*/
- const STATUS_COMPLETED = 'COMPLETED';
- const STATUS_APPROVED = 'APPROVED';
- const STATUS_CAPTURED = 'CAPTURED';
- const STATUS_AUTHORIZED = 'AUTHORIZED';
- const STATUS_PAYER_ACTION_REQUIRED = 'PAYER_ACTION_REQUIRED';
- const VOIDED = 'VOIDED';
+ const STATUS_COMPLETED = PayPalConstants::STATUS_COMPLETED;
+ const STATUS_APPROVED = PayPalConstants::STATUS_APPROVED;
+ const STATUS_CAPTURED = PayPalConstants::STATUS_CAPTURED;
+ const STATUS_AUTHORIZED = PayPalConstants::STATUS_AUTHORIZED;
+ const STATUS_PAYER_ACTION_REQUIRED = PayPalConstants::STATUS_PAYER_ACTION_REQUIRED;
+ const VOIDED = PayPalConstants::VOIDED;
/**
* PayPal payment intents.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::INTENT_* instead.
*/
- const INTENT_CAPTURE = 'CAPTURE';
- const INTENT_AUTHORIZE = 'AUTHORIZE';
+ const INTENT_CAPTURE = PayPalConstants::INTENT_CAPTURE;
+ const INTENT_AUTHORIZE = PayPalConstants::INTENT_AUTHORIZE;
/**
* PayPal payment actions.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::PAYMENT_ACTION_* instead.
*/
- const PAYMENT_ACTION_CAPTURE = 'capture';
- const PAYMENT_ACTION_AUTHORIZE = 'authorize';
+ const PAYMENT_ACTION_CAPTURE = PayPalConstants::PAYMENT_ACTION_CAPTURE;
+ const PAYMENT_ACTION_AUTHORIZE = PayPalConstants::PAYMENT_ACTION_AUTHORIZE;
/**
* PayPal shipping preferences.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::SHIPPING_* instead.
*/
- const SHIPPING_NO_SHIPPING = 'NO_SHIPPING';
- const SHIPPING_GET_FROM_FILE = 'GET_FROM_FILE';
- const SHIPPING_SET_PROVIDED_ADDRESS = 'SET_PROVIDED_ADDRESS';
+ const SHIPPING_NO_SHIPPING = PayPalConstants::SHIPPING_NO_SHIPPING;
+ const SHIPPING_GET_FROM_FILE = PayPalConstants::SHIPPING_GET_FROM_FILE;
+ const SHIPPING_SET_PROVIDED_ADDRESS = PayPalConstants::SHIPPING_SET_PROVIDED_ADDRESS;
/**
* PayPal user actions.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::USER_ACTION_* instead.
*/
- const USER_ACTION_PAY_NOW = 'PAY_NOW';
+ const USER_ACTION_PAY_NOW = PayPalConstants::USER_ACTION_PAY_NOW;
/**
* Maximum lengths for PayPal fields.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::PAYPAL_* instead.
*/
- const PAYPAL_ORDER_ITEM_NAME_MAX_LENGTH = 127;
- const PAYPAL_INVOICE_ID_MAX_LENGTH = 127;
- const PAYPAL_ADDRESS_LINE_MAX_LENGTH = 300;
- const PAYPAL_COUNTRY_CODE_LENGTH = 2;
- const PAYPAL_STATE_MAX_LENGTH = 300;
- const PAYPAL_CITY_MAX_LENGTH = 120;
- const PAYPAL_POSTAL_CODE_MAX_LENGTH = 60;
- const PAYPAL_LOCALE_MAX_LENGTH = 10;
+ const PAYPAL_ORDER_ITEM_NAME_MAX_LENGTH = PayPalConstants::PAYPAL_ORDER_ITEM_NAME_MAX_LENGTH;
+ const PAYPAL_INVOICE_ID_MAX_LENGTH = PayPalConstants::PAYPAL_INVOICE_ID_MAX_LENGTH;
+ const PAYPAL_ADDRESS_LINE_MAX_LENGTH = PayPalConstants::PAYPAL_ADDRESS_LINE_MAX_LENGTH;
+ const PAYPAL_COUNTRY_CODE_LENGTH = PayPalConstants::PAYPAL_COUNTRY_CODE_LENGTH;
+ const PAYPAL_STATE_MAX_LENGTH = PayPalConstants::PAYPAL_STATE_MAX_LENGTH;
+ const PAYPAL_CITY_MAX_LENGTH = PayPalConstants::PAYPAL_CITY_MAX_LENGTH;
+ const PAYPAL_POSTAL_CODE_MAX_LENGTH = PayPalConstants::PAYPAL_POSTAL_CODE_MAX_LENGTH;
+ const PAYPAL_LOCALE_MAX_LENGTH = PayPalConstants::PAYPAL_LOCALE_MAX_LENGTH;
/**
* Supported payment sources.
+ *
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::PAYMENT_SOURCE_* instead.
*/
- const PAYMENT_SOURCE_PAYPAL = 'paypal';
- const PAYMENT_SOURCE_VENMO = 'venmo';
- const PAYMENT_SOURCE_PAYLATER = 'paylater';
- const SUPPORTED_PAYMENT_SOURCES = array( self::PAYMENT_SOURCE_PAYPAL, self::PAYMENT_SOURCE_VENMO, self::PAYMENT_SOURCE_PAYLATER );
+ const PAYMENT_SOURCE_PAYPAL = PayPalConstants::PAYMENT_SOURCE_PAYPAL;
+ const PAYMENT_SOURCE_VENMO = PayPalConstants::PAYMENT_SOURCE_VENMO;
+ const PAYMENT_SOURCE_PAYLATER = PayPalConstants::PAYMENT_SOURCE_PAYLATER;
+ const SUPPORTED_PAYMENT_SOURCES = PayPalConstants::SUPPORTED_PAYMENT_SOURCES;
/**
* Fields to redact from logs.
*
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::FIELDS_TO_REDACT instead.
* @var array
*/
- const FIELDS_TO_REDACT = array(
- 'given_name',
- 'surname',
- 'full_name',
- 'address_line_1',
- 'address_line_2',
- 'admin_area_1',
- 'admin_area_2',
- 'postal_code',
- 'phone',
- 'phone_number',
- 'national_number',
- );
+ const FIELDS_TO_REDACT = PayPalConstants::FIELDS_TO_REDACT;
/**
* List of currencies supported by PayPal (Orders API V2).
*
+ * @deprecated 10.5.0 Use Automattic\WooCommerce\Gateways\PayPal\Constants::SUPPORTED_CURRENCIES instead.
* @var array<string>
*/
- const SUPPORTED_CURRENCIES = array(
- 'AUD', // Australian Dollar.
- 'BRL', // Brazilian Real.
- 'CAD', // Canadian Dollar.
- 'CNY', // Chinese Renminbi.
- 'CZK', // Czech Koruna.
- 'DKK', // Danish Krone.
- 'EUR', // Euro.
- 'HKD', // Hong Kong Dollar.
- 'HUF', // Hungarian Forint.
- 'ILS', // Israeli New Shekel.
- 'JPY', // Japanese Yen.
- 'MYR', // Malaysian Ringgit.
- 'MXN', // Mexican Peso.
- 'TWD', // New Taiwan Dollar.
- 'NZD', // New Zealand Dollar.
- 'NOK', // Norwegian Krone.
- 'PHP', // Philippine Peso.
- 'PLN', // Polish Złoty.
- 'GBP', // Pound Sterling.
- 'SGD', // Singapore Dollar.
- 'SEK', // Swedish Krona.
- 'CHF', // Swiss Franc.
- 'THB', // Thai Baht.
- 'USD', // United States Dollar.
- 'RUB', // Russian Ruble.
- );
+ const SUPPORTED_CURRENCIES = PayPalConstants::SUPPORTED_CURRENCIES;
}
diff --git a/plugins/woocommerce/src/Gateways/PayPal/Constants.php b/plugins/woocommerce/src/Gateways/PayPal/Constants.php
new file mode 100644
index 0000000000..e4a998c705
--- /dev/null
+++ b/plugins/woocommerce/src/Gateways/PayPal/Constants.php
@@ -0,0 +1,125 @@
+<?php
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\Gateways\PayPal;
+
+/**
+ * PayPal Gateway Constants.
+ *
+ * Provides constants for PayPal payment statuses, intents, and other PayPal-related values.
+ *
+ * @since 10.5.0
+ */
+class Constants {
+ /**
+ * PayPal proxy request timeout.
+ */
+ const WPCOM_PROXY_REQUEST_TIMEOUT = 60;
+
+ /**
+ * PayPal payment statuses.
+ */
+ const STATUS_COMPLETED = 'COMPLETED';
+ const STATUS_APPROVED = 'APPROVED';
+ const STATUS_CAPTURED = 'CAPTURED';
+ const STATUS_AUTHORIZED = 'AUTHORIZED';
+ const STATUS_PAYER_ACTION_REQUIRED = 'PAYER_ACTION_REQUIRED';
+ const VOIDED = 'VOIDED';
+
+ /**
+ * PayPal payment intents.
+ */
+ const INTENT_CAPTURE = 'CAPTURE';
+ const INTENT_AUTHORIZE = 'AUTHORIZE';
+
+ /**
+ * PayPal payment actions.
+ */
+ const PAYMENT_ACTION_CAPTURE = 'capture';
+ const PAYMENT_ACTION_AUTHORIZE = 'authorize';
+
+ /**
+ * PayPal shipping preferences.
+ */
+ const SHIPPING_NO_SHIPPING = 'NO_SHIPPING';
+ const SHIPPING_GET_FROM_FILE = 'GET_FROM_FILE';
+ const SHIPPING_SET_PROVIDED_ADDRESS = 'SET_PROVIDED_ADDRESS';
+
+ /**
+ * PayPal user actions.
+ */
+ const USER_ACTION_PAY_NOW = 'PAY_NOW';
+
+ /**
+ * Maximum lengths for PayPal fields.
+ */
+ const PAYPAL_ORDER_ITEM_NAME_MAX_LENGTH = 127;
+ const PAYPAL_INVOICE_ID_MAX_LENGTH = 127;
+ const PAYPAL_ADDRESS_LINE_MAX_LENGTH = 300;
+ const PAYPAL_COUNTRY_CODE_LENGTH = 2;
+ const PAYPAL_STATE_MAX_LENGTH = 300;
+ const PAYPAL_CITY_MAX_LENGTH = 120;
+ const PAYPAL_POSTAL_CODE_MAX_LENGTH = 60;
+ const PAYPAL_LOCALE_MAX_LENGTH = 10;
+
+ /**
+ * Supported payment sources.
+ */
+ const PAYMENT_SOURCE_PAYPAL = 'paypal';
+ const PAYMENT_SOURCE_VENMO = 'venmo';
+ const PAYMENT_SOURCE_PAYLATER = 'paylater';
+ const SUPPORTED_PAYMENT_SOURCES = array( self::PAYMENT_SOURCE_PAYPAL, self::PAYMENT_SOURCE_VENMO, self::PAYMENT_SOURCE_PAYLATER );
+
+ /**
+ * Fields to redact from logs.
+ *
+ * @var array
+ */
+ const FIELDS_TO_REDACT = array(
+ 'given_name',
+ 'surname',
+ 'full_name',
+ 'address_line_1',
+ 'address_line_2',
+ 'admin_area_1',
+ 'admin_area_2',
+ 'postal_code',
+ 'phone',
+ 'phone_number',
+ 'national_number',
+ );
+
+ /**
+ * List of currencies supported by PayPal (Orders API V2).
+ *
+ * @var array<string>
+ */
+ const SUPPORTED_CURRENCIES = array(
+ 'AUD', // Australian Dollar.
+ 'BRL', // Brazilian Real.
+ 'CAD', // Canadian Dollar.
+ 'CNY', // Chinese Renminbi.
+ 'CZK', // Czech Koruna.
+ 'DKK', // Danish Krone.
+ 'EUR', // Euro.
+ 'HKD', // Hong Kong Dollar.
+ 'HUF', // Hungarian Forint.
+ 'ILS', // Israeli New Shekel.
+ 'JPY', // Japanese Yen.
+ 'MYR', // Malaysian Ringgit.
+ 'MXN', // Mexican Peso.
+ 'TWD', // New Taiwan Dollar.
+ 'NZD', // New Zealand Dollar.
+ 'NOK', // Norwegian Krone.
+ 'PHP', // Philippine Peso.
+ 'PLN', // Polish Złoty.
+ 'GBP', // Pound Sterling.
+ 'SGD', // Singapore Dollar.
+ 'SEK', // Swedish Krona.
+ 'CHF', // Swiss Franc.
+ 'THB', // Thai Baht.
+ 'USD', // United States Dollar.
+ 'RUB', // Russian Ruble.
+ );
+}