diff --git a/src/API/WP/OAuthService.php b/src/API/WP/OAuthService.php
index 7773366ce8..14b9d6d33d 100644
--- a/src/API/WP/OAuthService.php
+++ b/src/API/WP/OAuthService.php
@@ -180,6 +180,15 @@ public function revoke_wpcom_api_auth(): string {
* Revoke token on deactivation.
*/
public function deactivate(): void {
- $this->revoke_wpcom_api_auth();
+ // Try to revoke the token on deactivation. If no token is available, it will throw an exception which we can ignore.
+ try {
+ $this->revoke_wpcom_api_auth();
+ } catch ( Exception $e ) {
+ do_action(
+ 'woocommerce_gla_error',
+ sprintf( 'Error revoking the WPCOM token: %s', $e->getMessage() ),
+ __METHOD__
+ );
+ }
}
}
diff --git a/src/ConnectionTest.php b/src/ConnectionTest.php
index 97d70e0081..cae3bf4a9b 100644
--- a/src/ConnectionTest.php
+++ b/src/ConnectionTest.php
@@ -748,14 +748,6 @@ protected function render_admin_page() {
-
- |
-
-
- Revoke WPCOM Partner Access
-
- |
-
@@ -889,24 +881,6 @@ protected function handle_actions() {
}
- if ( 'revoke-wpcom-partner-access' === $_GET['action'] && check_admin_referer( 'revoke-wpcom-partner-access' ) ) {
-
- $revoke_args = [
- 'method' => 'DELETE',
- 'timeout' => 30,
- 'url' => 'https://public-api.wordpress.com/wpcom/v2/sites/' . Jetpack_Options::get_option( 'id' ) . '/wc/partners/google/revoke-token',
- 'user_id' => get_current_user_id(),
- ];
-
- $revoke_response = Client::remote_request( $revoke_args, null );
-
- if ( is_wp_error( $revoke_response ) ) {
- $this->response .= $revoke_response->get_error_message();
- } else {
- $this->response .= wp_remote_retrieve_body( $revoke_response );
- }
- }
-
if ( 'disconnect-wp-api' === $_GET['action'] && check_admin_referer( 'disconnect-wp-api' ) ) {
$request = new Request( 'DELETE', '/wc/gla/rest-api/authorize' );
$this->send_rest_request( $request );
diff --git a/tests/Unit/API/WP/OAuthServiceTest.php b/tests/Unit/API/WP/OAuthServiceTest.php
index 40e8fb342e..59ec5b08de 100644
--- a/tests/Unit/API/WP/OAuthServiceTest.php
+++ b/tests/Unit/API/WP/OAuthServiceTest.php
@@ -123,8 +123,6 @@ public function test_deactivation_ok() {
public function test_deactivation_with_wp_error() {
$this->assertInstanceOf( Deactivateable::class, $this->service );
- $this->expectException( Exception::class );
- $this->expectExceptionMessage( 'error message' );
$this->jp->expects( $this->once() )
->method( 'remote_request' )->willReturn( new WP_Error( 'error', 'error message' ) );
@@ -132,7 +130,10 @@ public function test_deactivation_with_wp_error() {
$this->account_service->expects( $this->never() )
->method( 'reset_wpcom_api_authorization_data' );
+ // The exception should be caught and ignored.
$this->service->deactivate();
+
+ $this->assertEquals( 1, did_action( 'woocommerce_gla_error' ) );
}
/**