diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f02e2e9..f8560c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,9 +3,11 @@ on: push: branches: - 2.x + - 3.x pull_request: branches: - 2.x + - 3.x jobs: test: @@ -18,10 +20,11 @@ jobs: fail-fast: false matrix: php-version: - - "7.2" - - "7.3" - "7.4" - "8.0" + - "8.1" + - "8.2" + - "8.3" composer-version: - "2" steps: diff --git a/composer.json b/composer.json index 4d7f19d..243e287 100644 --- a/composer.json +++ b/composer.json @@ -4,17 +4,19 @@ "type": "library", "keywords": ["payment"], "require": { - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "psr/http-message": "^1.0", "psr/http-client-implementation": "^1.0", "php-http/message": "^1.6", "php-http/httplug": "^1.0 || ^2.0", "php-http/discovery": "^1.17", "eloquent/enumeration": "^5.1", - "jms/serializer": "^1.8 || ^3.0" + "jms/serializer": "^1.8 || ^3.0", + "doctrine/annotations": "^2.0" }, "require-dev": { "guzzlehttp/guzzle": "^7", + "php-http/guzzle7-adapter": "^1", "phpunit/phpunit": ">=5 <9", "symfony/yaml": "^2.0", "symfony/filesystem": "^3.1", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index adb7a80..2c52e92 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,14 +15,6 @@ parameters: count: 2 path: src/Exceptions/VippsException.php - - - message: """ - #^Call to deprecated method getOrderStatus\\(\\) of class zaporylie\\\\Vipps\\\\Api\\\\PaymentInterface\\: - Get order status was deprecated and can be removed in version 3\\.0\\.$# - """ - count: 1 - path: test/Integration/Api/PaymentsTest.php - - message: "#^Call to an undefined static method zaporylie\\\\Vipps\\\\Endpoint\\:\\:error\\(\\)\\.$#" count: 1 diff --git a/src/Client.php b/src/Client.php index 4db8f09..b2040f3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,6 +10,7 @@ use Http\Discovery\Psr18ClientDiscovery; use Psr\Http\Client\ClientInterface as HttpClientInterface; use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; use zaporylie\Vipps\Authentication\TokenMemoryCacheStorage; use zaporylie\Vipps\Authentication\TokenStorageInterface; use zaporylie\Vipps\Exceptions\Client\InvalidArgumentException; @@ -32,6 +33,11 @@ class Client implements ClientInterface */ protected $requestFactory; + /** + * @var \Psr\Http\Message\StreamFactoryInterface + */ + protected StreamFactoryInterface $streamFactory; + /** * @var string */ @@ -193,6 +199,17 @@ public function getRequestFactory(): RequestFactoryInterface return $this->requestFactory; } + /** + * {@inheritdoc} + */ + public function getStreamFactory(): StreamFactoryInterface + { + if (!isset($this->streamFactory)) { + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + return $this->streamFactory; + } + /** * Use this static method to get default HTTP Client. * diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 14a68af..399ec64 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -4,6 +4,7 @@ use Psr\Http\Client\ClientInterface as HttpClientInterface; use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; use zaporylie\Vipps\Authentication\TokenStorageInterface; interface ClientInterface @@ -69,9 +70,16 @@ public function getHttpClient() : HttpClientInterface; public function setHttpClient(?HttpClientInterface $httpClient); /** - * Gets messageFactory value. + * Gets requestFactoru value. * * @return \Psr\Http\Message\RequestFactoryInterface */ public function getRequestFactory(): RequestFactoryInterface; + + /** + * Gets streamFactory value. + * + * @return \Psr\Http\Message\StreamFactoryInterface + */ + public function getStreamFactory(): StreamFactoryInterface; } diff --git a/src/Resource/Authorization/GetToken.php b/src/Resource/Authorization/GetToken.php index ac12b83..99be069 100644 --- a/src/Resource/Authorization/GetToken.php +++ b/src/Resource/Authorization/GetToken.php @@ -23,7 +23,7 @@ class GetToken extends ResourceBase /** * @var string */ - protected $path = '/accessToken/get'; + protected $path = '/accesstoken/get'; /** * GetToken constructor. diff --git a/src/Resource/ResourceBase.php b/src/Resource/ResourceBase.php index b243df9..328d104 100644 --- a/src/Resource/ResourceBase.php +++ b/src/Resource/ResourceBase.php @@ -10,8 +10,6 @@ use Doctrine\Common\Annotations\AnnotationRegistry; use Http\Client\Exception\HttpException; -use Http\Client\HttpAsyncClient; -use Http\Client\HttpClient; use JMS\Serializer\SerializerBuilder; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; @@ -206,12 +204,16 @@ protected function handleRequest(RequestInterface $request) */ protected function getRequest() { - return $this->app->getClient()->getRequestFactory()->createRequest( + $request = $this->app->getClient()->getRequestFactory()->createRequest( $this->getMethod(), - $this->getUri($this->getPath()), - $this->getHeaders(), - $this->getBody() + $this->getUri($this->getPath()) ); + $body = $this->app->getClient()->getStreamFactory()->createStream($this->getBody()); + $request = $request->withBody($body); + foreach ($this->getHeaders() as $header => $value) { + $request = $request->withAddedHeader($header, $value); + } + return $request; } /** diff --git a/test/Unit/Resource/Authorization/GetTokenTest.php b/test/Unit/Resource/Authorization/GetTokenTest.php index 665420b..b32498b 100644 --- a/test/Unit/Resource/Authorization/GetTokenTest.php +++ b/test/Unit/Resource/Authorization/GetTokenTest.php @@ -65,7 +65,7 @@ public function testMethod() */ public function testPath() { - $this->assertEquals('/accessToken/get', $this->resource->getPath()); + $this->assertEquals('/accesstoken/get', $this->resource->getPath()); } /**