Skip to content

V2 #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

V2 #259

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/_templates/_credit_card_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<select name="month" id="month" class="form-select input-lg">
<option value="">Month</option>
<?php for ($i = 1; $i <= 12; $i++) : ?>
<option value="<?= $i; ?>" <?= $i == $card->getExpireMonth() ? 'selected': null ?>><?= str_pad($i, 2, 0, STR_PAD_LEFT); ?></option>
<option value="<?= $i; ?>" <?= $i == $card->getExpirationDate()->format('m') ? 'selected': null ?>><?= str_pad($i, 2, 0, STR_PAD_LEFT); ?></option>
<?php endfor; ?>
</select>
</div>
Expand All @@ -36,7 +36,7 @@
<select name="year" id="year" class="form-select input-lg">
<option value="">Year</option>
<?php for ($i = date('Y'); $i <= date('Y') + 30; $i++) : ?>
<option value="<?= $i; ?>" <?= $i == $card->getExpireYear('Y') ? 'selected': null ?>><?= $i; ?></option>
<option value="<?= $i; ?>" <?= $i == $card->getExpirationDate()->format('Y') ? 'selected': null ?>><?= $i; ?></option>
<?php endfor; ?>
</select>
</div>
Expand Down
78 changes: 18 additions & 60 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
parameters:
ignoreErrors:
-
message: '#^Parameter \#1 \$body of method Psr\\Http\\Message\\MessageInterface\:\:withBody\(\) expects Psr\\Http\\Message\\StreamInterface, Psr\\Http\\Message\\StreamInterface\|null given\.$#'
identifier: argument.type
count: 1
path: src/Client/HttpClient.php

-
message: '#^Parameter \#1 \$content of method Psr\\Http\\Message\\StreamFactoryInterface\:\:createStream\(\) expects string, array\<string, string\>\|string given\.$#'
identifier: argument.type
count: 1
path: src/Client/HttpClient.php

-
message: '#^Default value of the parameter \#3 \$order \(array\{\}\) of method Mews\\Pos\\Crypt\\PosNetCrypt\:\:createHash\(\) is incompatible with type array\{amount\: int, currency\: string, id\: string\}\.$#'
identifier: parameter.defaultValue
Expand All @@ -25,38 +13,32 @@ parameters:
path: src/Crypt/PosNetV1PosCrypt.php

-
message: '#^Parameter \#1 \$currency of method Mews\\Pos\\DataMapper\\RequestDataMapper\\AkbankPosRequestDataMapper\:\:mapCurrency\(\) expects ''EUR''\|''GBP''\|''JPY''\|''RUB''\|''TRY''\|''USD'', string given\.$#'
message: '#^Parameter \#1 \$cardType of method Mews\\Pos\\DataMapper\\RequestValueMapper\\RequestValueMapperInterface\:\:mapCardType\(\) expects ''amex''\|''master''\|''troy''\|''visa'', ''amex''\|''master''\|''troy''\|''visa''\|null given\.$#'
identifier: argument.type
count: 5
path: src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php

-
message: '#^Expression on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.expr
count: 1
path: src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
count: 2
path: src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php

-
message: '#^Parameter \#1 \$currency of method Mews\\Pos\\DataMapper\\RequestDataMapper\\EstPosRequestDataMapper\:\:mapCurrency\(\) expects ''EUR''\|''GBP''\|''JPY''\|''RUB''\|''TRY''\|''USD'', string given\.$#'
message: '#^Parameter \#1 \$cardType of method Mews\\Pos\\DataMapper\\RequestValueMapper\\RequestValueMapperInterface\:\:mapCardType\(\) expects ''amex''\|''master''\|''troy''\|''visa'', ''amex''\|''master''\|''troy''\|''visa''\|null given\.$#'
identifier: argument.type
count: 1
path: src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
path: src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php

