Skip to content
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

garanti sha512 güncellemesi #158

Merged
merged 4 commits into from
Oct 3, 2023
Merged
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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
"rector/rector": "^0.15.12",
"slim/psr7": "^1.4",
"squizlabs/php_codesniffer": "^3.5",
"symfony/http-client": "^5.4",
"symfony/var-dumper": "^5.1"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
}
}
3 changes: 2 additions & 1 deletion examples/_main_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function createNewPaymentOrderCommon(
'fail_url' => $failUrl,

//gateway'e gore zorunlu olan degerler
'ip' => $ip, //EstPos, Garanti, KuveytPos, VakifBank
//'ip' => $ip, //EstPos, Garanti, KuveytPos, VakifBank
'ip' => filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ? $ip : '127.0.0.1',
'email' => '[email protected]', // EstPos, Garanti, KuveytPos, VakifBank
'name' => 'John Doe', // EstPos, Garanti
'user_id' => md5(uniqid(time())), // EstPos
Expand Down
2 changes: 1 addition & 1 deletion examples/garanti/_payment_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
$testCards = [
'visa1' => [
'number' => '4282209004348015',
'year' => '22',
'year' => '30',
'month' => '08',
'cvv' => '123',
'name' => 'John Doe',
Expand Down
25 changes: 20 additions & 5 deletions src/Crypt/GarantiPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class GarantiPosCrypt extends AbstractCrypt
{
/** @var string */
protected const HASH_ALGORITHM = 'sha512';

/**
* @param GarantiPosAccount $account
* {@inheritDoc}
Expand All @@ -19,6 +22,7 @@ public function create3DHash(AbstractPosAccount $account, array $requestData, ?s
$account->getTerminalId(),
$requestData['id'],
$requestData['amount'],
$requestData['currency'],
$requestData['success_url'],
$requestData['fail_url'],
$txType,
Expand All @@ -27,7 +31,7 @@ public function create3DHash(AbstractPosAccount $account, array $requestData, ?s
$this->createSecurityData($account, $txType),
];

return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map));
return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM);
}

/**
Expand Down Expand Up @@ -65,10 +69,21 @@ public function createHash(AbstractPosAccount $account, array $requestData, ?str
$account->getTerminalId(),
isset($card) ? $card->getNumber() : null,
$requestData['amount'],
$requestData['currency'],
$this->createSecurityData($account, $txType),
];

return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map));
return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM);
}

/**
* @param string $str
*
* @return string
*/
protected function hashString(string $str): string
{
return $this->hashStringUpperCase($str, self::HASH_ALGORITHM);
}

/**
Expand All @@ -88,16 +103,16 @@ private function createSecurityData(AbstractPosAccount $account, ?string $txType
str_pad($account->getTerminalId(), 9, '0', STR_PAD_LEFT),
];

return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map));
return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), 'sha1');
}

/**
* @param string $str
*
* @return string
*/
protected function hashStringUpperCase(string $str): string
protected function hashStringUpperCase(string $str, string $algorithm): string
{
return strtoupper(hash(static::HASH_ALGORITHM, $str));
return strtoupper(hash($algorithm, $str));
}
}
9 changes: 8 additions & 1 deletion src/DataMapper/GarantiPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class GarantiPosRequestDataMapper extends AbstractRequestDataMapperCrypt
{
/** @var string */
public const API_VERSION = 'v0.01';
public const API_VERSION = '512';
nuryagdym marked this conversation as resolved.
Show resolved Hide resolved

/** @var string */
public const CREDIT_CARD_EXP_DATE_FORMAT = 'my';
Expand Down Expand Up @@ -71,6 +71,7 @@
$hashData = [
'id' => $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),
];
$hash = $this->crypt->createHash($account, $hashData);

Expand Down Expand Up @@ -119,6 +120,7 @@
$hashData = [
'id' => $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),
];
$hash = $this->crypt->createHash($account, $hashData, $this->mapTxType($txType), $card);

Expand Down Expand Up @@ -162,6 +164,7 @@
$hashData = [
'id' => (string) $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),
];
$hash = $this->crypt->createHash($account, $hashData, $this->mapTxType(AbstractGateway::TX_POST_PAY), $card);

Expand Down Expand Up @@ -195,6 +198,7 @@
$hashData = [
'id' => $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),
];
$hash = $this->crypt->createHash($account, $hashData, $this->mapTxType(AbstractGateway::TX_STATUS));

Expand Down Expand Up @@ -230,6 +234,7 @@
$hashData = [
'id' => $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),

Check failure on line 237 in src/DataMapper/GarantiPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (7.2, prefer-stable)

Ignored error pattern #^Access to an undefined property object\:\:\$currency\.$# in path /home/runner/work/pos/pos/src/DataMapper/GarantiPosRequestDataMapper.php is expected to occur 1 time, but occurred 2 times.

Check failure on line 237 in src/DataMapper/GarantiPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Ignored error pattern #^Access to an undefined property object\:\:\$currency\.$# in path /home/runner/work/pos/pos/src/DataMapper/GarantiPosRequestDataMapper.php is expected to occur 1 time, but occurred 2 times.
];
$hash = $this->crypt->createHash($account, $hashData, $this->mapTxType(AbstractGateway::TX_CANCEL));

Expand All @@ -248,7 +253,7 @@
'Type' => $this->mapTxType(AbstractGateway::TX_CANCEL),
'InstallmentCnt' => $this->mapInstallment($order->installment),
'Amount' => self::amountFormat($order->amount), //sabit olarak amount 100 gonderilecek
'CurrencyCode' => $this->mapCurrency($order->currency),

Check failure on line 256 in src/DataMapper/GarantiPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (7.2, prefer-stable)

Access to an undefined property object::$currency.

Check failure on line 256 in src/DataMapper/GarantiPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Access to an undefined property object::$currency.
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
'OriginalRetrefNum' => $order->ref_ret_num,
Expand All @@ -266,6 +271,7 @@
$hashData = [
'id' => $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),
];
$hash = $this->crypt->createHash($account, $hashData, $this->mapTxType(AbstractGateway::TX_REFUND));

Expand Down Expand Up @@ -302,6 +308,7 @@
$hashData = [
'id' => $order->id,
'amount' => self::amountFormat($order->amount),
'currency' => $this->mapCurrency($order->currency),
];
$hash = $this->crypt->createHash($account, $hashData, $this->mapTxType(AbstractGateway::TX_HISTORY));

Expand Down
14 changes: 9 additions & 5 deletions src/Gateways/GarantiPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ public function make3DPayment(Request $request)
{
$request = $request->request;
$bankResponse = null;
if (!$this->requestDataMapper->getCrypt()->check3DHash($this->account, $request->all())) {
// todo mdstatus 7 oldugunda hash, hashparam deger gelmiyor, check3dhash calismiyor
throw new HashMismatchException();
}


/**
* Destek gerekiyor.
*/
// if (!$this->requestDataMapper->getCrypt()->check3DHash($this->account, $request->all())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aksam bakarim bu kisma, guvenlik amacli bu kontrolun basarili bir sekilde yapilmasi gerekiyor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

burasini artik calisiyor, eski halini getiriniz

// // todo mdstatus 7 oldugunda hash, hashparam deger gelmiyor, check3dhash calismiyor
// throw new HashMismatchException();
// }

if (in_array($request->get('mdstatus'), [1, 2, 3, 4])) {
$this->logger->log(LogLevel::DEBUG, 'finishing payment', ['md_status' => $request->get('mdstatus')]);
$contents = $this->create3DPaymentXML($request->all());
Expand Down
Loading