From 7b6e7efa8aac9cde89a8399a158561173497560e Mon Sep 17 00:00:00 2001 From: Zvonimir Maglica Date: Thu, 19 Dec 2024 09:21:00 +0100 Subject: [PATCH] Remove hooks from customer service constructor (#9992) --- .../dev-7264-remove-hooks-from-customer-service-constructor | 4 ++++ dev/phpcs/WCPay/ruleset.xml | 4 ---- includes/class-wc-payments-customer-service.php | 5 +++++ includes/class-wc-payments-token-service.php | 5 +++++ includes/class-wc-payments.php | 2 ++ 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 changelog/dev-7264-remove-hooks-from-customer-service-constructor diff --git a/changelog/dev-7264-remove-hooks-from-customer-service-constructor b/changelog/dev-7264-remove-hooks-from-customer-service-constructor new file mode 100644 index 00000000000..d912717fc31 --- /dev/null +++ b/changelog/dev-7264-remove-hooks-from-customer-service-constructor @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Remove hooks from customer and token services to dedicated methods diff --git a/dev/phpcs/WCPay/ruleset.xml b/dev/phpcs/WCPay/ruleset.xml index 9806ccfe9e7..7c8cefbd0e3 100644 --- a/dev/phpcs/WCPay/ruleset.xml +++ b/dev/phpcs/WCPay/ruleset.xml @@ -17,10 +17,6 @@ */includes/class-wc-payments-order-success-page.php - - */includes/class-wc-payments-customer-service.php - */includes/class-wc-payments-token-service.php - */includes/class-wc-payments-webhook-reliability-service.php diff --git a/includes/class-wc-payments-customer-service.php b/includes/class-wc-payments-customer-service.php index 05f95c32d31..d0f97e061c0 100644 --- a/includes/class-wc-payments-customer-service.php +++ b/includes/class-wc-payments-customer-service.php @@ -99,7 +99,12 @@ public function __construct( $this->database_cache = $database_cache; $this->session_service = $session_service; $this->order_service = $order_service; + } + /** + * Initialize hooks + */ + public function init_hooks() { /* * Adds the WooCommerce Payments customer ID found in the user session * to the WordPress user as metadata. diff --git a/includes/class-wc-payments-token-service.php b/includes/class-wc-payments-token-service.php index 7bfdc482e18..283a0d7851a 100644 --- a/includes/class-wc-payments-token-service.php +++ b/includes/class-wc-payments-token-service.php @@ -47,7 +47,12 @@ class WC_Payments_Token_Service { public function __construct( WC_Payments_API_Client $payments_api_client, WC_Payments_Customer_Service $customer_service ) { $this->payments_api_client = $payments_api_client; $this->customer_service = $customer_service; + } + /** + * Initializes hooks. + */ + public function init_hooks() { add_action( 'woocommerce_payment_token_deleted', [ $this, 'woocommerce_payment_token_deleted' ], 10, 2 ); add_action( 'woocommerce_payment_token_set_default', [ $this, 'woocommerce_payment_token_set_default' ], 10, 2 ); add_filter( 'woocommerce_get_customer_payment_tokens', [ $this, 'woocommerce_get_customer_payment_tokens' ], 10, 3 ); diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index 17300478794..32c75df5fc7 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -554,6 +554,8 @@ public static function init() { self::$onboarding_service->init_hooks(); self::$incentives_service->init_hooks(); self::$compatibility_service->init_hooks(); + self::$customer_service->init_hooks(); + self::$token_service->init_hooks(); $payment_method_classes = [ CC_Payment_Method::class,