diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d64abbe3..dc95d65a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10,6 +10,11 @@ parameters: 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\\}\\.$#" + count: 1 + path: src/Crypt/PosNetCrypt.php + - message: "#^Parameter \\#1 \\$currency of method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\AkbankPosRequestDataMapper\\:\\:mapCurrency\\(\\) expects 'EUR'\\|'GBP'\\|'JPY'\\|'RUB'\\|'TRY'\\|'USD', string given\\.$#" count: 5 diff --git a/src/Crypt/AkbankPosCrypt.php b/src/Crypt/AkbankPosCrypt.php index a7cdde01..21439282 100644 --- a/src/Crypt/AkbankPosCrypt.php +++ b/src/Crypt/AkbankPosCrypt.php @@ -6,7 +6,6 @@ namespace Mews\Pos\Crypt; use Mews\Pos\Entity\Account\AbstractPosAccount; -use Mews\Pos\Entity\Account\AkbankPosAccount; use Mews\Pos\Exceptions\NotImplementedException; class AkbankPosCrypt extends AbstractCrypt @@ -24,7 +23,6 @@ public function generateRandomString(int $length = 128): string } /** - * @param AkbankPosAccount $posAccount * {@inheritDoc} */ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string @@ -32,8 +30,8 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): $hashData = [ $formInputs['paymentModel'], $formInputs['txnCode'], - $posAccount->getClientId(), - $posAccount->getTerminalId(), + $formInputs['merchantSafeId'], + $formInputs['terminalSafeId'], $formInputs['orderId'], $formInputs['lang'], $formInputs['amount'], @@ -45,7 +43,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): $formInputs['okUrl'], $formInputs['failUrl'], $formInputs['emailAddress'] ?? '', - $posAccount->getSubMerchantId() ?? '', + $formInputs['subMerchantId'] ?? '', // 3D hosting model does not have credit card information $formInputs['creditCard'] ?? '', diff --git a/src/Crypt/EstPosCrypt.php b/src/Crypt/EstPosCrypt.php index 51266e47..2341bb7e 100644 --- a/src/Crypt/EstPosCrypt.php +++ b/src/Crypt/EstPosCrypt.php @@ -16,7 +16,7 @@ class EstPosCrypt extends AbstractCrypt public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string { $hashData = [ - $posAccount->getClientId(), + $formInputs['clientid'], $formInputs['oid'], $formInputs['amount'], $formInputs['okUrl'], @@ -27,7 +27,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): $posAccount->getStoreKey(), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } diff --git a/src/Crypt/GarantiPosCrypt.php b/src/Crypt/GarantiPosCrypt.php index b20eb362..38c9a3f9 100644 --- a/src/Crypt/GarantiPosCrypt.php +++ b/src/Crypt/GarantiPosCrypt.php @@ -20,7 +20,7 @@ class GarantiPosCrypt extends AbstractCrypt public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string { $map = [ - $posAccount->getTerminalId(), + $formInputs['terminalid'], $formInputs['orderid'], $formInputs['txnamount'], $formInputs['txncurrencycode'], @@ -29,10 +29,10 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): $formInputs['txntype'], $formInputs['txninstallmentcount'], $posAccount->getStoreKey(), - $this->createSecurityData($posAccount, $formInputs['txntype']), + $this->createSecurityData($posAccount, $formInputs['terminalid'], $formInputs['txntype']), ]; - return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM); + return $this->hashStringUpperCase(\implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM); } /** @@ -71,14 +71,14 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): { $map = [ $requestData['Order']['OrderID'], - $posAccount->getTerminalId(), + $requestData['Terminal']['ID'], $requestData['Card']['Number'] ?? null, $requestData['Transaction']['Amount'], $requestData['Transaction']['CurrencyCode'] ?? null, - $this->createSecurityData($posAccount, $requestData['Transaction']['Type']), + $this->createSecurityData($posAccount, $requestData['Terminal']['ID'], $requestData['Transaction']['Type']), ]; - return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM); + return $this->hashStringUpperCase(\implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM); } /** @@ -93,17 +93,18 @@ public function hashString(string $str, ?string $encryptionKey = null): string * Make Security Data * * @param GarantiPosAccount $posAccount + * @param string $terminalId * @param string|null $txType * * @return string */ - private function createSecurityData(AbstractPosAccount $posAccount, ?string $txType = null): string + private function createSecurityData(AbstractPosAccount $posAccount, string $terminalId, ?string $txType = null): string { - $password = 'void' === $txType || 'refund' === $txType ? $posAccount->getRefundPassword() : $posAccount->getPassword(); + $password = ('void' === $txType || 'refund' === $txType) ? $posAccount->getRefundPassword() : $posAccount->getPassword(); $map = [ $password, - \str_pad($posAccount->getTerminalId(), 9, '0', STR_PAD_LEFT), + \str_pad($terminalId, 9, '0', STR_PAD_LEFT), ]; return $this->hashStringUpperCase(\implode(static::HASH_SEPARATOR, $map), 'sha1'); @@ -116,6 +117,6 @@ private function createSecurityData(AbstractPosAccount $posAccount, ?string $txT */ private function hashStringUpperCase(string $str, string $algorithm): string { - return strtoupper(hash($algorithm, $str)); + return strtoupper(\hash($algorithm, $str)); } } diff --git a/src/Crypt/InterPosCrypt.php b/src/Crypt/InterPosCrypt.php index ae5b3253..cc24cfee 100644 --- a/src/Crypt/InterPosCrypt.php +++ b/src/Crypt/InterPosCrypt.php @@ -16,7 +16,7 @@ class InterPosCrypt extends AbstractCrypt public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): string { $hashData = [ - $posAccount->getClientId(), + $formInputs['ShopCode'], $formInputs['OrderId'], $formInputs['PurchAmount'], $formInputs['OkUrl'], @@ -27,7 +27,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): $posAccount->getStoreKey(), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } diff --git a/src/Crypt/KuveytPosCrypt.php b/src/Crypt/KuveytPosCrypt.php index 19adb0c1..8aa7ccc9 100644 --- a/src/Crypt/KuveytPosCrypt.php +++ b/src/Crypt/KuveytPosCrypt.php @@ -38,7 +38,7 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): $hashedPassword = $this->hashString($posAccount->getStoreKey()); $hashData = [ - $posAccount->getClientId(), + $requestData['MerchantId'], // non-payment request may not have MerchantOrderId and Amount fields $requestData['MerchantOrderId'] ?? '', $requestData['Amount'] ?? '', @@ -47,7 +47,7 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): $requestData['OkUrl'] ?? '', $requestData['FailUrl'] ?? '', - $posAccount->getUsername(), + $requestData['UserName'], $hashedPassword, ]; diff --git a/src/Crypt/PayFlexCPV4Crypt.php b/src/Crypt/PayFlexCPV4Crypt.php index 9ca94c52..50e624c5 100644 --- a/src/Crypt/PayFlexCPV4Crypt.php +++ b/src/Crypt/PayFlexCPV4Crypt.php @@ -35,15 +35,15 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool public function createHash(AbstractPosAccount $posAccount, array $requestData): string { $hashData = [ - $posAccount->getClientId(), + $requestData['HostMerchantId'], $requestData['AmountCode'], $requestData['Amount'], - $posAccount->getPassword(), + $requestData['MerchantPassword'], '', 'VBank3DPay2014', // todo ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } diff --git a/src/Crypt/PayForPosCrypt.php b/src/Crypt/PayForPosCrypt.php index e5aa8c97..3bd19836 100644 --- a/src/Crypt/PayForPosCrypt.php +++ b/src/Crypt/PayForPosCrypt.php @@ -26,7 +26,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs): $formInputs['Rnd'], $posAccount->getStoreKey(), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } @@ -47,7 +47,7 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool $posAccount->getUsername(), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); $hash = $this->hashString($hashStr); diff --git a/src/Crypt/PosNetCrypt.php b/src/Crypt/PosNetCrypt.php index 45eafab2..16091fad 100644 --- a/src/Crypt/PosNetCrypt.php +++ b/src/Crypt/PosNetCrypt.php @@ -32,13 +32,17 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs, */ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool { + if (null === $posAccount->getStoreKey()) { + throw new \LogicException('Account storeKey eksik!'); + } + $secondHashData = [ $data['mdStatus'], $data['xid'], $data['amount'], $data['currency'], $posAccount->getClientId(), - $this->createSecurityData($posAccount), + $this->createSecurityData($posAccount->getStoreKey(), $posAccount->getTerminalId()), ]; $hashStr = implode(static::HASH_SEPARATOR, $secondHashData); @@ -58,20 +62,24 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool } /** - * @param PosNetAccount $posAccount + * @param array{amount: int, currency: string, id: string} $order * * @inheritdoc */ - public function createHash(AbstractPosAccount $posAccount, array $requestData): string + public function createHash(AbstractPosAccount $posAccount, array $requestData, array $order = []): string { + if (null === $posAccount->getStoreKey()) { + throw new \LogicException('Account storeKey eksik!'); + } + $hashData = [ - $requestData['id'], - $requestData['amount'], - $requestData['currency'], - $posAccount->getClientId(), - $this->createSecurityData($posAccount), + $order['id'], + $order['amount'], + $order['currency'], + $requestData['mid'], + $this->createSecurityData($posAccount->getStoreKey(), $requestData['tid']), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } @@ -79,17 +87,18 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): /** * Make Security Data * - * @param PosNetAccount $posAccount + * @param string $storeKey + * @param string $terminalId * * @return string */ - public function createSecurityData(AbstractPosAccount $posAccount): string + private function createSecurityData(string $storeKey, string $terminalId): string { $hashData = [ - $posAccount->getStoreKey(), - $posAccount->getTerminalId(), + $storeKey, + $terminalId, ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } diff --git a/src/Crypt/PosNetV1PosCrypt.php b/src/Crypt/PosNetV1PosCrypt.php index 4106e8f2..00fc85f6 100644 --- a/src/Crypt/PosNetV1PosCrypt.php +++ b/src/Crypt/PosNetV1PosCrypt.php @@ -6,7 +6,6 @@ namespace Mews\Pos\Crypt; use Mews\Pos\Entity\Account\AbstractPosAccount; -use Mews\Pos\Entity\Account\PosNetAccount; class PosNetV1PosCrypt extends AbstractCrypt { @@ -17,15 +16,13 @@ class PosNetV1PosCrypt extends AbstractCrypt protected const HASH_SEPARATOR = ''; /** - * @param PosNetAccount $posAccount - * * {@inheritDoc} */ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs, ?string $txType = null): string { $hashData = [ - $posAccount->getClientId(), - $posAccount->getTerminalId(), + $formInputs['MerchantNo'], + $formInputs['TerminalNo'], // no card data for 3D host payment $formInputs['CardNo'] ?? null, $formInputs['Cvv'] ?? null, @@ -40,8 +37,6 @@ public function create3DHash(AbstractPosAccount $posAccount, array $formInputs, } /** - * @param PosNetAccount $posAccount - * * {@inheritdoc} */ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool @@ -68,7 +63,6 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool } /** - * @param PosNetAccount $posAccount * @param array> $requestData * * @inheritDoc @@ -77,9 +71,11 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): { /** @var array $threeDSecureData */ $threeDSecureData = $requestData['ThreeDSecureData']; + + /** @var array $hashData */ $hashData = [ - $posAccount->getClientId(), - $posAccount->getTerminalId(), + $requestData['MerchantNo'], + $requestData['TerminalNo'], $threeDSecureData['SecureTransactionId'], $threeDSecureData['CavvData'], $threeDSecureData['Eci'], @@ -87,7 +83,7 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): $posAccount->getStoreKey(), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); + $hashStr = \implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); } diff --git a/src/Crypt/ToslaPosCrypt.php b/src/Crypt/ToslaPosCrypt.php index 3679e049..3232fcd6 100644 --- a/src/Crypt/ToslaPosCrypt.php +++ b/src/Crypt/ToslaPosCrypt.php @@ -57,8 +57,8 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData): { $hashData = [ $posAccount->getStoreKey(), - $posAccount->getClientId(), - $posAccount->getUsername(), + $requestData['clientId'], + $requestData['apiUser'], $requestData['rnd'], $requestData['timeSpan'], ]; diff --git a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php index 8a3ffd71..62ca6e79 100644 --- a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php @@ -6,6 +6,8 @@ namespace Mews\Pos\DataMapper\RequestDataMapper; use InvalidArgumentException; +use Mews\Pos\Crypt\CryptInterface; +use Mews\Pos\Crypt\PosNetCrypt; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; @@ -67,6 +69,9 @@ class PosNetRequestDataMapper extends AbstractRequestDataMapper PosInterface::CURRENCY_RUB => 'RU', ]; + /** @var PosNetCrypt */ + protected CryptInterface $crypt; + /** * @param PosNetAccount $posAccount * @param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType kullanilmiyor @@ -77,14 +82,12 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array { $order = $this->preparePaymentOrder($order); - $mappedOrder = $order; + $mappedOrder = []; $mappedOrder['id'] = self::formatOrderId($order['id']); $mappedOrder['amount'] = $this->formatAmount($order['amount']); - $mappedOrder['currency'] = $this->mapCurrency($order['currency']); - - $hash = $this->crypt->createHash($posAccount, $mappedOrder); + $mappedOrder['currency'] = (string) $this->mapCurrency($order['currency']); - return [ + $requestData = [ 'mid' => $posAccount->getClientId(), 'tid' => $posAccount->getTerminalId(), 'oosTranData' => [ @@ -92,9 +95,12 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array 'merchantData' => $responseData['MerchantPacket'], 'sign' => $responseData['Sign'], 'wpAmount' => 0, - 'mac' => $hash, ], ]; + + $requestData['oosTranData']['mac'] = $this->crypt->createHash($posAccount, $requestData, $mappedOrder); + + return $requestData; } /** @@ -328,23 +334,24 @@ public function create3DResolveMerchantRequestData(AbstractPosAccount $posAccoun { $order = $this->preparePaymentOrder($order); - $mappedOrder = $order; + $mappedOrder = []; $mappedOrder['id'] = self::formatOrderId($order['id']); $mappedOrder['amount'] = $this->formatAmount($order['amount']); - $mappedOrder['currency'] = $this->mapCurrency($order['currency']); + $mappedOrder['currency'] = (string) $this->mapCurrency($order['currency']); - $hash = $this->crypt->createHash($posAccount, $mappedOrder); - - return [ + $requestData = [ 'mid' => $posAccount->getClientId(), 'tid' => $posAccount->getTerminalId(), 'oosResolveMerchantData' => [ 'bankData' => $responseData['BankPacket'], 'merchantData' => $responseData['MerchantPacket'], 'sign' => $responseData['Sign'], - 'mac' => $hash, ], ]; + + $requestData['oosResolveMerchantData']['mac'] = $this->crypt->createHash($posAccount, $requestData, $mappedOrder); + + return $requestData; } /** diff --git a/tests/Unit/Crypt/AkbankPosCryptTest.php b/tests/Unit/Crypt/AkbankPosCryptTest.php index 6efd3ea4..4aad5b7c 100644 --- a/tests/Unit/Crypt/AkbankPosCryptTest.php +++ b/tests/Unit/Crypt/AkbankPosCryptTest.php @@ -143,6 +143,32 @@ public static function create3DHashDataProvider(): array ], 'expected' => 'ilR2mCExklKEti+2x61A8pcOfzJ5z5M6xMYmmU8ClaKaDuxKooFuH3v7XW/ba25xlTDqGN1H//i0zTiJl5YnfA==', ], + '3d_secure_with_sub_merchant_id' => [ + 'requestData' => [ + 'paymentModel' => '3D', + 'txnCode' => '3000', + 'merchantSafeId' => '2023090417500272654BD9A49CF07574', + 'terminalSafeId' => '2023090417500284633D137A249DBBEB', + 'orderId' => '20240404A4B0', + 'lang' => 'TR', + 'amount' => '1.01', + 'ccbRewardAmount' => '1.00', + 'pcbRewardAmount' => '1.00', + 'xcbRewardAmount' => '1.00', + 'currencyCode' => '949', + 'installCount' => '1', + 'okUrl' => 'http://localhost/akbankpos/3d/response.php', + 'failUrl' => 'http://localhost/akbankpos/3d/response.php', + 'subMerchantId' => 'hdfksafjsallk', + 'emailAddress' => 'test@test.com', + 'randomNumber' => 'AEDDD8688E11A3DC588DAB2ED59B2F64D45E798761CEFF17F4DB47581072697890180C4195986250F89C2C67A04A3B96F0AC66AE99B49BB7BEE618FBD621C4CD', + 'requestDateTime' => '2024-04-04T21:11:41.000', + 'creditCard' => '4355093000315232', + 'expiredDate' => '1135', + 'cvv' => '665', + ], + 'expected' => 'blqnTrcdZ2JhQBjOmIhyYPhKvC4BlbG7oArE5IkCeuo8CwaYV69EJSOph7J1JKY9opIsmc5QoscGmltGMUJtTQ==', + ], '3d_host' => [ 'requestData' => [ 'paymentModel' => 'MODEL_3D_HOST', diff --git a/tests/Unit/Crypt/EstPosCryptTest.php b/tests/Unit/Crypt/EstPosCryptTest.php index 4a66a359..c8e13f89 100644 --- a/tests/Unit/Crypt/EstPosCryptTest.php +++ b/tests/Unit/Crypt/EstPosCryptTest.php @@ -44,6 +44,7 @@ protected function setUp(): void public function testCreate3DHash(): void { $requestData = [ + 'clientid' => '700655000200', 'oid' => 'order222', 'amount' => '100.25', 'taksit' => '', @@ -58,26 +59,6 @@ public function testCreate3DHash(): void $this->assertSame($expected, $actual); } - /** - * @return void - */ - public function testCreate3DHashFor3DPay(): void - { - $requestData = [ - 'oid' => 'order222', - 'amount' => '100.25', - 'islemtipi' => 'Auth', - 'taksit' => '', - 'okUrl' => 'https://domain.com/success', - 'failUrl' => 'https://domain.com/fail_url', - 'rnd' => 'rand', - ]; - $expected = 'S7UxUAohxaxzl35WxHyDfuQx0sg='; - - $actual = $this->crypt->create3DHash($this->account, $requestData); - $this->assertSame($expected, $actual); - } - /** * @dataProvider threeDHashCheckDataProvider */ diff --git a/tests/Unit/Crypt/GarantiPosCryptTest.php b/tests/Unit/Crypt/GarantiPosCryptTest.php index 6a635a1a..d2498375 100644 --- a/tests/Unit/Crypt/GarantiPosCryptTest.php +++ b/tests/Unit/Crypt/GarantiPosCryptTest.php @@ -67,17 +67,18 @@ public function testCheck3DHashException(): void public function testCreate3DHash(): void { $requestData = [ - 'orderid' => 'order222', - 'txnamount' => 10025, - 'txninstallmentcount' => '', - 'txntype' => 'sales', - 'txncurrencycode' => '949', - 'successurl' => 'https://domain.com/success', - 'errorurl' => 'https://domain.com/fail_url', + 'terminalid' => '30691298', + 'orderid' => 'order222', + 'txnamount' => 10025, + 'txninstallmentcount' => '', + 'txntype' => 'sales', + 'txncurrencycode' => '949', + 'successurl' => 'https://domain.com/success', + 'errorurl' => 'https://domain.com/fail_url', ]; $expected = '372D6CB20B2B699D0A6667DFF46E3AA8CF3F9D8C2BB69A7C411895151FFCFAAB5277CCFE3B3A06035FEEFBFBFD40C79DBE51DBF867D0A24B37335A28F0CEFDE2'; - $actual = $this->crypt->create3DHash($this->account, $requestData); + $actual = $this->crypt->create3DHash($this->account, $requestData); $this->assertSame($expected, $actual); } @@ -97,51 +98,51 @@ public static function threeDHashCheckDataProvider(): array [ 'expectedResult' => true, 'responseData' => [ - 'xid' => 'f3ec4783-f48c-475c-a59c-ab25f3170ec5', - 'mdstatus' => '1', - 'mderrormessage' => 'Y-status/Challenge authentication via ACS: https://gbemv3dsecure.garanti.com.tr/web/creq', - 'txnstatus' => '', - 'eci' => '02', - 'cavv' => 'xgRlQDz4AAAAAAAAAAAAAAAAAAA=', - 'paressyntaxok' => '', - 'paresverified' => '', - 'version' => '', - 'ireqcode' => '', - 'ireqdetail' => '', - 'vendorcode' => '', - 'cavvalgorithm' => '', - 'md' => 'aW5kZXg6MDJ6LjAI5iAcKf/ilXjYIOnTh4t+deHrtwO8ze7tPTL1YCDcBe8KEpuq6HDLYbqQSluL7p3kGcpFzX9s9XcegNhHMsDszxqGd33+p+p5sULGrDF3J2GGfiJDwan4ku7+eiTyS8x2xS9pUy7PTgMGc6jw94aLfXLHskhvY7FYWrymzQ==', - 'terminalid' => '30691298', - 'oid' => '2023100354BB', - 'authcode' => '', - 'response' => '', - 'errmsg' => '', - 'hostmsg' => '', - 'procreturncode' => '', - 'transid' => '2023100354BB', - 'hostrefnum' => '', - 'rnd' => 'kW094tPzNEhqORzzCsLB', - 'hash' => '416B6253425E73184F118CC02E3BAA393622059BF6B0865D83F501E55A61339B9EC659CBCF7297EDECC1B17BF6281D90CC0AD8EDF3E1EFE94432ACCEAF79B26E', - 'hashparams' => 'clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:', - 'hashparamsval' => '306912982023100354BB1xgRlQDz4AAAAAAAAAAAAAAAAAAA=02aW5kZXg6MDJ6LjAI5iAcKf/ilXjYIOnTh4t+deHrtwO8ze7tPTL1YCDcBe8KEpuq6HDLYbqQSluL7p3kGcpFzX9s9XcegNhHMsDszxqGd33+p+p5sULGrDF3J2GGfiJDwan4ku7+eiTyS8x2xS9pUy7PTgMGc6jw94aLfXLHskhvY7FYWrymzQ==kW094tPzNEhqORzzCsLB', - 'clientid' => '30691298', - 'MaskedPan' => '54066975****1173', - 'apiversion' => '512', - 'orderid' => '2023100354BB', - 'txninstallmentcount' => '', - 'terminaluserid' => 'PROVAUT', - 'secure3dhash' => 'B0EE6F6405ABB6EF014D802880EF3DC72CEA1EFD16E7E346A4CD6F6EE6ED2148FA8DCFD703EAEA9C154C7C200CF42D00A874832D6D3F22F9447EDF241D540286', + 'xid' => 'f3ec4783-f48c-475c-a59c-ab25f3170ec5', + 'mdstatus' => '1', + 'mderrormessage' => 'Y-status/Challenge authentication via ACS: https://gbemv3dsecure.garanti.com.tr/web/creq', + 'txnstatus' => '', + 'eci' => '02', + 'cavv' => 'xgRlQDz4AAAAAAAAAAAAAAAAAAA=', + 'paressyntaxok' => '', + 'paresverified' => '', + 'version' => '', + 'ireqcode' => '', + 'ireqdetail' => '', + 'vendorcode' => '', + 'cavvalgorithm' => '', + 'md' => 'aW5kZXg6MDJ6LjAI5iAcKf/ilXjYIOnTh4t+deHrtwO8ze7tPTL1YCDcBe8KEpuq6HDLYbqQSluL7p3kGcpFzX9s9XcegNhHMsDszxqGd33+p+p5sULGrDF3J2GGfiJDwan4ku7+eiTyS8x2xS9pUy7PTgMGc6jw94aLfXLHskhvY7FYWrymzQ==', + 'terminalid' => '30691298', + 'oid' => '2023100354BB', + 'authcode' => '', + 'response' => '', + 'errmsg' => '', + 'hostmsg' => '', + 'procreturncode' => '', + 'transid' => '2023100354BB', + 'hostrefnum' => '', + 'rnd' => 'kW094tPzNEhqORzzCsLB', + 'hash' => '416B6253425E73184F118CC02E3BAA393622059BF6B0865D83F501E55A61339B9EC659CBCF7297EDECC1B17BF6281D90CC0AD8EDF3E1EFE94432ACCEAF79B26E', + 'hashparams' => 'clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:', + 'hashparamsval' => '306912982023100354BB1xgRlQDz4AAAAAAAAAAAAAAAAAAA=02aW5kZXg6MDJ6LjAI5iAcKf/ilXjYIOnTh4t+deHrtwO8ze7tPTL1YCDcBe8KEpuq6HDLYbqQSluL7p3kGcpFzX9s9XcegNhHMsDszxqGd33+p+p5sULGrDF3J2GGfiJDwan4ku7+eiTyS8x2xS9pUy7PTgMGc6jw94aLfXLHskhvY7FYWrymzQ==kW094tPzNEhqORzzCsLB', + 'clientid' => '30691298', + 'MaskedPan' => '54066975****1173', + 'apiversion' => '512', + 'orderid' => '2023100354BB', + 'txninstallmentcount' => '', + 'terminaluserid' => 'PROVAUT', + 'secure3dhash' => 'B0EE6F6405ABB6EF014D802880EF3DC72CEA1EFD16E7E346A4CD6F6EE6ED2148FA8DCFD703EAEA9C154C7C200CF42D00A874832D6D3F22F9447EDF241D540286', 'secure3dsecuritylevel' => '3D', - 'txncurrencycode' => '949', - 'customeremailaddress' => 'mail@customer.com', - 'errorurl' => 'http://localhost/garanti/3d/response.php', - 'terminalmerchantid' => '7000679', - 'mode' => 'TEST', - 'terminalprovuserid' => 'PROVAUT', - 'txnamount' => '101', - 'successurl' => 'http://localhost/garanti/3d/response.php', - 'txntype' => 'sales', - 'customeripaddress' => '172.26.0.1', + 'txncurrencycode' => '949', + 'customeremailaddress' => 'mail@customer.com', + 'errorurl' => 'http://localhost/garanti/3d/response.php', + 'terminalmerchantid' => '7000679', + 'mode' => 'TEST', + 'terminalprovuserid' => 'PROVAUT', + 'txnamount' => '101', + 'successurl' => 'http://localhost/garanti/3d/response.php', + 'txntype' => 'sales', + 'customeripaddress' => '172.26.0.1', ], ], ]; @@ -152,60 +153,75 @@ public static function hashCreateDataProvider(): array return [ [ 'requestData' => [ + 'Terminal' => [ + 'ID' => '30691298', + ], 'Order' => [ 'OrderID' => 'order222', ], 'Transaction' => [ - 'Type' => 'sales', - 'Amount' => 10025, + 'Type' => 'sales', + 'Amount' => 10025, 'CurrencyCode' => '949', ], ], - 'expected' => '0CFE09F107274C6A07292DA061A4EECAB0F5F0CF87F831F2D3626A3346A941126C52D1D95A3B77ADF5AC348B3D25C76BA5D8D98A29557D087D3367BFFACCD25C', + 'expected' => '0CFE09F107274C6A07292DA061A4EECAB0F5F0CF87F831F2D3626A3346A941126C52D1D95A3B77ADF5AC348B3D25C76BA5D8D98A29557D087D3367BFFACCD25C', ], [ 'requestData' => [ + 'Terminal' => [ + 'ID' => '30691298', + ], 'Order' => [ 'OrderID' => 'order222', ], 'Transaction' => [ - 'Type' => 'preauth', - 'Amount' => 10025, + 'Type' => 'preauth', + 'Amount' => 10025, 'CurrencyCode' => '949', ], ], - 'expected' => '0CFE09F107274C6A07292DA061A4EECAB0F5F0CF87F831F2D3626A3346A941126C52D1D95A3B77ADF5AC348B3D25C76BA5D8D98A29557D087D3367BFFACCD25C', + 'expected' => '0CFE09F107274C6A07292DA061A4EECAB0F5F0CF87F831F2D3626A3346A941126C52D1D95A3B77ADF5AC348B3D25C76BA5D8D98A29557D087D3367BFFACCD25C', ], [ 'requestData' => [ + 'Terminal' => [ + 'ID' => '30691298', + ], 'Order' => [ 'OrderID' => '4499996', ], 'Transaction' => [ - 'Type' => 'void', + 'Type' => 'void', // for cancel request amount is always 100 - 'Amount' => 100, + 'Amount' => 100, 'CurrencyCode' => '949', ], ], - 'expected' => 'C0C88761726D1844AF49FBE756DBE4586F7339169994CF700AE50AA8EAD0C8E81F5828C3392CE39CFC3F8C976FC3E24B576F4DB55DAF2E7D3A6F6B6E5E89B189', + 'expected' => 'C0C88761726D1844AF49FBE756DBE4586F7339169994CF700AE50AA8EAD0C8E81F5828C3392CE39CFC3F8C976FC3E24B576F4DB55DAF2E7D3A6F6B6E5E89B189', ], [ 'requestData' => [ + 'Terminal' => [ + 'ID' => '30691298', + ], 'Order' => [ 'OrderID' => '4499996', ], 'Transaction' => [ - 'Type' => 'refund', - 'Amount' => 202, + 'Type' => 'refund', + 'Amount' => 202, 'CurrencyCode' => '949', ], ], - 'expected' => '0F97D922001221B9C90AA692CF5D4082FF6D3EB38BE863A47F9C08E63CD87312270D6F298E5FBBC320654861DA1C6EE826E0C83E904916351A9D3032FA426BAA', + 'expected' => '0F97D922001221B9C90AA692CF5D4082FF6D3EB38BE863A47F9C08E63CD87312270D6F298E5FBBC320654861DA1C6EE826E0C83E904916351A9D3032FA426BAA', ], 'bininq' => [ 'requestData' => [ 'Version' => 'v0.00', + 'Terminal' => [ + 'ID' => '30691298', + ], 'Customer' => [ 'IPAddress' => '1.1.111.111', 'EmailAddress' => 'Cem@cem.com', @@ -224,7 +240,7 @@ public static function hashCreateDataProvider(): array ], ], ], - 'expected' => 'B129BF998FF8C97C42D3FC923AA4271656B112549665FA130ACF631EA3EB73D917AEB3D646481564CACE38D1687F7744F82E5A1DBB6966F1512E0AF29B4C067B', + 'expected' => 'B129BF998FF8C97C42D3FC923AA4271656B112549665FA130ACF631EA3EB73D917AEB3D646481564CACE38D1687F7744F82E5A1DBB6966F1512E0AF29B4C067B', ], ]; } diff --git a/tests/Unit/Crypt/InterPosCryptTest.php b/tests/Unit/Crypt/InterPosCryptTest.php index eb5ae8a7..c8bacf0d 100644 --- a/tests/Unit/Crypt/InterPosCryptTest.php +++ b/tests/Unit/Crypt/InterPosCryptTest.php @@ -129,6 +129,7 @@ public static function threeDHashCreateDataProvider(): array return [ [ 'requestData' => [ + 'ShopCode' => '3123', 'OrderId' => 'order222', 'PurchAmount' => '100.25', 'TxnType' => 'Auth', diff --git a/tests/Unit/Crypt/KuveytPosCryptTest.php b/tests/Unit/Crypt/KuveytPosCryptTest.php index f73d1f1f..d2f7a3bf 100644 --- a/tests/Unit/Crypt/KuveytPosCryptTest.php +++ b/tests/Unit/Crypt/KuveytPosCryptTest.php @@ -82,6 +82,8 @@ public static function hashCreateDataProvider(): array return [ [ 'requestData' => [ + 'MerchantId' => '80', + 'UserName' => 'apiuser', 'MerchantOrderId' => 'ORDER-123', 'Amount' => 7256, ], @@ -89,6 +91,8 @@ public static function hashCreateDataProvider(): array ], [ 'requestData' => [ + 'MerchantId' => '80', + 'UserName' => 'apiuser', 'MerchantOrderId' => 'ORDER-123', 'Amount' => 7256, 'OkUrl' => 'http://localhost:44785/Home/Success', diff --git a/tests/Unit/Crypt/PayFlexCP4CryptTest.php b/tests/Unit/Crypt/PayFlexCP4CryptTest.php index d182de47..c7527df0 100644 --- a/tests/Unit/Crypt/PayFlexCP4CryptTest.php +++ b/tests/Unit/Crypt/PayFlexCP4CryptTest.php @@ -69,8 +69,10 @@ public static function hashCreateDataProvider(): array return [ [ 'requestData' => [ - 'AmountCode' => '949', - 'Amount' => '10.10', + 'HostMerchantId' => '000000000111111', + 'MerchantPassword' => '3XTgER89as', + 'AmountCode' => '949', + 'Amount' => '10.10', ], 'expected' => '/MfLewtkUjpN5e/RY2iuIoT72hk=', ], diff --git a/tests/Unit/Crypt/PosNetCryptTest.php b/tests/Unit/Crypt/PosNetCryptTest.php index 3c4f83b3..f59dee61 100644 --- a/tests/Unit/Crypt/PosNetCryptTest.php +++ b/tests/Unit/Crypt/PosNetCryptTest.php @@ -2,9 +2,11 @@ /** * @license MIT */ + namespace Mews\Pos\Tests\Unit\Crypt; use Mews\Pos\Crypt\PosNetCrypt; +use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\Factory\AccountFactory; @@ -46,16 +48,30 @@ public function testCreate3DHashException(): void $this->crypt->create3DHash($this->account, []); } + public function testCreateHashException(): void + { + $account = $this->createMock(AbstractPosAccount::class); + $this->expectException(\LogicException::class); + $this->crypt->createHash($account, []); + } + /** * @dataProvider hashCreateDataProvider */ - public function testCreateHash(array $requestData, string $expected): void + public function testCreateHash(array $requestData, array $order, string $expected): void { - $actual = $this->crypt->createHash($this->account, $requestData); + $actual = $this->crypt->createHash($this->account, $requestData, $order); $this->assertSame($expected, $actual); } + public function testCheck3DHashException(): void + { + $account = $this->createMock(AbstractPosAccount::class); + $this->expectException(\LogicException::class); + $this->crypt->check3DHash($account, []); + } + /** * @dataProvider threeDHashCheckDataProvider */ @@ -67,28 +83,19 @@ public function testCheck3DHash(bool $expected, array $responseData): void $this->assertFalse($this->crypt->check3DHash($this->account, $responseData)); } - /** - * @return void - */ - public function testCreateSecurityData(): void - { - $this->assertSame('c1PPl+2UcdixyhgLYnf4VfJyFGaNQNOwE0uMkci7Uag=', $this->crypt->createSecurityData($this->account)); - } - public static function hashCreateDataProvider(): array { return [ [ 'requestData' => [ + 'mid' => '6706598320', + 'tid' => '67005551', + ], + 'order' => [ 'id' => 'TST_190620093100_024', 'amount' => 175, 'installment' => 0, 'currency' => 'TL', - 'success_url' => 'https://domain.com/success', - 'fail_url' => 'https://domain.com/fail_url', - 'rand' => '0.43625700 1604831630', - 'lang' => 'tr', - ], 'expected' => 'nyeFSQ4J9NZVeCcEGCDomM8e2YIvoeIa/IDh2D3qaL4=', ], diff --git a/tests/Unit/Crypt/PosNetV1PosCryptTest.php b/tests/Unit/Crypt/PosNetV1PosCryptTest.php index 1ab18cd6..34aae037 100644 --- a/tests/Unit/Crypt/PosNetV1PosCryptTest.php +++ b/tests/Unit/Crypt/PosNetV1PosCryptTest.php @@ -2,6 +2,7 @@ /** * @license MIT */ + namespace Mews\Pos\Tests\Unit\Crypt; use Mews\Pos\Crypt\PosNetV1PosCrypt; @@ -114,28 +115,28 @@ public static function hashFromParamsDataProvider(): array { return [ [ - 'storeKey' => '10,10,10,10,10,10,10,10', - 'data ' => [ + 'storeKey' => '10,10,10,10,10,10,10,10', + 'data ' => [ 'MACParams' => 'MerchantNo:TerminalNo:ReferenceCode:OrderId', 'MerchantNo' => '6700950031', 'TerminalNo' => '67540050', 'ReferenceCode' => '021459486690000191', 'OrderId' => null, ], - 'expected' => 'qhLo/2Ro+vT81i0SMV/VHifDV9VzQQgK+7d8hlId9YM=', + 'expected' => 'qhLo/2Ro+vT81i0SMV/VHifDV9VzQQgK+7d8hlId9YM=', ], [ - 'storeKey' => '10,10,10,10,10,10,10,10', + 'storeKey' => '10,10,10,10,10,10,10,10', 'requestData' => [ - 'MerchantNo' => '6700950031', - 'TerminalNo' => '67540050', - 'MACParams' => 'MerchantNo:TerminalNo:CardNo:Cvc2:ExpireDate:Amount', + 'MerchantNo' => '6700950031', + 'TerminalNo' => '67540050', + 'MACParams' => 'MerchantNo:TerminalNo:CardNo:Cvc2:ExpireDate:Amount', 'CardInformationData' => [ - 'Amount' => '175', - 'CardNo' => '5400619360964581', + 'Amount' => '175', + 'CardNo' => '5400619360964581', 'ExpireDate' => '2001', - 'Cvc2' => '056', - ] + 'Cvc2' => '056', + ], ], 'expected' => 'xuhPbpcPJ6kVs7JeIXS8f06Cv0mb9cNPMfjp1HiB7Ew=', ], @@ -181,6 +182,8 @@ public static function hashCreateDataProvider(): array return [ [ 'requestData' => [ + 'MerchantNo' => '6700950031', + 'TerminalNo' => '67540050', 'ThreeDSecureData' => [ 'MerchantNo' => '6700950031', 'TerminalNo' => '67540050', @@ -194,6 +197,8 @@ public static function hashCreateDataProvider(): array ], [ 'requestData' => [ + 'MerchantNo' => '6700950031', + 'TerminalNo' => '67540050', 'ThreeDSecureData' => [ 'MerchantNo' => '6700950031', 'TerminalNo' => '67540050', diff --git a/tests/Unit/Crypt/ToslaPosCryptTest.php b/tests/Unit/Crypt/ToslaPosCryptTest.php index c5f2431a..9148bbaf 100644 --- a/tests/Unit/Crypt/ToslaPosCryptTest.php +++ b/tests/Unit/Crypt/ToslaPosCryptTest.php @@ -47,6 +47,8 @@ public function testCreate3DHash(): void public function testCreateHash(): void { $requestData = [ + 'clientId' => '1000000494', + 'apiUser' => 'POS_ENT_Test_001', 'timeSpan' => '20231209201121', 'rnd' => 'rand', ]; diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php index fcd646b4..018096d9 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php @@ -194,9 +194,12 @@ public function testCreateCancelRequestData(array $order, array $expectedData): */ public function testCreate3DPaymentRequestData(array $order, array $mappedOrder, string $txType, array $responseData, array $expected): void { + $requestDataWithoutHash = $expected; + unset($requestDataWithoutHash['oosTranData']['mac']); + $this->crypt->expects(self::once()) ->method('createHash') - ->with($this->account, $mappedOrder) + ->with($this->account, $requestDataWithoutHash, $mappedOrder) ->willReturn($expected['oosTranData']['mac']); $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, $txType, $responseData); @@ -229,9 +232,12 @@ public function testCreate3DEnrollmentCheckRequestDataFailTooLongOrderId(): void */ public function testCreate3DResolveMerchantRequestData(array $order, array $mappedOrder, array $responseData, array $expectedData): void { + $requestDataWithoutMac = $expectedData; + unset($requestDataWithoutMac['oosResolveMerchantData']['mac']); + $this->crypt->expects(self::once()) ->method('createHash') - ->with($this->account, $mappedOrder) + ->with($this->account, $requestDataWithoutMac, $mappedOrder) ->willReturn($expectedData['oosResolveMerchantData']['mac']); $actualData = $this->requestDataMapper->create3DResolveMerchantRequestData($this->account, $order, $responseData); @@ -430,7 +436,6 @@ public static function create3DPaymentRequestDataDataProvider(): array 'mapped_order' => [ 'id' => '000000002020110828BC', 'amount' => 10001, - 'installment' => '0', 'currency' => 'TL', ], 'txType' => PosInterface::TX_TYPE_PAY_AUTH, @@ -687,7 +692,6 @@ public static function resolveMerchantDataDataProvider(): array 'mapped_order' => [ 'id' => '000000002020110828BC', 'amount' => 10001, - 'installment' => '0', 'currency' => 'TL', ], 'response_data' => [