Skip to content

Commit

Permalink
OP-366 - Add CR Fixes on Client, add support for PHP 8.0, fix for Syl…
Browse files Browse the repository at this point in the history
…ius 1.12
  • Loading branch information
SzymonKostrubiec committed Jul 26, 2024
1 parent c4fe3bf commit d72153c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "8.1", "8.2", "8.3" ]
php: [ "8.0", "8.1", "8.2", "8.3" ]
symfony: ["^5.4", "^6.0"]
sylius: ["^1.12", "^1.13"]
node: [ "18.x", "20.x" ]
mysql: ["8.0"]

exclude:
- sylius: ^1.13
php: 8.0
- sylius: ^1.12
php: 8.0
symfony: ^6.4
env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Implementation imoje api to sylius store",
"license": "MIT",
"require": {
"php": "^8.1",
"php": "^8.0",
"ext-json": "*",
"sylius/refund-plugin": "^1.0",
"sylius/sylius": "^1.12 || ^1.13",
Expand All @@ -17,7 +17,7 @@
"bitbag/coding-standard": "^3.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"doctrine/dbal": "^2.7.0",
"doctrine/dbal": "^2.7 || ^3.0",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
"friends-of-behat/mink-debug-extension": "^2.0",
Expand Down Expand Up @@ -47,7 +47,7 @@
"vimeo/psalm": "4.27.0"
},
"conflict": {
"symfony/validator": "^6.4.7"
"symfony/validator": "~6.4.7"
},
"config": {
"sort-packages": true,
Expand Down
36 changes: 17 additions & 19 deletions src/Client/ImojeApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Symfony\Component\Serializer\Serializer;
Expand Down Expand Up @@ -57,13 +58,10 @@ public function createTransaction(
$parameters = $this->requestParamsProvider->buildRequestParams($transactionModel, $this->token);

try {
$request = $this->requestFactory
$httpRequest = $this->requestFactory
->createRequest('POST', $url)
->withHeader('Accept', 'application/json')
->withHeader('Content-Type', 'application/json')
->withHeader('Authorization', \sprintf('Bearer %s', $this->token))
->withBody($this->streamFactory->createStream($parameters['body']));

$request = $this->setRequestHeaders($httpRequest);
$response = $this->httpClient->sendRequest($request);
} catch (ClientExceptionInterface $e) {
throw new ImojeBadRequestException($e->getMessage());
Expand All @@ -77,10 +75,8 @@ public function getShopInfo(string $serviceId): ServiceModelInterface
$url = $this->url . 'service/' . $serviceId;

try {
$request = $this->requestFactory->createRequest('GET', $url)
->withHeader('Accept', 'application/json')
->withHeader('Content-Type', 'application/json')
->withHeader('Authorization', \sprintf('Bearer %s', $this->token));
$httpRequest = $this->requestFactory->createRequest('GET', $url);
$request = $this->setRequestHeaders($httpRequest);
$response = $this->httpClient->sendRequest($request);
} catch (ClientExceptionInterface $e) {
throw new ImojeBadRequestException($e->getMessage());
Expand All @@ -96,11 +92,8 @@ public function getShopInfo(string $serviceId): ServiceModelInterface
public function getTransactionData(string $url): ResponseInterface
{
try {
$request = $this->requestFactory->createRequest('GET', $url)
->withHeader('Accept', 'application/json')
->withHeader('Content-Type', 'application/json')
->withHeader('Authorization', \sprintf('Bearer %s', $this->token));

$httpRequest = $this->requestFactory->createRequest('GET', $url);
$request = $this->setRequestHeaders($httpRequest);
$response = $this->httpClient->sendRequest($request);
} catch (ClientExceptionInterface $e) {
throw new ImojeBadRequestException($e->getMessage());
Expand All @@ -117,18 +110,23 @@ public function refundTransaction(
$parameters = $this->requestParamsProvider->buildRequestRefundParams($this->token, $serviceId, $amount);

try {
$request = $this->requestFactory
$httpRequest = $this->requestFactory
->createRequest('POST', $url)
->withHeader('Accept', 'application/json')
->withHeader('Content-Type', 'application/json')
->withHeader('Authorization', \sprintf('Bearer %s', $this->token))
->withBody($this->streamFactory->createStream($parameters['body']));

$request = $this->setRequestHeaders($httpRequest);
$response = $this->httpClient->sendRequest($request);
} catch (ClientExceptionInterface $e) {
throw new ImojeBadRequestException($e->getMessage());
}

return $response;
}

private function setRequestHeaders(RequestInterface $request): RequestInterface
{
return $request
->withHeader('Accept', 'application/json')
->withHeader('Content-Type', 'application/json')
->withHeader('Authorization', \sprintf('Bearer %s', $this->token));
}
}
7 changes: 5 additions & 2 deletions src/Resources/config/services/providers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius.http_client" class="Symfony\Component\HttpClient\Psr18Client" />
<service id="sylius.request_factory" class="Symfony\Component\HttpClient\Psr18Client" />
<service id="sylius.stream_factory" class="Symfony\Component\HttpClient\Psr18Client"/>
<service class="BitBag\SyliusImojePlugin\Provider\ImojeClientConfigurationProvider"
id="bitbag.sylius_imoje_plugin.provider.imoje_client_configuration_provider"
>
Expand All @@ -16,8 +19,8 @@
<argument type="service" id="sylius.http_client"/>
<argument type="service" id="bitbag.sylius_imoje_plugin.provider.request_params.request_params_provider"/>
<argument type="service" id="bitbag.sylius_imoje_plugin.factory.serializer.serializer_factory"/>
<argument type="service" id="Psr\Http\Message\RequestFactoryInterface"/>
<argument type="service" id="Psr\Http\Message\StreamFactoryInterface"/>
<argument type="service" id="sylius.request_factory"/>
<argument type="service" id="sylius.stream_factory"/>
</service>

<service class="BitBag\SyliusImojePlugin\Provider\BlikModel\BlikModelProvider"
Expand Down

0 comments on commit d72153c

Please sign in to comment.