Skip to content

Commit

Permalink
rename createHash parameter for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Nov 17, 2024
1 parent 088ce7d commit 5d845c3
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 88 deletions.
16 changes: 16 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@
<directory>tests/Functional</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory="var/coverage-cache"
includeUncoveredFiles="true"
processUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<html outputDirectory="var/coverage-report-html"/>
<xml outputDirectory="var/coverage-report-xml"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
<include>
<directory>src</directory>
</include>
</coverage>
</phpunit>
45 changes: 21 additions & 24 deletions src/Crypt/AkbankPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ public function generateRandomString(int $length = 128): string
* @param AkbankPosAccount $posAccount
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
$hashData = [
$requestData['paymentModel'],
$requestData['txnCode'],
$formInputs['paymentModel'],
$formInputs['txnCode'],
$posAccount->getClientId(),
$posAccount->getTerminalId(),
$requestData['orderId'],
$requestData['lang'],
$requestData['amount'],
$requestData['ccbRewardAmount'] ?? '',
$requestData['pcbRewardAmount'] ?? '',
$requestData['xcbRewardAmount'] ?? '',
$requestData['currencyCode'],
$requestData['installCount'],
$requestData['okUrl'],
$requestData['failUrl'],
$requestData['emailAddress'] ?? '',
$formInputs['orderId'],
$formInputs['lang'],
$formInputs['amount'],
$formInputs['ccbRewardAmount'] ?? '',
$formInputs['pcbRewardAmount'] ?? '',
$formInputs['xcbRewardAmount'] ?? '',
$formInputs['currencyCode'],
$formInputs['installCount'],
$formInputs['okUrl'],
$formInputs['failUrl'],
$formInputs['emailAddress'] ?? '',
$posAccount->getSubMerchantId() ?? '',

// 3D hosting model does not have credit card information
$requestData['creditCard'] ?? '',
$requestData['expiredDate'] ?? '',
$requestData['cvv'] ?? '',
$formInputs['creditCard'] ?? '',
$formInputs['expiredDate'] ?? '',
$formInputs['cvv'] ?? '',

$requestData['randomNumber'],
$requestData['requestDateTime'],
$requestData['b2bIdentityNumber'] ?? '',
$formInputs['randomNumber'],
$formInputs['requestDateTime'],
$formInputs['b2bIdentityNumber'] ?? '',
];

$hashStr = \implode(static::HASH_SEPARATOR, $hashData);
Expand Down Expand Up @@ -89,10 +89,7 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
}

/**
* @param AbstractPosAccount $posAccount
* @param array<string, mixed> $requestData
*
* @return string
* @inheritDoc
*/
public function createHash(AbstractPosAccount $posAccount, array $requestData): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Crypt/CryptInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool;
* creates hash for 3D form data
*
* @param AbstractPosAccount $posAccount
* @param array<string, string> $requestData
* @param array<string, string> $formInputs
*
* @return string
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string;
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string;

