diff --git a/src/Api/AbstractApi.php b/src/Api/AbstractApi.php index dcfdd5f..f6cfc09 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/AbstractApi.php @@ -20,8 +20,8 @@ abstract class AbstractApi * @param T $session */ public function __construct( - private IPayClient $client, - private SessionInterface $session, + protected IPayClient $iPayClient, + protected SessionInterface $session, ) { $this->objectMapper = new ObjectMapperUsingReflection( new ReflectionDefinitionProvider( @@ -37,7 +37,7 @@ public function __construct( */ protected function post(string $uri, array $data = []): array { - $response = $this->client->getClient()->post( + $response = $this->iPayClient->getClient()->post( $uri, [], BodyBuilder::from($data) @@ -54,11 +54,6 @@ public function getObjectMapper(): ObjectMapper return $this->objectMapper; } - public function getClient(): IPayClient - { - return $this->client; - } - /** * @return T */ diff --git a/src/Api/UnauthenticatedApi.php b/src/Api/UnauthenticatedApi.php index 1df0c8b..e00986e 100644 --- a/src/Api/UnauthenticatedApi.php +++ b/src/Api/UnauthenticatedApi.php @@ -16,7 +16,7 @@ public function login( $result = $this->post('/signIn', get_defined_vars()); return new AuthenticatedApi( - $this->getClient(), + $this->iPayClient, new AuthenticatedSession($result['sessionId']) ); } diff --git a/src/Encryption/Encrypter.php b/src/Encryption/Encrypter.php index da4d9db..7339402 100644 --- a/src/Encryption/Encrypter.php +++ b/src/Encryption/Encrypter.php @@ -18,12 +18,10 @@ public static function encrypt(string $message): string $mlen = strlen($message); $result = ''; - foreach ( - str_split( - $message, - (int) ceil($mlen / ceil($mlen / 86)) - ) as $part - ) { + foreach (str_split( + $message, + (int) ceil($mlen / ceil($mlen / 86)) + ) as $part) { openssl_public_encrypt( $part, $part, diff --git a/src/IPayClient.php b/src/IPayClient.php index bf48938..ff8d75a 100644 --- a/src/IPayClient.php +++ b/src/IPayClient.php @@ -9,6 +9,8 @@ use Http\Client\Common\PluginClient; use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; +use IPay\Api\AuthenticatedApi; +use IPay\Api\AuthenticatedSession; use IPay\Api\UnauthenticatedApi; use IPay\Api\UnauthenticatedSession; use IPay\Http\Plugin\ExceptionThrower; @@ -46,4 +48,9 @@ public function unauthenticated(): UnauthenticatedApi { return new UnauthenticatedApi($this, new UnauthenticatedSession()); } + + public function session(string $id): AuthenticatedApi + { + return new AuthenticatedApi($this, new AuthenticatedSession($id)); + } }