mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
✨ Reset all settings on disconnect
This commit is contained in:
parent
d8bd774744
commit
3d8121510a
2 changed files with 37 additions and 17 deletions
|
@ -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,7 +285,7 @@ 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()
|
||||
|
|
|
@ -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' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue