Skip to content

Commit

Permalink
run rector php
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Apr 26, 2024
1 parent aab2470 commit 5e42b54
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/Crypt/AbstractCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function generateRandomString(int $length = 24): string
$charactersLength = \strlen($characters);
$randomString = '';

for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[\rand(0, $charactersLength - 1)];
for ($i = 0; $i < $length; ++$i) {
$randomString .= $characters[random_int(0, $charactersLength - 1)];
}

return $randomString;
Expand Down
1 change: 1 addition & 0 deletions src/Crypt/AkbankPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function hashString(string $str, ?string $encryptionKey = null): string
if (null === $encryptionKey) {
throw new \LogicException('Encryption key zorunlu!');
}

$str = \hash_hmac(static::HASH_ALGORITHM, $str, $encryptionKey, true);

return \base64_encode($str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function isSupportedTxType(string $txType, ?string $paymentModel = null):
if (!isset($this->txTypeMappings[$txType])) {
return false;
}

if (\is_array($this->txTypeMappings[$txType])) {
if (null === $paymentModel) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
if (null !== $posAccount->getSubMerchantId()) {
$inputs['subMerchantId'] = $posAccount->getSubMerchantId();
}

if ($creditCard instanceof CreditCardInterface) {
$inputs['creditCard'] = $creditCard->getNumber();
$inputs['expiredDate'] = $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
'Amount' => (string) $this->formatAmount($order['amount']),
'CurrencyCode' => (string) $this->mapCurrency($order['currency']),
'MerchantReturnURL' => (string) $order['success_url'],
'InstallmentCount' => (string) $this->mapInstallment($order['installment']),
'InstallmentCount' => $this->mapInstallment($order['installment']),
'Language' => $this->getLang($posAccount, $order),
'TxnState' => 'INITIAL',
'OpenNewWindow' => '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function mapTxType($txType): ?string
if (\is_array($mapping) && \in_array($txType, $mapping, true)) {
return $mappedTxType;
}

if ($mapping === $txType) {
return $mappedTxType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,26 @@ public function mapOrderHistoryResponse(array $rawResponseData): array
} else {
$transactions[] = $this->mapSingleOrderHistoryTransaction($rawTx);
}
$orderId = $orderId ?? $rawTx['orgOrderId'] ?? $rawTx['orderId'] ?? null;

$orderId ??= $rawTx['orgOrderId'] ?? $rawTx['orderId'] ?? null;
}
}

if (!$isRecurringOrder) {
\usort($transactions, function (array $tx1, array $tx2) {
\usort($transactions, static function (array $tx1, array $tx2) {
if (null !== $tx1['transaction_time'] && null === $tx2['transaction_time']) {
return 1;
}

if (null === $tx1['transaction_time'] && null !== $tx2['transaction_time']) {
return -1;
}

if ($tx1['transaction_time'] == $tx2['transaction_time']) {
return 0;
} elseif ($tx1['transaction_time'] < $tx2['transaction_time']) {
}

if ($tx1['transaction_time'] < $tx2['transaction_time']) {
return -1;
}

Expand Down Expand Up @@ -520,6 +525,7 @@ private function mapSingleRecurringOrderHistoryTransaction(array $rawTx): array
if (PosInterface::PAYMENT_STATUS_PAYMENT_PENDING !== $transaction['order_status']) {
$transaction['transaction_time'] = new \DateTimeImmutable($rawTx['txnDateTime']);
}

if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transaction['order_status']) {
$transaction['batch_num'] = $rawTx['batchNumber'];
$transaction['ref_ret_num'] = $rawTx['rrn'];
Expand Down
12 changes: 2 additions & 10 deletions src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ public function mapRefundResponse(array $rawResponseData): array

$responseResults = $drawbackResult['Results'];
if (self::TX_APPROVED !== $status && isset($responseResults['Result']) && [] !== $responseResults['Result']) {
if (isset($responseResults['Result'][0])) {
$responseResult = $responseResults['Result'][0];
} else {
$responseResult = $responseResults['Result'];
}
$responseResult = $responseResults['Result'][0] ?? $responseResults['Result'];
$result['proc_return_code'] = $procReturnCode;
$result['error_code'] = $responseResult['ErrorCode'] ?? $procReturnCode;
$result['error_message'] = $responseResult['ErrorMessage'];
Expand Down Expand Up @@ -292,11 +288,7 @@ public function mapCancelResponse(array $rawResponseData): array

$responseResults = $rawResponseData['SaleReversalResult']['Results'];
if (self::TX_APPROVED !== $status && isset($responseResults['Result']) && [] !== $responseResults['Result']) {
if (isset($responseResults['Result'][0])) {
$responseResult = $responseResults['Result'][0];
} else {
$responseResult = $responseResults['Result'];
}
$responseResult = $responseResults['Result'][0] ?? $responseResults['Result'];
$result['proc_return_code'] = $procReturnCode;
$result['error_code'] = $responseResult['ErrorCode'] ?? $procReturnCode;
$result['error_message'] = $responseResult['ErrorMessage'];
Expand Down
7 changes: 2 additions & 5 deletions src/Gateways/AkbankPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ protected function send($contents, string $txType, string $paymentModel, string
if (!\is_string($contents)) {
throw new \InvalidArgumentException(\sprintf('Argument type must be string, %s provided.', \gettype($contents)));
}

$hash = $this->requestDataMapper->getCrypt()->hashString($contents, $this->account->getStoreKey());

$response = $this->client->post($url, [
Expand Down Expand Up @@ -217,10 +218,6 @@ private function getRequestURIByTransactionType(string $txType): string
PosInterface::TX_TYPE_HISTORY => 'portal/report/transaction',
];

if (isset($arr[$txType])) {
return $arr[$txType];
}

return 'transaction/process';
return $arr[$txType] ?? 'transaction/process';
}
}
1 change: 1 addition & 0 deletions src/Gateways/KuveytPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function getApiURL(string $txType = null, string $paymentModel = null, ?s
)) {
return $this->getQueryAPIUrl();
}

if (null !== $txType && null !== $paymentModel) {
return parent::getApiURL().'/'.$this->getRequestURIByTransactionType($txType, $paymentModel);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Serializer/AkbankPosSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function decode(string $data, ?string $txType = null): array
if ('' === $data) {
return [];
}

$decodedData = $this->serializer->decode($data, JsonEncoder::FORMAT);

if (PosInterface::TX_TYPE_HISTORY === $txType && isset($decodedData['data'])) {
Expand All @@ -66,15 +67,18 @@ private function decompress(string $data): string
if (!$gzipStream) {
return '';
}

$decompressedData = '';
$i = 0;
while (!gzeof($gzipStream)) {
$i++;
++$i;
if ($i > 1000000) {
throw new \RuntimeException('Invalid history data');
}

$decompressedData .= gzread($gzipStream, 1024);
}

gzclose($gzipStream);

return $decompressedData;
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/KuveytPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro
];
$requestData = $requestDataPreparedEvent->getRequestData();
$requestData = array_merge($requestData, $additionalRequestDataForKuveyt);

$requestDataPreparedEvent->setRequestData($requestData);
$this->assertSame(PosInterface::TX_TYPE_PAY_AUTH, $requestDataPreparedEvent->getTxType());
});
Expand Down Expand Up @@ -228,7 +229,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro
*/
public function testRefundFail(array $lastResponse): array
{
$refundOrder = $this->createRefundOrder(\get_class($this->pos), $lastResponse);
$refundOrder = $this->createRefundOrder(\get_class($this->pos), $lastResponse);
$refundOrder['amount'] = 1.0;

$eventIsThrown = false;
Expand Down
3 changes: 1 addition & 2 deletions tests/Functional/PaymentTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Mews\Pos\Tests\Functional;

use Mews\Pos\Gateways\AkbankPos;
use Mews\Pos\Gateways\EstPos;
use Mews\Pos\Gateways\EstV3Pos;
use Mews\Pos\Gateways\GarantiPos;
Expand All @@ -23,7 +22,7 @@ private function createPaymentOrder(
bool $tekrarlanan = false
): array
{
if ($tekrarlanan && get_class($this->pos) === AkbankPos::class) {
if ($tekrarlanan && $this->pos instanceof \Mews\Pos\Gateways\AkbankPos) {
// AkbankPos'ta recurring odemede orderTrackId/orderId en az 36 karakter olmasi gerekiyor
$orderId = date('Ymd').strtoupper(substr(uniqid(sha1(time())), 0, 28));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function testCreateCancelRequestData(array $order, array $expected): void
ksort($item);
}
}

foreach ($expected as &$item) {
if (is_array($item)) {
ksort($item);
Expand Down Expand Up @@ -193,6 +194,7 @@ public function testCreateRefundRequestData(array $order, array $expected): void
ksort($item);
}
}

foreach ($expected as &$item) {
if (is_array($item)) {
ksort($item);
Expand Down Expand Up @@ -221,6 +223,7 @@ public function testCreateStatusRequestData(array $order, array $expected): void
ksort($item);
}
}

foreach ($expected as &$item) {
if (is_array($item)) {
ksort($item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function testMapPaymentResponse(string $txType, array $responseData, arra
$this->assertIsArray($actualData['all']);
$this->assertNotEmpty($actualData['all']);
}

unset($actualData['all']);
\ksort($expectedData);
\ksort($actualData);
Expand Down

0 comments on commit 5e42b54

Please sign in to comment.