From 3d8121510aecd9cb262a6e2fe3e598db1f99a1d3 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Wed, 12 Feb 2025 17:03:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Reset=20all=20settings=20on=20disco?= =?UTF-8?q?nnect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-settings/services.php | 31 ++++++++++--------- .../Endpoint/AuthenticationRestEndpoint.php | 23 ++++++++++++-- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 1f20a91af..e5ab98d74 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -126,6 +126,7 @@ return array( 'settings.rest.authentication' => static function ( ContainerInterface $container ) : AuthenticationRestEndpoint { return new AuthenticationRestEndpoint( $container->get( 'settings.service.authentication_manager' ), + $container->get( 'settings.service.data-manager' ) ); }, 'settings.rest.login_link' => static function ( ContainerInterface $container ) : LoginLinkRestEndpoint { @@ -284,14 +285,14 @@ return array( $container->get( 'settings.data.general' ) ); }, - 'settings.service.todos_eligibilities' => static function( ContainerInterface $container ): TodosEligibilityService { + 'settings.service.todos_eligibilities' => static function ( ContainerInterface $container ) : TodosEligibilityService { $features = apply_filters( 'woocommerce_paypal_payments_rest_common_merchant_features', array() ); $payment_endpoint = $container->get( 'settings.rest.payment' ); - $settings = $payment_endpoint->get_details()->get_data(); + $settings = $payment_endpoint->get_details()->get_data(); $pay_later_endpoint = $container->get( 'settings.rest.pay_later_messaging' ); $pay_later_settings = $pay_later_endpoint->get_details()->get_data(); @@ -326,20 +327,20 @@ return array( $is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses ); return new TodosEligibilityService( - $capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane. - $capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout. - $is_pay_later_messaging_enabled_for_any_location, // Enable Pay Later messaging. - ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['product'], // Add Pay Later messaging (Product page). - ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['cart'], // Add Pay Later messaging (Cart). - ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout). - true, // Configure a PayPal Subscription. - true, // Add PayPal buttons. - true, // Register Domain for Apple Pay. + $capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane. + $capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout. + $is_pay_later_messaging_enabled_for_any_location, // Enable Pay Later messaging. + ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['product'], // Add Pay Later messaging (Product page). + ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['cart'], // Add Pay Later messaging (Cart). + ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout). + true, // Configure a PayPal Subscription. + true, // Add PayPal buttons. + true, // Register Domain for Apple Pay. $capabilities['acdc'] && ! ( $capabilities['apple_pay'] && $capabilities['google_pay'] ), // Add digital wallets to your account. - $capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account. - $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account. - true, // Configure a PayPal Subscription. - $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay. + $capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account. + $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account. + true, // Configure a PayPal Subscription. + $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay. $capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay. ); }, diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php index 7ac964b2d..28f64946b 100644 --- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php @@ -14,6 +14,7 @@ use WP_REST_Request; use WP_REST_Response; use WP_REST_Server; use WooCommerce\PayPalCommerce\Settings\Service\AuthenticationManager; +use WooCommerce\PayPalCommerce\Settings\Service\SettingsDataManager; /** * REST controller for authenticating and connecting to a PayPal merchant account. @@ -40,6 +41,13 @@ class AuthenticationRestEndpoint extends RestEndpoint { */ private AuthenticationManager $authentication_manager; + /** + * Settings data manager service. + * + * @var SettingsDataManager + */ + private SettingsDataManager $data_manager; + /** * Defines the JSON response format (when connection was successful). * @@ -58,9 +66,12 @@ class AuthenticationRestEndpoint extends RestEndpoint { * Constructor. * * @param AuthenticationManager $authentication_manager The authentication manager. + * @param SettingsDataManager $data_manager Settings data manager, to reset + * settings. */ - public function __construct( AuthenticationManager $authentication_manager ) { + public function __construct( AuthenticationManager $authentication_manager, SettingsDataManager $data_manager ) { $this->authentication_manager = $authentication_manager; + $this->data_manager = $data_manager; } /** @@ -209,11 +220,19 @@ class AuthenticationRestEndpoint extends RestEndpoint { /** * Disconnect the merchant and clear the authentication details. * + * @param WP_REST_Request $request Full data about the request. + * * @return WP_REST_Response */ - public function disconnect() : WP_REST_Response { + public function disconnect( WP_REST_Request $request ) : WP_REST_Response { + $reset_settings = $request->get_param( 'reset' ); + $this->authentication_manager->disconnect(); + if ( $reset_settings ) { + $this->data_manager->reset_all_settings(); + } + return $this->return_success( 'OK' ); } }