/**
* create hash for API requests
Expand Down
21 changes: 9 additions & 12 deletions src/Crypt/EstPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class EstPosCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
$hashData = [
$posAccount->getClientId(),
$requestData['oid'],
$requestData['amount'],
$requestData['okUrl'],
$requestData['failUrl'],
$requestData['islemtipi'],
$requestData['taksit'],
$requestData['rnd'],
$formInputs['oid'],
$formInputs['amount'],
$formInputs['okUrl'],
$formInputs['failUrl'],
$formInputs['islemtipi'],
$formInputs['taksit'],
$formInputs['rnd'],
$posAccount->getStoreKey(),
];

Expand Down Expand Up @@ -59,10 +59,7 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
}

/**
* @param AbstractPosAccount $posAccount
* @param array<string, mixed> $requestData
*
* @return string
* @inheritDoc
*/
public function createHash(AbstractPosAccount $posAccount, array $requestData): string
{
Expand Down
17 changes: 7 additions & 10 deletions src/Crypt/EstV3PosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class EstV3PosCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
\ksort($requestData, SORT_NATURAL | SORT_FLAG_CASE);
foreach (\array_keys($requestData) as $key) {
\ksort($formInputs, SORT_NATURAL | SORT_FLAG_CASE);
foreach (\array_keys($formInputs) as $key) {
/**
* this part is needed only to create hash from the bank response
*
Expand All @@ -31,13 +31,13 @@ public function create3DHash(AbstractPosAccount $posAccount, array $requestData)
* Payten tarafından hash içerisinde olmaması gerektiği teyidi alındı.
*/
if (\in_array(\strtolower($key), ['hash', 'encoding' , 'nationalidno'])) {
unset($requestData[$key]);
unset($formInputs[$key]);
}
}

$requestData[] = $posAccount->getStoreKey();
$formInputs[] = $posAccount->getStoreKey();
// escape | and \ characters
$data = \str_replace("\\", "\\\\", \array_values($requestData));
$data = \str_replace("\\", "\\\\", \array_values($formInputs));
$data = \str_replace(self::HASH_SEPARATOR, "\\".self::HASH_SEPARATOR, $data);

$hashStr = \implode(self::HASH_SEPARATOR, $data);
Expand Down Expand Up @@ -68,10 +68,7 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
}

/**
* @param AbstractPosAccount $posAccount
* @param array<string, mixed> $requestData
*
* @return string
* @inheritDoc
*/
public function createHash(AbstractPosAccount $posAccount, array $requestData): string
{
Expand Down
18 changes: 9 additions & 9 deletions src/Crypt/GarantiPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class GarantiPosCrypt extends AbstractCrypt
* @param GarantiPosAccount $posAccount
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
$map = [
$posAccount->getTerminalId(),
$requestData['orderid'],
$requestData['txnamount'],
$requestData['txncurrencycode'],
$requestData['successurl'],
$requestData['errorurl'],
$requestData['txntype'],
$requestData['txninstallmentcount'],
$formInputs['orderid'],
$formInputs['txnamount'],
$formInputs['txncurrencycode'],
$formInputs['successurl'],
$formInputs['errorurl'],
$formInputs['txntype'],
$formInputs['txninstallmentcount'],
$posAccount->getStoreKey(),
$this->createSecurityData($posAccount, $requestData['txntype']),
$this->createSecurityData($posAccount, $formInputs['txntype']),
];

return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM);
Expand Down
16 changes: 8 additions & 8 deletions src/Crypt/InterPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class InterPosCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
$hashData = [
$posAccount->getClientId(),
$requestData['OrderId'],
$requestData['PurchAmount'],
$requestData['OkUrl'],
$requestData['FailUrl'],
$requestData['TxnType'],
$requestData['InstallmentCount'],
$requestData['Rnd'],
$formInputs['OrderId'],
$formInputs['PurchAmount'],
$formInputs['OkUrl'],
$formInputs['FailUrl'],
$formInputs['TxnType'],
$formInputs['InstallmentCount'],
$formInputs['Rnd'],
$posAccount->getStoreKey(),
];

Expand Down
2 changes: 1 addition & 1 deletion src/Crypt/KuveytPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class KuveytPosCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Crypt/NullCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NullCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Crypt/PayFlexCPV4Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PayFlexCPV4Crypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
throw new NotImplementedException();
}
Expand Down
18 changes: 9 additions & 9 deletions src/Crypt/PayForPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class PayForPosCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
$hashData = [
$requestData['MbrId'],
$requestData['OrderId'],
$requestData['PurchAmount'],
$requestData['OkUrl'],
$requestData['FailUrl'],
$requestData['TxnType'],
$requestData['InstallmentCount'],
$requestData['Rnd'],
$formInputs['MbrId'],
$formInputs['OrderId'],
$formInputs['PurchAmount'],
$formInputs['OkUrl'],
$formInputs['FailUrl'],
$formInputs['TxnType'],
$formInputs['InstallmentCount'],
$formInputs['Rnd'],
$posAccount->getStoreKey(),
];
$hashStr = implode(static::HASH_SEPARATOR, $hashData);
Expand Down
2 changes: 1 addition & 1 deletion src/Crypt/PosNetCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PosNetCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData, ?string $txType = null): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs, ?string $txType = null): string
{
throw new NotImplementedException();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Crypt/PosNetV1PosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class PosNetV1PosCrypt extends AbstractCrypt
*
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData, ?string $txType = null): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs, ?string $txType = null): string
{
$hashData = [
$posAccount->getClientId(),
$posAccount->getTerminalId(),
// no card data for 3D host payment
$requestData['CardNo'] ?? null,
$requestData['Cvv'] ?? null,
$requestData['ExpiredDate'] ?? null,
$formInputs['CardNo'] ?? null,
$formInputs['Cvv'] ?? null,
$formInputs['ExpiredDate'] ?? null,

$requestData['Amount'],
$formInputs['Amount'],
$posAccount->getStoreKey(),
];
$hashStr = \implode(static::HASH_SEPARATOR, $hashData);
Expand Down
7 changes: 2 additions & 5 deletions src/Crypt/ToslaPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ToslaPosCrypt extends AbstractCrypt
/**
* {@inheritDoc}
*/
public function create3DHash(AbstractPosAccount $posAccount, array $requestData): string
public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -51,10 +51,7 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
}

/**
* @param AbstractPosAccount $posAccount
* @param array<string, mixed> $requestData
*
* @return string
* @inheritDoc
*/
public function createHash(AbstractPosAccount $posAccount, array $requestData): string
{
Expand Down

0 comments on commit 5d845c3

Please sign in to comment.