-
message: '#^Expression on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.expr
count: 1
path: src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php
message: '#^Parameter \#1 \$installment of method Mews\\Pos\\DataMapper\\RequestValueFormatter\\ParamPosRequestValueFormatter\:\:formatInstallment\(\) expects int\<0, max\>, int given\.$#'
identifier: argument.type
count: 3
path: src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

-
message: '#^Expression on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.expr
message: '#^Default value of the parameter \#7 \$extraData \(array\{\}\) of method Mews\\Pos\\DataMapper\\RequestDataMapper\\PayFlexCPV4PosRequestDataMapper\:\:create3DFormData\(\) is incompatible with type array\{CommonPaymentUrl\: string, PaymentToken\: string\}\.$#'
identifier: parameter.defaultValue
count: 1
path: src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php
path: src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php

-
message: '#^Default value of the parameter \#7 \$extraData \(array\{\}\) of method Mews\\Pos\\DataMapper\\RequestDataMapper\\PayFlexCPV4PosRequestDataMapper\:\:create3DFormData\(\) is incompatible with type array\{CommonPaymentUrl\: string, PaymentToken\: string\}\.$#'
identifier: parameter.defaultValue
message: '#^Parameter \#1 \$cardType of method Mews\\Pos\\DataMapper\\RequestValueMapper\\RequestValueMapperInterface\:\:mapCardType\(\) expects ''amex''\|''master''\|''troy''\|''visa'', ''amex''\|''master''\|''troy''\|''visa''\|null given\.$#'
identifier: argument.type
count: 1
path: src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php

Expand All @@ -67,14 +49,14 @@ parameters:
path: src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php

-
message: '#^Expression on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.expr
message: '#^Method Mews\\Pos\\DataMapper\\RequestDataMapper\\PayFlexV4PosRequestDataMapper\:\:create3DEnrollmentCheckRequestData\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php

-
message: '#^Method Mews\\Pos\\DataMapper\\RequestDataMapper\\PayFlexV4PosRequestDataMapper\:\:create3DEnrollmentCheckRequestData\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
message: '#^Parameter \#1 \$cardType of method Mews\\Pos\\DataMapper\\RequestValueMapper\\RequestValueMapperInterface\:\:mapCardType\(\) expects ''amex''\|''master''\|''troy''\|''visa'', ''amex''\|''master''\|''troy''\|''visa''\|null given\.$#'
identifier: argument.type
count: 1
path: src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php

Expand All @@ -84,12 +66,6 @@ parameters:
count: 1
path: src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php

-
message: '#^Expression on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.expr
count: 1
path: src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php

-
message: '#^Cannot assign offset ''authCode'' to array\<string, string\>\|string\.$#'
identifier: offsetAssign.dimType
Expand Down Expand Up @@ -120,12 +96,6 @@ parameters:
count: 1
path: src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php

-
message: '#^Method Mews\\Pos\\DataMapper\\RequestDataMapper\\PosNetRequestDataMapper\:\:create3DEnrollmentCheckRequestData\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php

-
message: '#^Method Mews\\Pos\\DataMapper\\RequestDataMapper\\PosNetV1PosRequestDataMapper\:\:create3DFormData\(\) has parameter \$extraData with no type specified\.$#'
identifier: missingType.parameter
Expand Down Expand Up @@ -162,18 +132,6 @@ parameters:
count: 1
path: src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php

-
message: '#^Property Mews\\Pos\\DataMapper\\ResponseDataMapper\\AbstractResponseDataMapper\:\:\$secureTypeMappings \(array\<string, ''3d''\|''3d_host''\|''3d_pay''\|''3d_pay_hosting''\|''regular''\>\) does not accept non\-empty\-array\<1\|2\|3\|string, ''3d''\|''3d_host''\|''3d_pay''\|''3d_pay_hosting''\|''regular''\>\.$#'
identifier: assign.propertyType
count: 1
path: src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php

