From ea9ecbeb23f9c4fec88dcdfd557c08a2d8c61ba4 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 19:19:15 +0400 Subject: [PATCH 01/15] Create the simple redirect task --- .../WcTasks/Tasks/SimpleRedirectTask.php | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php new file mode 100644 index 000000000..b187f6b17 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php @@ -0,0 +1,120 @@ +id = $id; + $this->title = $title; + $this->description = $description; + $this->redirect_url = $redirect_url; + } + + /** + * The task ID. + * + * @return string + */ + public function get_id(): string { + return $this->id; + } + + /** + * The task title. + * + * @return string + */ + public function get_title(): string { + return $this->title; + } + + /** + * The task content. + * + * @return string + */ + public function get_content(): string { + return ''; + } + + /** + * The task time. + * + * @return string + */ + public function get_time(): string { + return $this->description; + } + + /** + * The task redirection URL. + * + * @return string + */ + public function get_action_url(): string { + return $this->redirect_url; + } + + /** + * The task completion. + * + * We need to set the task completed when the redirection happened for the first time. + * So this method of a parent class should be overridden. + * + * @return bool + */ + public function is_complete(): bool { + return parent::is_visited(); + } +} From dd216475619041c335558e7d53c0ac0948e1c7bf Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 19:19:38 +0400 Subject: [PATCH 02/15] Create the factory for simple redirect task creation --- .../Factory/SimpleRedirectTaskFactory.php | 23 ++++++++++++++++ .../SimpleRedirectTaskFactoryInterface.php | 26 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php new file mode 100644 index 000000000..7f9d6e893 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php @@ -0,0 +1,23 @@ + Date: Wed, 11 Sep 2024 19:19:51 +0400 Subject: [PATCH 03/15] Create the task registrar --- .../WcTasks/Registrar/TaskRegistrar.php | 32 +++++++++++++++++++ .../Registrar/TaskRegistrarInterface.php | 25 +++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrarInterface.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php new file mode 100644 index 000000000..174e60e6b --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php @@ -0,0 +1,32 @@ +get_error_message() ); + } + } + } +} diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrarInterface.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrarInterface.php new file mode 100644 index 000000000..992b41150 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrarInterface.php @@ -0,0 +1,25 @@ + Date: Wed, 11 Sep 2024 19:20:04 +0400 Subject: [PATCH 04/15] Add the services and configs --- modules/ppcp-wc-gateway/services.php | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 6ca2ecafe..f487818c5 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -29,6 +29,11 @@ use WooCommerce\PayPalCommerce\WcGateway\Endpoint\CaptureCardPayment; use WooCommerce\PayPalCommerce\WcGateway\Endpoint\RefreshFeatureStatusEndpoint; use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector; use WooCommerce\PayPalCommerce\WcGateway\Helper\FeesUpdater; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Factory\SimpleRedirectTaskFactory; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Factory\SimpleRedirectTaskFactoryInterface; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrar; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrarInterface; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Tasks\SimpleRedirectTask; use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer; @@ -1762,4 +1767,58 @@ return array( $container->get( 'woocommerce.logger.woocommerce' ) ); }, + + 'wcgateway.settings.wc-tasks.simple-redirect-task-factory' => static function(): SimpleRedirectTaskFactoryInterface { + return new SimpleRedirectTaskFactory(); + }, + 'wcgateway.settings.wc-tasks.task-registrar' => static function(): TaskRegistrarInterface { + return new TaskRegistrar(); + }, + + /** + * A configuration for simple redirect wc tasks. + * + * @returns array + */ + 'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' => static function(): array { + $section_id = PayPalGateway::ID; + $pay_later_tab_id = Settings::PAY_LATER_TAB_ID; + + return array( + array( + 'id' => 'pay-later-messaging-task', + 'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ), + 'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ), + 'redirect_url' => admin_url("admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}"), + ), + ); + }, + + /** + * Retrieves the list of simple redirect task instances. + * + * @returns SimpleRedirectTask[] + */ + 'wcgateway.settings.wc-tasks.simple-redirect-tasks' => static function( ContainerInterface $container ): array { + $simple_redirect_tasks_config = $container->get( 'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' ); + $simple_redirect_task_factory = $container->get( 'wcgateway.settings.wc-tasks.simple-redirect-task-factory' ); + assert( $simple_redirect_task_factory instanceof SimpleRedirectTaskFactoryInterface ); + + $simple_redirect_tasks = array(); + + foreach ( $simple_redirect_tasks_config as $config ) { + $id = $config['id'] ?? ''; + $title = $config['title'] ?? ''; + $description = $config['description'] ?? ''; + $redirect_url = $config['redirect_url'] ?? ''; + $simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url ); + } + + return $simple_redirect_tasks; + }, ); From 12d17a7990ce40786ebae82ae1d9d24ab4763d7e Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 19:20:19 +0400 Subject: [PATCH 05/15] Register the tasks --- .../ppcp-wc-gateway/src/WCGatewayModule.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 09cceda99..eab936f52 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway; +use Exception; use Psr\Log\LoggerInterface; use Throwable; use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message; @@ -55,6 +56,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener; use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer; use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrarInterface; /** * Class WcGatewayModule @@ -86,6 +88,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul $this->register_order_functionality( $c ); $this->register_columns( $c ); $this->register_checkout_paypal_address_preset( $c ); + $this->register_wc_tasks( $c ); add_action( 'woocommerce_sections_checkout', @@ -831,4 +834,30 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul 2 ); } + + /** + * Registers the tasks inside "Things to do next" WC section. + * + * @param ContainerInterface $container The container. + * @return void + */ + protected function register_wc_tasks( ContainerInterface $container ): void { + $simple_redirect_tasks = $container->get( 'wcgateway.settings.wc-tasks.simple-redirect-tasks' ); + $task_registrar = $container->get( 'wcgateway.settings.wc-tasks.task-registrar' ); + assert( $task_registrar instanceof TaskRegistrarInterface ); + + $logger = $container->get( 'woocommerce.logger.woocommerce' ); + assert( $logger instanceof LoggerInterface ); + + add_action( + 'init', + static function () use ( $simple_redirect_tasks, $task_registrar, $logger ): void { + try { + $task_registrar->register( $simple_redirect_tasks ); + } catch ( Exception $exception ) { + $logger->error( "Failed to create a task in the 'Things to do next' section of WC. " . $exception->getMessage() ); + } + }, + ); + } } From 4fb62c5c72f872ad6eeef455874e424e0f62a72f Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 19:41:12 +0400 Subject: [PATCH 06/15] Add stubs for WC Task --- tests/stubs/Task.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/stubs/Task.php diff --git a/tests/stubs/Task.php b/tests/stubs/Task.php new file mode 100644 index 000000000..1d2461c90 --- /dev/null +++ b/tests/stubs/Task.php @@ -0,0 +1,36 @@ + Date: Wed, 11 Sep 2024 19:44:57 +0400 Subject: [PATCH 07/15] Add stubs for WC Task --- tests/stubs/Task.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/stubs/Task.php b/tests/stubs/Task.php index 1d2461c90..d0e3c23c1 100644 --- a/tests/stubs/Task.php +++ b/tests/stubs/Task.php @@ -1,9 +1,7 @@ Date: Wed, 11 Sep 2024 19:46:48 +0400 Subject: [PATCH 08/15] Add stubs for WC Task --- tests/PHPUnit/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index 8910b0241..647473e12 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -10,5 +10,6 @@ require_once TESTS_ROOT_DIR . '/stubs/WC_Payment_Gateway.php'; require_once TESTS_ROOT_DIR . '/stubs/WC_Payment_Gateway_CC.php'; require_once TESTS_ROOT_DIR . '/stubs/WC_Ajax.php'; require_once TESTS_ROOT_DIR . '/stubs/WC_Checkout.php'; +require_once TESTS_ROOT_DIR . '/stubs/Task.php'; Hamcrest\Util::registerGlobalFunctions(); From 15a8a0d9d0e515973190cbc09c2e472cdc662699 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 20:18:46 +0400 Subject: [PATCH 09/15] Add condition to check if pay later task should be enabled --- modules/ppcp-wc-gateway/services.php | 9 +++++--- .../Factory/SimpleRedirectTaskFactory.php | 4 ++-- .../SimpleRedirectTaskFactoryInterface.php | 3 ++- .../WcTasks/Registrar/TaskRegistrar.php | 5 +++++ .../WcTasks/Tasks/SimpleRedirectTask.php | 21 ++++++++++++++++++- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index f487818c5..4bacab63a 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1782,10 +1782,11 @@ return array( * id: string, * title: string, * description: string, - * redirect_url: string + * redirect_url: string, + * is_enabled: bool * }> */ - 'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' => static function(): array { + 'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' => static function( ContainerInterface $container ): array { $section_id = PayPalGateway::ID; $pay_later_tab_id = Settings::PAY_LATER_TAB_ID; @@ -1795,6 +1796,7 @@ return array( 'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ), 'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ), 'redirect_url' => admin_url("admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}"), + 'is_enabled' => $container->get('paylater-configurator.is-available'), ), ); }, @@ -1816,7 +1818,8 @@ return array( $title = $config['title'] ?? ''; $description = $config['description'] ?? ''; $redirect_url = $config['redirect_url'] ?? ''; - $simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url ); + $is_enabled = $config['is_enabled'] ?? false; + $simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url, $is_enabled ); } return $simple_redirect_tasks; diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php index 7f9d6e893..be21d6cfa 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php @@ -17,7 +17,7 @@ class SimpleRedirectTaskFactory implements SimpleRedirectTaskFactoryInterface { /** * {@inheritDoc} */ - public function create_task( string $id, string $title, string $description, string $redirect_url ): SimpleRedirectTask { - return new SimpleRedirectTask( $id, $title, $description, $redirect_url ); + public function create_task( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ): SimpleRedirectTask { + return new SimpleRedirectTask( $id, $title, $description, $redirect_url, $is_enabled ); } } diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php index 8931622d4..f8d17b57f 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php @@ -20,7 +20,8 @@ interface SimpleRedirectTaskFactoryInterface { * @param string $title The task title. * @param string $description The task description. * @param string $redirect_url The redirection URL. + * @param bool $is_enabled Whether the task is enabled. * @return SimpleRedirectTask The task. */ - public function create_task( string $id, string $title, string $description, string $redirect_url ): SimpleRedirectTask; + public function create_task( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ): SimpleRedirectTask; } diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php index 174e60e6b..c710c7a09 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php @@ -9,6 +9,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists; use RuntimeException; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Tasks\SimpleRedirectTask; use WP_Error; /** @@ -23,6 +24,10 @@ class TaskRegistrar implements TaskRegistrarInterface { */ public function register( array $tasks ): void { foreach ( $tasks as $task ) { + if ( $task instanceof SimpleRedirectTask && ! $task->is_enabled() ) { + return; + } + $added_task = TaskLists::add_task( 'extended', $task ); if ( $added_task instanceof WP_Error ) { throw new RuntimeException( $added_task->get_error_message() ); diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php index b187f6b17..104a9be6d 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php @@ -44,6 +44,14 @@ class SimpleRedirectTask extends Task { */ protected string $redirect_url; + /** + * Whether the task is enabled. + * + * @var bool + */ + protected bool $is_enabled; + + /** * SimpleRedirectTask constructor. * @@ -51,14 +59,16 @@ class SimpleRedirectTask extends Task { * @param string $title The task title. * @param string $description The task description. * @param string $redirect_url The redirection URL. + * @param bool $is_enabled Whether the task is enabled. */ - public function __construct( string $id, string $title, string $description, string $redirect_url ) { + public function __construct( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ) { parent::__construct(); $this->id = $id; $this->title = $title; $this->description = $description; $this->redirect_url = $redirect_url; + $this->is_enabled = $is_enabled; } /** @@ -106,6 +116,15 @@ class SimpleRedirectTask extends Task { return $this->redirect_url; } + /** + * Whether the task is enabled. + * + * @return bool + */ + public function is_enabled(): bool { + return $this->is_enabled; + } + /** * The task completion. * From 42a6cb2b45ba2a42c69fe0ebbece12ac1e485a16 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 20:23:09 +0400 Subject: [PATCH 10/15] Continue instead of exit --- .../src/Settings/WcTasks/Registrar/TaskRegistrar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php index c710c7a09..c7ec4b5d5 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php @@ -25,7 +25,7 @@ class TaskRegistrar implements TaskRegistrarInterface { public function register( array $tasks ): void { foreach ( $tasks as $task ) { if ( $task instanceof SimpleRedirectTask && ! $task->is_enabled() ) { - return; + continue; } $added_task = TaskLists::add_task( 'extended', $task ); From 137a8b4975977c9eac5c04ab418fb984289735d1 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 20:28:31 +0400 Subject: [PATCH 11/15] Early return instead of complicating the task --- modules/ppcp-wc-gateway/services.php | 16 +++++++------- .../Factory/SimpleRedirectTaskFactory.php | 4 ++-- .../SimpleRedirectTaskFactoryInterface.php | 3 +-- .../WcTasks/Tasks/SimpleRedirectTask.php | 21 +------------------ .../ppcp-wc-gateway/src/WCGatewayModule.php | 6 +++++- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 4bacab63a..e0001821c 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1790,15 +1790,18 @@ return array( $section_id = PayPalGateway::ID; $pay_later_tab_id = Settings::PAY_LATER_TAB_ID; - return array( - array( + $list_of_config = array(); + + if ( $container->get('paylater-configurator.is-available') ) { + $list_of_config[] = array( 'id' => 'pay-later-messaging-task', 'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ), 'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ), 'redirect_url' => admin_url("admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}"), - 'is_enabled' => $container->get('paylater-configurator.is-available'), - ), - ); + ); + } + + return $list_of_config; }, /** @@ -1818,8 +1821,7 @@ return array( $title = $config['title'] ?? ''; $description = $config['description'] ?? ''; $redirect_url = $config['redirect_url'] ?? ''; - $is_enabled = $config['is_enabled'] ?? false; - $simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url, $is_enabled ); + $simple_redirect_tasks[] = $simple_redirect_task_factory->create_task( $id, $title, $description, $redirect_url ); } return $simple_redirect_tasks; diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php index be21d6cfa..7f9d6e893 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactory.php @@ -17,7 +17,7 @@ class SimpleRedirectTaskFactory implements SimpleRedirectTaskFactoryInterface { /** * {@inheritDoc} */ - public function create_task( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ): SimpleRedirectTask { - return new SimpleRedirectTask( $id, $title, $description, $redirect_url, $is_enabled ); + public function create_task( string $id, string $title, string $description, string $redirect_url ): SimpleRedirectTask { + return new SimpleRedirectTask( $id, $title, $description, $redirect_url ); } } diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php index f8d17b57f..8931622d4 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Factory/SimpleRedirectTaskFactoryInterface.php @@ -20,8 +20,7 @@ interface SimpleRedirectTaskFactoryInterface { * @param string $title The task title. * @param string $description The task description. * @param string $redirect_url The redirection URL. - * @param bool $is_enabled Whether the task is enabled. * @return SimpleRedirectTask The task. */ - public function create_task( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ): SimpleRedirectTask; + public function create_task( string $id, string $title, string $description, string $redirect_url ): SimpleRedirectTask; } diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php index 104a9be6d..b187f6b17 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Tasks/SimpleRedirectTask.php @@ -44,14 +44,6 @@ class SimpleRedirectTask extends Task { */ protected string $redirect_url; - /** - * Whether the task is enabled. - * - * @var bool - */ - protected bool $is_enabled; - - /** * SimpleRedirectTask constructor. * @@ -59,16 +51,14 @@ class SimpleRedirectTask extends Task { * @param string $title The task title. * @param string $description The task description. * @param string $redirect_url The redirection URL. - * @param bool $is_enabled Whether the task is enabled. */ - public function __construct( string $id, string $title, string $description, string $redirect_url, bool $is_enabled ) { + public function __construct( string $id, string $title, string $description, string $redirect_url ) { parent::__construct(); $this->id = $id; $this->title = $title; $this->description = $description; $this->redirect_url = $redirect_url; - $this->is_enabled = $is_enabled; } /** @@ -116,15 +106,6 @@ class SimpleRedirectTask extends Task { return $this->redirect_url; } - /** - * Whether the task is enabled. - * - * @return bool - */ - public function is_enabled(): bool { - return $this->is_enabled; - } - /** * The task completion. * diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index eab936f52..5a7ca2c62 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -843,7 +843,11 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul */ protected function register_wc_tasks( ContainerInterface $container ): void { $simple_redirect_tasks = $container->get( 'wcgateway.settings.wc-tasks.simple-redirect-tasks' ); - $task_registrar = $container->get( 'wcgateway.settings.wc-tasks.task-registrar' ); + if ( empty( $simple_redirect_tasks ) ) { + return; + } + + $task_registrar = $container->get( 'wcgateway.settings.wc-tasks.task-registrar' ); assert( $task_registrar instanceof TaskRegistrarInterface ); $logger = $container->get( 'woocommerce.logger.woocommerce' ); From 216654418cd7e72014c59d73312e991b2721460b Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 20:29:36 +0400 Subject: [PATCH 12/15] Fix the dockblock --- modules/ppcp-wc-gateway/services.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index e0001821c..a78be7a54 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1782,8 +1782,7 @@ return array( * id: string, * title: string, * description: string, - * redirect_url: string, - * is_enabled: bool + * redirect_url: string * }> */ 'wcgateway.settings.wc-tasks.simple-redirect-tasks-config' => static function( ContainerInterface $container ): array { From 09b6e09df442ad9f7f10a112c8e4605da7cc9a37 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 11 Sep 2024 20:31:19 +0400 Subject: [PATCH 13/15] Remove the leftover check --- .../src/Settings/WcTasks/Registrar/TaskRegistrar.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php index c7ec4b5d5..174e60e6b 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcTasks/Registrar/TaskRegistrar.php @@ -9,7 +9,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists; use RuntimeException; -use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Tasks\SimpleRedirectTask; use WP_Error; /** @@ -24,10 +23,6 @@ class TaskRegistrar implements TaskRegistrarInterface { */ public function register( array $tasks ): void { foreach ( $tasks as $task ) { - if ( $task instanceof SimpleRedirectTask && ! $task->is_enabled() ) { - continue; - } - $added_task = TaskLists::add_task( 'extended', $task ); if ( $added_task instanceof WP_Error ) { throw new RuntimeException( $added_task->get_error_message() ); From 4309689365db63aff10b00e0e060589a26a1ee64 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 12 Sep 2024 12:11:39 +0200 Subject: [PATCH 14/15] Add namespace and constructor to stub task class --- tests/stubs/Task.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/stubs/Task.php b/tests/stubs/Task.php index d0e3c23c1..0a577cebe 100644 --- a/tests/stubs/Task.php +++ b/tests/stubs/Task.php @@ -1,9 +1,22 @@ task_list = $task_list; + } + /** * ID. * From 2722c3f326f95bf88c1f165c9bccf13beb0bee67 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 12 Sep 2024 14:23:42 +0400 Subject: [PATCH 15/15] Fix the coding styles --- modules/ppcp-wc-gateway/services.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index a78be7a54..a23de8457 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1791,12 +1791,12 @@ return array( $list_of_config = array(); - if ( $container->get('paylater-configurator.is-available') ) { + if ( $container->get( 'paylater-configurator.is-available' ) ) { $list_of_config[] = array( 'id' => 'pay-later-messaging-task', 'title' => __( 'Configure PayPal Pay Later messaging', 'woocommerce-paypal-payments' ), 'description' => __( 'Decide where you want dynamic Pay Later messaging to show up and how you want it to look on your site.', 'woocommerce-paypal-payments' ), - 'redirect_url' => admin_url("admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}"), + 'redirect_url' => admin_url( "admin.php?page=wc-settings&tab=checkout§ion={$section_id}&ppcp-tab={$pay_later_tab_id}" ), ); }