🚚 Rename ConnectionManager class

This commit is contained in:
Philipp Stracker 2025-01-08 17:18:52 +01:00
parent 67a6d9e765
commit 8ce7d6ca99
No known key found for this signature in database
3 changed files with 26 additions and 19 deletions

View file

@ -10,21 +10,21 @@ declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Settings;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Settings\Ajax\SwitchSettingsUiEndpoint;
use WooCommerce\PayPalCommerce\Settings\Data\CommonSettings;
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\AuthenticationRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint;
use WooCommerce\PayPalCommerce\Settings\Ajax\SwitchSettingsUiEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint;
use WooCommerce\PayPalCommerce\Settings\Handler\ConnectionListener;
use WooCommerce\PayPalCommerce\Settings\Service\AuthenticationManager;
use WooCommerce\PayPalCommerce\Settings\Service\ConnectionUrlGenerator;
use WooCommerce\PayPalCommerce\Settings\Service\OnboardingUrlManager;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Settings\Handler\ConnectionListener;
use WooCommerce\PayPalCommerce\Settings\Service\ConnectionManager;
return array(
'settings.url' => static function ( ContainerInterface $container ) : string {
@ -82,7 +82,7 @@ return array(
},
'settings.rest.connect_manual' => static function ( ContainerInterface $container ) : AuthenticationRestEndpoint {
return new AuthenticationRestEndpoint(
$container->get( 'settings.service.connection_manager' ),
$container->get( 'settings.service.authentication_manager' ),
);
},
'settings.rest.login_link' => static function ( ContainerInterface $container ) : LoginLinkRestEndpoint {
@ -180,8 +180,8 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'settings.service.connection_manager' => static function ( ContainerInterface $container ) : ConnectionManager {
return new ConnectionManager(
'settings.service.authentication_manager' => static function ( ContainerInterface $container ) : AuthenticationManager {
return new AuthenticationManager(
$container->get( 'settings.data.common' ),
$container->get( 'api.env.paypal-host' ),
$container->get( 'api.env.endpoint.login-seller' ),

View file

@ -20,7 +20,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Helper\InMemoryCache;
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
use WooCommerce\PayPalCommerce\Settings\Service\ConnectionManager;
use WooCommerce\PayPalCommerce\Settings\Service\AuthenticationManager;
/**
* REST controller for authenticating and connecting to a PayPal merchant account.
@ -40,6 +40,13 @@ class AuthenticationRestEndpoint extends RestEndpoint {
*/
protected $rest_base = 'authenticate';
/**
* Authentication manager service.
*
* @var AuthenticationManager
*/
private AuthenticationManager $authentication_manager;
/**
* Defines the JSON response format (when connection was successful).
*
@ -57,16 +64,16 @@ class AuthenticationRestEndpoint extends RestEndpoint {
/**
* Constructor.
*
* @param ConnectionManager $connection_manager The connection manager.
* @param AuthenticationManager $authentication_manager The authentication manager.
*/
public function __construct( ConnectionManager $connection_manager ) {
$this->connection_manager = $connection_manager;
public function __construct( AuthenticationManager $authentication_manager ) {
$this->authentication_manager = $authentication_manager;
}
/**
* Configure REST API routes.
*/
public function register_routes() {
public function register_routes() : void {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/direct',
@ -139,13 +146,13 @@ class AuthenticationRestEndpoint extends RestEndpoint {
$use_sandbox = $request->get_param( 'useSandbox' );
try {
$this->connection_manager->validate_id_and_secret( $client_id, $client_secret );
$this->connection_manager->connect_via_secret( $use_sandbox, $client_id, $client_secret );
$this->authentication_manager->validate_id_and_secret( $client_id, $client_secret );
$this->authentication_manager->connect_via_secret( $use_sandbox, $client_id, $client_secret );
} catch ( Exception $exception ) {
return $this->return_error( $exception->getMessage() );
}
$account = $this->connection_manager->get_account_details();
$account = $this->authentication_manager->get_account_details();
$response = $this->sanitize_for_javascript( $this->response_map, $account );
return $this->return_success( $response );
@ -165,13 +172,13 @@ class AuthenticationRestEndpoint extends RestEndpoint {
$use_sandbox = $request->get_param( 'useSandbox' );
try {
$this->connection_manager->validate_id_and_auth_code( $shared_id, $auth_code );
$this->connection_manager->connect_via_auth_code( $use_sandbox, $shared_id, $auth_code );
$this->authentication_manager->validate_id_and_auth_code( $shared_id, $auth_code );
$this->authentication_manager->connect_via_auth_code( $use_sandbox, $shared_id, $auth_code );
} catch ( Exception $exception ) {
return $this->return_error( $exception->getMessage() );
}
$account = $this->connection_manager->get_account_details();
$account = $this->authentication_manager->get_account_details();
$response = $this->sanitize_for_javascript( $this->response_map, $account );
return $this->return_success( $response );

View file

@ -25,7 +25,7 @@ use WooCommerce\PayPalCommerce\Settings\DTO\MerchantConnectionDTO;
/**
* Class that manages the connection to PayPal.
*/
class ConnectionManager {
class AuthenticationManager {
/**
* Data model that stores the connection details.
*