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 {
|
'settings.rest.authentication' => static function ( ContainerInterface $container ) : AuthenticationRestEndpoint {
|
||||||
return new AuthenticationRestEndpoint(
|
return new AuthenticationRestEndpoint(
|
||||||
$container->get( 'settings.service.authentication_manager' ),
|
$container->get( 'settings.service.authentication_manager' ),
|
||||||
|
$container->get( 'settings.service.data-manager' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'settings.rest.login_link' => static function ( ContainerInterface $container ) : LoginLinkRestEndpoint {
|
'settings.rest.login_link' => static function ( ContainerInterface $container ) : LoginLinkRestEndpoint {
|
||||||
|
@ -284,14 +285,14 @@ return array(
|
||||||
$container->get( 'settings.data.general' )
|
$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(
|
$features = apply_filters(
|
||||||
'woocommerce_paypal_payments_rest_common_merchant_features',
|
'woocommerce_paypal_payments_rest_common_merchant_features',
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
|
|
||||||
$payment_endpoint = $container->get( 'settings.rest.payment' );
|
$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_endpoint = $container->get( 'settings.rest.pay_later_messaging' );
|
||||||
$pay_later_settings = $pay_later_endpoint->get_details()->get_data();
|
$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 );
|
$is_pay_later_messaging_enabled_for_any_location = ! array_filter( $pay_later_statuses );
|
||||||
|
|
||||||
return new TodosEligibilityService(
|
return new TodosEligibilityService(
|
||||||
$capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane.
|
$capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane.
|
||||||
$capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout.
|
$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, // 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['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['cart'], // Add Pay Later messaging (Cart).
|
||||||
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout).
|
! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout).
|
||||||
true, // Configure a PayPal Subscription.
|
true, // Configure a PayPal Subscription.
|
||||||
true, // Add PayPal buttons.
|
true, // Add PayPal buttons.
|
||||||
true, // Register Domain for Apple Pay.
|
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'] && $capabilities['google_pay'] ), // Add digital wallets to your account.
|
||||||
$capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay 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.
|
$capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account.
|
||||||
true, // Configure a PayPal Subscription.
|
true, // Configure a PayPal Subscription.
|
||||||
$capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
|
$capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay.
|
||||||
$capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay.
|
$capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay.
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,6 +14,7 @@ use WP_REST_Request;
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\AuthenticationManager;
|
use WooCommerce\PayPalCommerce\Settings\Service\AuthenticationManager;
|
||||||
|
use WooCommerce\PayPalCommerce\Settings\Service\SettingsDataManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REST controller for authenticating and connecting to a PayPal merchant account.
|
* REST controller for authenticating and connecting to a PayPal merchant account.
|
||||||
|
@ -40,6 +41,13 @@ class AuthenticationRestEndpoint extends RestEndpoint {
|
||||||
*/
|
*/
|
||||||
private AuthenticationManager $authentication_manager;
|
private AuthenticationManager $authentication_manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings data manager service.
|
||||||
|
*
|
||||||
|
* @var SettingsDataManager
|
||||||
|
*/
|
||||||
|
private SettingsDataManager $data_manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the JSON response format (when connection was successful).
|
* Defines the JSON response format (when connection was successful).
|
||||||
*
|
*
|
||||||
|
@ -58,9 +66,12 @@ class AuthenticationRestEndpoint extends RestEndpoint {
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param AuthenticationManager $authentication_manager The authentication manager.
|
* @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->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.
|
* Disconnect the merchant and clear the authentication details.
|
||||||
*
|
*
|
||||||
|
* @param WP_REST_Request $request Full data about the request.
|
||||||
|
*
|
||||||
* @return WP_REST_Response
|
* @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();
|
$this->authentication_manager->disconnect();
|
||||||
|
|
||||||
|
if ( $reset_settings ) {
|
||||||
|
$this->data_manager->reset_all_settings();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->return_success( 'OK' );
|
return $this->return_success( 'OK' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue