Reset all settings on disconnect

This commit is contained in:
Philipp Stracker 2025-02-12 17:03:00 +01:00
parent d8bd774744
commit 3d8121510a
No known key found for this signature in database
2 changed files with 37 additions and 17 deletions

View file

@ -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 {

View file

@ -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' );
}
}