-
message: '#^Property Mews\\Pos\\DataMapper\\ResponseDataMapper\\AbstractResponseDataMapper\:\:\$currencyMappings \(array\<string, ''EUR''\|''GBP''\|''JPY''\|''RUB''\|''TRY''\|''USD''\>\) does not accept non\-empty\-array\<392\|643\|826\|840\|949\|978\|string, ''EUR''\|''GBP''\|''JPY''\|''RUB''\|''TRY''\|''USD''\>\.$#'
identifier: assign.propertyType
count: 1
path: src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php

-
message: '#^Method Mews\\Pos\\Factory\\PosFactory\:\:createPosGateway\(\) should return Mews\\Pos\\PosInterface but returns object\.$#'
identifier: return.type
Expand Down
151 changes: 151 additions & 0 deletions src/Client/AbstractHttpClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

/**
* @license MIT
*/

namespace Mews\Pos\Client;

use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\PosInterface;
use Mews\Pos\Serializer\EncodedData;
use Mews\Pos\Serializer\SerializerInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Log\LoggerInterface;

/**
* PSR18 HTTP Client wrapper
*/
abstract class AbstractHttpClient implements HttpClientInterface
{
protected ClientInterface $client;

protected RequestFactoryInterface $requestFactory;

protected StreamFactoryInterface $streamFactory;
protected SerializerInterface $serializer;
protected array $config;

Check failure on line 30 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Property Mews\Pos\Client\AbstractHttpClient::$config type has no value type specified in iterable type array.

Check failure on line 30 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Property Mews\Pos\Client\AbstractHttpClient::$config type has no value type specified in iterable type array.

Check failure on line 30 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Property Mews\Pos\Client\AbstractHttpClient::$config type has no value type specified in iterable type array.

Check failure on line 30 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Property Mews\Pos\Client\AbstractHttpClient::$config type has no value type specified in iterable type array.
protected bool $isTestMode;
protected LoggerInterface $logger;

/**
* @param ClientInterface $client
* @param RequestFactoryInterface $requestFactory
* @param StreamFactoryInterface $streamFactory
*/
public function __construct(

Check failure on line 39 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::__construct() has parameter $config with no value type specified in iterable type array.

Check failure on line 39 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::__construct() has parameter $config with no value type specified in iterable type array.

Check failure on line 39 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::__construct() has parameter $config with no value type specified in iterable type array.

Check failure on line 39 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::__construct() has parameter $config with no value type specified in iterable type array.
ClientInterface $client,
RequestFactoryInterface $requestFactory,
StreamFactoryInterface $streamFactory,
SerializerInterface $serializer,
LoggerInterface $logger,
array $config
)
{
$this->client = $client;
$this->requestFactory = $requestFactory;
$this->streamFactory = $streamFactory;
$this->config = $config;
$this->serializer = $serializer;
$this->logger = $logger;
}

/**
* todo protected?
* @phpstan-param self::TX_TYPE_* $txType
* @phpstan-param self::MODEL_* $paymentModel
* @phpstan-param self::TX_TYPE_PAY_* $orderTxType
*
* @param string|null $txType
* @param string|null $paymentModel
* @param string|null $orderTxType
*
* @return non-empty-string
*/
public function getApiURL(string $txType = null, string $paymentModel = null, ?string $orderTxType = null): string

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

PHPDoc tag @param for parameter $orderTxType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

PHPDoc tag @param for parameter $paymentModel contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

PHPDoc tag @param for parameter $txType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

PHPDoc tag @param for parameter $orderTxType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

PHPDoc tag @param for parameter $paymentModel contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

PHPDoc tag @param for parameter $txType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

PHPDoc tag @param for parameter $orderTxType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

PHPDoc tag @param for parameter $paymentModel contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

PHPDoc tag @param for parameter $txType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

PHPDoc tag @param for parameter $orderTxType contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

PHPDoc tag @param for parameter $paymentModel contains unresolvable type.

Check failure on line 68 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

PHPDoc tag @param for parameter $txType contains unresolvable type.
{
if (isset($this->config['query_api']) && \in_array($txType, [
PosInterface::TX_TYPE_STATUS,
PosInterface::TX_TYPE_CUSTOM_QUERY,
], true)) {
//todo
return $this->config['query_api'];
}

return $this->config['payment_api'];
}

/**
* @inheritDoc
*/
public function request(string $txType, string $paymentModel, array $requestData, array $order, string $url = null, AbstractPosAccount $account = null, bool $encode = true, bool $decode = true)
{
$content = $encode ? $this->serializer->encode($requestData, $txType) : $requestData;

$url ??= $this->getApiURL($txType, $paymentModel, $order['transaction_type'] ?? null);

$request = $this->createRequest($txType, $url, $content, $account);

Check failure on line 90 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Parameter #3 $content of method Mews\Pos\Client\AbstractHttpClient::createRequest() expects Mews\Pos\Serializer\EncodedData, array<string, mixed>|Mews\Pos\Serializer\EncodedData given.

Check failure on line 90 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Parameter #3 $content of method Mews\Pos\Client\AbstractHttpClient::createRequest() expects Mews\Pos\Serializer\EncodedData, array<string, mixed>|Mews\Pos\Serializer\EncodedData given.

Check failure on line 90 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Parameter #3 $content of method Mews\Pos\Client\AbstractHttpClient::createRequest() expects Mews\Pos\Serializer\EncodedData, array<string, mixed>|Mews\Pos\Serializer\EncodedData given.

Check failure on line 90 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Parameter #3 $content of method Mews\Pos\Client\AbstractHttpClient::createRequest() expects Mews\Pos\Serializer\EncodedData, array<string, mixed>|Mews\Pos\Serializer\EncodedData given.

$this->logger->debug('sending request', ['url' => $url]);

$response = $this->client->sendRequest($request);

if ($response->getStatusCode() === 204) {
// todo toslapos
$this->logger->warning('response from api is empty');

return $this->data = [];

Check failure on line 100 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Access to an undefined property Mews\Pos\Client\AbstractHttpClient::$data.

Check failure on line 100 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Access to an undefined property Mews\Pos\Client\AbstractHttpClient::$data.

Check failure on line 100 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Access to an undefined property Mews\Pos\Client\AbstractHttpClient::$data.

Check failure on line 100 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Access to an undefined property Mews\Pos\Client\AbstractHttpClient::$data.
}

$this->logger->debug('request completed', ['status_code' => $response->getStatusCode()]);

$this->checkFailResponse($txType, $response);
$response->getBody()->rewind();

return $decode
? $this->serializer->decode($response->getBody()->getContents(), $txType)
: $response->getBody()->getContents();
}

/**
* @param bool $isTestMode
*
* @return void
*/
public function setTestMode(bool $isTestMode): void
{
$this->isTestMode = $isTestMode;
}

/**
* @return bool
*/
public function isTestMode(): bool
{
return $this->isTestMode;
}

/**
* @param PosInterface::TX_TYPE_* $txType // todo do we need it?
* @param string $url
* @param EncodedData $content
* @param AbstractPosAccount $account
*
* @return RequestInterface
*/
abstract protected function createRequest(string $txType, string $url, EncodedData $content, AbstractPosAccount $account = null): RequestInterface;

/**
* To be overridden
* @param PosInterface::TX_TYPE_* $txType
* @param $response
*
* @throws \RuntimeException when request failed
*/
protected function checkFailResponse(string $txType, $response): void

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has RuntimeException in PHPDoc @throws tag but it's not thrown.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has parameter $response with no type specified.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has RuntimeException in PHPDoc @throws tag but it's not thrown.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has parameter $response with no type specified.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has RuntimeException in PHPDoc @throws tag but it's not thrown.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has parameter $response with no type specified.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has RuntimeException in PHPDoc @throws tag but it's not thrown.

Check failure on line 148 in src/Client/AbstractHttpClient.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\Client\AbstractHttpClient::checkFailResponse() has parameter $response with no type specified.
{
}
}
Loading
Loading