diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index dd2c786a1..7f62da5f6 100644 --- a/modules/ppcp-api-client/services.php +++ b/modules/ppcp-api-client/services.php @@ -1662,12 +1662,15 @@ return array( $container->get( 'wcgateway.settings' ) ); }, + 'api.client-credentials-cache' => static function( ContainerInterface $container ): Cache { + return new Cache( 'ppcp-client-credentials-cache' ); + }, 'api.user-id-token' => static function( ContainerInterface $container ): UserIdToken { return new UserIdToken( $container->get( 'api.host' ), $container->get( 'woocommerce.logger.woocommerce' ), $container->get( 'api.client-credentials' ), - new Cache( 'ppcp-client-credentials-cache' ) + $container->get( 'api.client-credentials-cache' ) ); }, 'api.sdk-client-token' => static function( ContainerInterface $container ): SdkClientToken { @@ -1675,7 +1678,7 @@ return array( $container->get( 'api.host' ), $container->get( 'woocommerce.logger.woocommerce' ), $container->get( 'api.client-credentials' ), - new Cache( 'ppcp-client-credentials-cache' ) + $container->get( 'api.client-credentials-cache' ) ); }, ); diff --git a/modules/ppcp-api-client/src/ApiModule.php b/modules/ppcp-api-client/src/ApiModule.php index 42bc1f117..5c3ec56bd 100644 --- a/modules/ppcp-api-client/src/ApiModule.php +++ b/modules/ppcp-api-client/src/ApiModule.php @@ -10,6 +10,9 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\ApiClient; use WC_Order; +use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken; +use WooCommerce\PayPalCommerce\ApiClient\Authentication\UserIdToken; +use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry; use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderTransient; use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; @@ -94,6 +97,21 @@ class ApiModule implements ModuleInterface { 10, 2 ); + + add_action( + 'wp_logout', + function() use ( $c ) { + $client_credentials_cache = $c->get( 'api.client-credentials-cache' ); + assert( $client_credentials_cache instanceof Cache ); + + if ( $client_credentials_cache->has( UserIdToken::CACHE_KEY ) ) { + $client_credentials_cache->delete( UserIdToken::CACHE_KEY ); + } + if ( $client_credentials_cache->has( SdkClientToken::CACHE_KEY ) ) { + $client_credentials_cache->delete( SdkClientToken::CACHE_KEY ); + } + } + ); } /**