From d2bbf19f5bdbe9a047540f4d59151c37095d46d3 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Wed, 2 Oct 2024 16:18:27 +0200 Subject: [PATCH 1/3] add more rules into .editorconfig --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 5b3b9654..77226817 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,10 @@ indent_size = 4 ij_php_align_assignments = true ij_php_align_class_constants = true ij_php_align_key_value_pairs = true +ij_php_align_phpdoc_param_names = true +ij_php_align_phpdoc_comments = true +ij_php_space_after_type_cast = true +ij_php_concat_spaces = false ij_php_phpdoc_param_spaces_between_tag_and_type = 1 [*.md] From c765b1774101fd84c611078f061263e056bfac97 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Wed, 2 Oct 2024 16:30:55 +0200 Subject: [PATCH 2/3] minor code refactor --- .../RequestDataMapper/AkbankPosRequestDataMapper.php | 2 +- .../RequestDataMapper/EstPosRequestDataMapper.php | 5 ++++- .../PayFlexCPV4PosRequestDataMapper.php | 9 --------- .../RequestDataMapper/ToslaPosRequestDataMapper.php | 2 +- .../VakifKatilimPosRequestDataMapper.php | 10 +++++----- src/Factory/RequestDataMapperFactory.php | 7 ++----- .../PayFlexCPV4PosRequestDataMapperTest.php | 12 ------------ 7 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php index 02620c82..f7820999 100644 --- a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php @@ -344,7 +344,7 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $ $requestData['report'] = [ 'batchNumber' => $order['batch_num'], ]; - } elseif (isset($order['start_date']) && isset($order['end_date'])) { + } elseif (isset($order['start_date'], $order['end_date'])) { $requestData['report'] = [ 'startDateTime' => $this->formatRequestDateTime($order['start_date']), 'endDateTime' => $this->formatRequestDateTime($order['end_date']), diff --git a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php index 8a01b4c5..cbb5cce1 100644 --- a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php @@ -135,7 +135,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po 'Total' => isset($order['amount']) ? (float) $this->formatAmount($order['amount']) : null, ]; - if (isset($order['amount']) && isset($order['pre_auth_amount']) && $order['pre_auth_amount'] < $order['amount']) { + if (isset($order['amount'], $order['pre_auth_amount']) && $order['pre_auth_amount'] < $order['amount']) { // when amount < pre_auth_amount then we need to send PREAMT value $requestData['Extra']['PREAMT'] = $order['pre_auth_amount']; } @@ -271,9 +271,12 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s * @phpstan-param PosInterface::MODEL_3D_* $paymentModel * @phpstan-param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType * + * @param AbstractPosAccount $posAccount * @param array $order * @param string $paymentModel * @param string $txType + * @param string $gatewayURL + * @param CreditCardInterface|null $creditCard * * @return array{gateway: string, method: 'POST', inputs: array} * diff --git a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php index 0ca2d167..3c502961 100644 --- a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php @@ -52,15 +52,6 @@ class PayFlexCPV4PosRequestDataMapper extends AbstractRequestDataMapper PosInterface::LANG_EN => 'en-US', ]; - /** - * {@inheritdoc} - */ - protected array $recurringOrderFrequencyMapping = [ - 'DAY' => 'Day', - 'MONTH' => 'Month', - 'YEAR' => 'Year', - ]; - /** * {@inheritDoc} * diff --git a/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php index 3e50d328..3fcddaae 100644 --- a/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php @@ -211,7 +211,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s if ($creditCard instanceof CreditCardInterface) { $inputs['CardHolderName'] = (string) $creditCard->getHolderName(); $inputs['CardNo'] = $creditCard->getNumber(); - $inputs['ExpireDate'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_DATE_FORMAT); + $inputs['ExpireDate'] = $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT); $inputs['Cvv'] = $creditCard->getCvv(); } diff --git a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php index 56fbf4ea..1355302e 100644 --- a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php @@ -411,13 +411,13 @@ protected function prepareRefundOrder(array $order): array * * @inheritDoc */ - protected function prepareHistoryOrder(array $order): array + protected function prepareHistoryOrder(array $data): array { return [ - 'start_date' => $order['start_date'], - 'end_date' => $order['end_date'], - 'page' => $order['page'] ?? 1, - 'page_size' => $order['page_size'] ?? 10, + 'start_date' => $data['start_date'], + 'end_date' => $data['end_date'], + 'page' => $data['page'] ?? 1, + 'page_size' => $data['page_size'] ?? 10, ]; } diff --git a/src/Factory/RequestDataMapperFactory.php b/src/Factory/RequestDataMapperFactory.php index b450b68b..72e81a54 100644 --- a/src/Factory/RequestDataMapperFactory.php +++ b/src/Factory/RequestDataMapperFactory.php @@ -45,8 +45,8 @@ class RequestDataMapperFactory /** * @param class-string $gatewayClass * @param EventDispatcherInterface $eventDispatcher - * @param array $currencies * @param CryptInterface $crypt + * @param array $currencies * * @return RequestDataMapperInterface */ @@ -65,15 +65,12 @@ public static function createGatewayRequestMapper(string $gatewayClass, EventDis PosNet::class => PosNetRequestDataMapper::class, PosNetV1Pos::class => PosNetV1PosRequestDataMapper::class, PayFlexCPV4Pos::class => PayFlexCPV4PosRequestDataMapper::class, + PayFlexV4Pos::class => PayFlexV4PosRequestDataMapper::class, ]; if (isset($classMappings[$gatewayClass])) { return new $classMappings[$gatewayClass]($eventDispatcher, $crypt, $currencies); } - if (PayFlexV4Pos::class === $gatewayClass) { - return new PayFlexV4PosRequestDataMapper($eventDispatcher, $crypt, $currencies); - } - throw new DomainException('unsupported gateway'); } } diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php index cf22531a..65302c3f 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php @@ -82,18 +82,6 @@ public function testFormatAmount(): void $this->assertSame('1000.00', $method->invokeArgs($this->requestDataMapper, [1000])); } - /** - * @testWith ["MONTH", "Month"] - * ["Month", "Month"] - */ - public function testMapRecurringFrequency(string $frequency, string $expected): void - { - $class = new \ReflectionObject($this->requestDataMapper); - $method = $class->getMethod('mapRecurringFrequency'); - $method->setAccessible(true); - $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$frequency])); - } - /** * @return void */ From 9a3f8317744456a97da7bc987d83cb3b26782a50 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Wed, 2 Oct 2024 17:50:23 +0200 Subject: [PATCH 3/3] tests - use assetsSame instead of assertEquals --- tests/Unit/Crypt/EstPosCryptTest.php | 4 +- tests/Unit/Crypt/EstV3PosCryptTest.php | 4 +- tests/Unit/Crypt/GarantiPosCryptTest.php | 2 +- tests/Unit/Crypt/PosNetV1PosCryptTest.php | 2 +- tests/Unit/Crypt/ToslaPosCryptTest.php | 4 +- .../EstPosRequestDataMapperTest.php | 182 +++++-------- .../EstV3PosRequestDataMapperTest.php | 8 +- .../GarantiPosRequestDataMapperTest.php | 2 +- .../KuveytPosRequestDataMapperTest.php | 2 +- .../PayFlexV4PosRequestDataMapperTest.php | 10 +- .../PayForPosRequestDataMapperTest.php | 254 +++++++++--------- .../PosNetRequestDataMapperTest.php | 25 +- .../ToslaPosRequestDataMapperTest.php | 12 +- .../KuveytPosResponseDataMapperTest.php | 4 +- .../PayForPosResponseDataMapperTest.php | 1 - .../VakifKatilimPosResponseDataMapperTest.php | 4 +- tests/Unit/Gateways/ToslaPosTest.php | 6 +- .../Unit/Serializer/PosNetSerializerTest.php | 2 +- 18 files changed, 244 insertions(+), 284 deletions(-) diff --git a/tests/Unit/Crypt/EstPosCryptTest.php b/tests/Unit/Crypt/EstPosCryptTest.php index a7ead888..9f019d11 100644 --- a/tests/Unit/Crypt/EstPosCryptTest.php +++ b/tests/Unit/Crypt/EstPosCryptTest.php @@ -53,7 +53,7 @@ public function testCreate3DHash(): void $expected = 'S7UxUAohxaxzl35WxHyDfuQx0sg='; $actual = $this->crypt->create3DHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -73,7 +73,7 @@ public function testCreate3DHashFor3DPay(): void $expected = 'S7UxUAohxaxzl35WxHyDfuQx0sg='; $actual = $this->crypt->create3DHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** diff --git a/tests/Unit/Crypt/EstV3PosCryptTest.php b/tests/Unit/Crypt/EstV3PosCryptTest.php index 85b5da39..bcff0bfe 100644 --- a/tests/Unit/Crypt/EstV3PosCryptTest.php +++ b/tests/Unit/Crypt/EstV3PosCryptTest.php @@ -72,7 +72,7 @@ public function testCreate3DHashFor3DPay(): void ]; $actual = $this->crypt->create3DHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function testCreate3DHashFor3DSecure(): void @@ -95,7 +95,7 @@ public function testCreate3DHashFor3DSecure(): void $expected = '4aUsG5hqlIFLc9s8PKc5rWb2OLhmxDDewNgKa2XrwoYCIxlyVq8Fjl4IVaZzoqL983CfTseicmnTA0PjZr74xg=='; $actual = $this->crypt->create3DHash($this->account, $inputs); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function threeDHashCheckDataProvider(): array diff --git a/tests/Unit/Crypt/GarantiPosCryptTest.php b/tests/Unit/Crypt/GarantiPosCryptTest.php index 4d4e3b93..32815f0b 100644 --- a/tests/Unit/Crypt/GarantiPosCryptTest.php +++ b/tests/Unit/Crypt/GarantiPosCryptTest.php @@ -80,7 +80,7 @@ public function testCreate3DHash(): void public function testCreateHash(array $requestData, string $expected): void { $actual = $this->crypt->createHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function threeDHashCheckDataProvider(): array diff --git a/tests/Unit/Crypt/PosNetV1PosCryptTest.php b/tests/Unit/Crypt/PosNetV1PosCryptTest.php index 51b761c5..222121e7 100644 --- a/tests/Unit/Crypt/PosNetV1PosCryptTest.php +++ b/tests/Unit/Crypt/PosNetV1PosCryptTest.php @@ -63,7 +63,7 @@ public function testHashFromParamsWhenNotFound(): void public function testCreateHash(array $requestData, string $expected): void { $actual = $this->crypt->createHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } diff --git a/tests/Unit/Crypt/ToslaPosCryptTest.php b/tests/Unit/Crypt/ToslaPosCryptTest.php index a4938564..e41f8741 100644 --- a/tests/Unit/Crypt/ToslaPosCryptTest.php +++ b/tests/Unit/Crypt/ToslaPosCryptTest.php @@ -45,7 +45,7 @@ public function testCreate3DHash(): void $expected = 'BwZ05tt0aNgIgtrrqmlTwSIaeetpQyyGLH6xTsQbHae7ANCIVKmLHPxYWk5XP3Li5fr4La1bZS9/43OihP0dig=='; $actual = $this->crypt->create3DHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function testCreateHash(): void @@ -57,7 +57,7 @@ public function testCreateHash(): void $expected = 'BwZ05tt0aNgIgtrrqmlTwSIaeetpQyyGLH6xTsQbHae7ANCIVKmLHPxYWk5XP3Li5fr4La1bZS9/43OihP0dig=='; $actual = $this->crypt->createHash($this->account, $requestData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** diff --git a/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php index 8dcbea4a..72343c90 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php @@ -145,7 +145,7 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra { $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -164,34 +164,13 @@ public function testCreateNonSecurePaymentRequestData(array $order, CreditCardIn } /** - * @return void - */ - public function testCreateCancelRequestData(): void - { - $order = [ - 'id' => '2020110828BC', - ]; - - $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - - $expectedData = $this->getSampleCancelXMLData($this->account, $order); - $this->assertEquals($expectedData, $actual); - } - - /** - * @return void + * @dataProvider createCancelRequestDataProvider */ - public function testCreateCancelRecurringOrderRequestData(): void + public function testCreateCancelRequestData(array $order, array $expected): void { - $order = [ - 'id' => '2020110828BC', - 'recurringOrderInstallmentNumber' => '2', - ]; - $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $expectedData = $this->getSampleRecurringOrderCancelXMLData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expected, $actual); } /** @@ -200,7 +179,7 @@ public function testCreateCancelRecurringOrderRequestData(): void public function testCreateOrderHistoryRequestData(array $order, array $expected): void { $actual = $this->requestDataMapper->createOrderHistoryRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function testCreateHistoryRequestData(): void @@ -215,7 +194,7 @@ public function testCreateHistoryRequestData(): void public function testCreate3DPaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, array $responseData, array $expected): void { $actual = $this->requestDataMapper->create3DPaymentRequestData($posAccount, $order, $txType, $responseData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -255,37 +234,17 @@ public function testGet3DFormData( $isWithCard ? $this->card : null ); - $this->assertEquals($expected, $actual); - } - - /** - * @return void - */ - public function testCreateStatusRequestData(): void - { - $order = [ - 'id' => '2020110828BC', - ]; - - $actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order); - - $expectedData = $this->getSampleStatusRequestData($this->account, $order); - $this->assertEquals($expectedData, $actualData); + $this->assertSame($expected, $actual); } /** - * @return void + * @dataProvider statusRequestDataProvider */ - public function testCreateRecurringStatusRequestData(): void + public function testCreateStatusRequestData(array $order, array $expected): void { - $order = [ - 'recurringId' => '2020110828BC', - ]; - $actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $expectedData = $this->getSampleRecurringStatusRequestData($this->account, $order); - $this->assertEquals($expectedData, $actualData); + $this->assertSame($expected, $actualData); } /** @@ -424,8 +383,8 @@ public static function threeDFormDataProvider(): array 'lang' => 'tr', 'currency' => '949', 'taksit' => '', - 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', 'islemtipi' => 'Auth', + 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', ], ], ], @@ -450,11 +409,11 @@ public static function threeDFormDataProvider(): array 'currency' => '949', 'taksit' => '', 'islemtipi' => 'Auth', - 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', 'pan' => '5555444433332222', 'Ecom_Payment_Card_ExpDate_Month' => '01', 'Ecom_Payment_Card_ExpDate_Year' => '22', 'cv2' => '123', + 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', ], ], ], @@ -597,39 +556,36 @@ public static function refundRequestDataProvider(): array ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleCancelXMLData(AbstractPosAccount $posAccount, array $order): array + public static function createCancelRequestDataProvider(): array { return [ - 'Name' => $posAccount->getUsername(), - 'Password' => $posAccount->getPassword(), - 'ClientId' => $posAccount->getClientId(), - 'OrderId' => $order['id'], - 'Type' => 'Void', - ]; - } - - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleRecurringOrderCancelXMLData(AbstractPosAccount $posAccount, array $order): array - { - return [ - 'Name' => $posAccount->getUsername(), - 'Password' => $posAccount->getPassword(), - 'ClientId' => $posAccount->getClientId(), - 'Extra' => [ - 'RECORDTYPE' => 'Order', - 'RECURRINGOPERATION' => 'Cancel', - 'RECORDID' => $order['id'].'-'.$order['recurringOrderInstallmentNumber'], + [ + 'order' => [ + 'id' => '2020110828BC', + ], + 'expected' => [ + 'Name' => 'ISBANKAPI', + 'Password' => 'ISBANK07', + 'ClientId' => '700655000200', + 'OrderId' => '2020110828BC', + 'Type' => 'Void', + ], + ], + [ + 'order' => [ + 'id' => '2020110828BC', + 'recurringOrderInstallmentNumber' => '2', + ], + 'expected' => [ + 'Name' => 'ISBANKAPI', + 'Password' => 'ISBANK07', + 'ClientId' => '700655000200', + 'Extra' => [ + 'RECORDTYPE' => 'Order', + 'RECURRINGOPERATION' => 'Cancel', + 'RECORDID' => '2020110828BC-2', + ], + ], ], ]; } @@ -707,40 +663,36 @@ public static function nonSecurePaymentRequestDataDataProvider(): array ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleStatusRequestData(AbstractPosAccount $posAccount, array $order): array + public static function statusRequestDataProvider(): array { return [ - 'Name' => $posAccount->getUsername(), - 'Password' => $posAccount->getPassword(), - 'ClientId' => $posAccount->getClientId(), - 'OrderId' => $order['id'], - 'Extra' => [ - 'ORDERSTATUS' => 'QUERY', + [ + 'order' => [ + 'id' => '2020110828BC', + ], + 'expected' => [ + 'Name' => 'ISBANKAPI', + 'Password' => 'ISBANK07', + 'ClientId' => '700655000200', + 'Extra' => [ + 'ORDERSTATUS' => 'QUERY', + ], + 'OrderId' => '2020110828BC', + ], ], - ]; - } - - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleRecurringStatusRequestData(AbstractPosAccount $posAccount, array $order): array - { - return [ - 'Name' => $posAccount->getUsername(), - 'Password' => $posAccount->getPassword(), - 'ClientId' => $posAccount->getClientId(), - 'Extra' => [ - 'ORDERSTATUS' => 'QUERY', - 'RECURRINGID' => $order['recurringId'], + [ + 'order' => [ + 'recurringId' => '22303O8EA19252', + ], + 'expected' => [ + 'Name' => 'ISBANKAPI', + 'Password' => 'ISBANK07', + 'ClientId' => '700655000200', + 'Extra' => [ + 'ORDERSTATUS' => 'QUERY', + 'RECURRINGID' => '22303O8EA19252', + ], + ], ], ]; } diff --git a/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php index 5e6367f7..7aa128e2 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php @@ -92,7 +92,7 @@ public function testGet3DFormData( $isWithCard ? $this->card : null ); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public static function threeDFormDataProvider(): array @@ -155,13 +155,13 @@ public static function threeDFormDataProvider(): array 'lang' => 'tr', 'currency' => '949', 'taksit' => '', - 'TranType' => 'Auth', - 'hashAlgorithm' => 'ver3', - 'hash' => '3fvBzh0HT3UiKUTXis0Ke2NG3mAp9eBOwx26bstv+l6L946GrOF2JklXfqTNc6VBeqUSkuLxo4ErtwCWuPCzYw==', 'pan' => '5555444433332222', 'Ecom_Payment_Card_ExpDate_Month' => '01', 'Ecom_Payment_Card_ExpDate_Year' => '22', 'cv2' => '123', + 'TranType' => 'Auth', + 'hashAlgorithm' => 'ver3', + 'hash' => '3fvBzh0HT3UiKUTXis0Ke2NG3mAp9eBOwx26bstv+l6L946GrOF2JklXfqTNc6VBeqUSkuLxo4ErtwCWuPCzYw==', ], ], ], diff --git a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php index 5a583109..40eea299 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php @@ -237,7 +237,7 @@ public function testCreate3DPaymentRequestData(GarantiPosAccount $garantiPosAcco $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, '', $responseData); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** diff --git a/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php index d5e7da15..000b1dca 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php @@ -178,7 +178,7 @@ public function testCreateCancelRequestData(array $order, array $expected): void \ksort($actual); \ksort($expected); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php index df96798a..d6248ae3 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php @@ -131,7 +131,7 @@ public function testMapInstallment($installment, $expected): void public function testCreate3DPaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, array $gatewayResponse, CreditCardInterface $creditCard, array $expected): void { $actual = $this->requestDataMapper->create3DPaymentRequestData($posAccount, $order, $txType, $gatewayResponse, $creditCard); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -153,7 +153,7 @@ public function testCreate3DEnrollmentCheckData(array $order, ?CreditCardInterfa ->willReturn($expected['VerifyEnrollmentRequestId']); $actual = $this->requestDataMapper->create3DEnrollmentCheckRequestData($this->account, $order, $creditCard); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } @@ -464,11 +464,11 @@ public static function three3DEnrollmentRequestDataDataProvider(): \Generator 'Currency' => '949', 'SuccessUrl' => 'https://domain.com/success', 'FailureUrl' => 'https://domain.com/fail_url', - 'IsRecurring' => 'false', - 'InstallmentCount' => '2', 'Pan' => '5555444433332222', 'ExpiryDate' => '2112', 'BrandName' => '100', + 'IsRecurring' => 'false', + 'InstallmentCount' => '2', ], ]; @@ -492,10 +492,10 @@ public static function three3DEnrollmentRequestDataDataProvider(): \Generator 'Currency' => '949', 'SuccessUrl' => 'https://domain.com/success', 'FailureUrl' => 'https://domain.com/fail_url', - 'IsRecurring' => 'true', 'Pan' => '5555444433332222', 'ExpiryDate' => '2112', 'BrandName' => '100', + 'IsRecurring' => 'true', 'RecurringFrequency' => '3', 'RecurringFrequencyType' => 'Month', 'RecurringInstallmentCount' => '2', diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php index c7c32c05..f6c7407d 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php @@ -120,49 +120,38 @@ public function testMapInstallment($installment, $expected): void } /** - * @return void + * @dataProvider createNonSecurePostAuthPaymentRequestDataDataProvider */ - public function testCreateNonSecurePostAuthPaymentRequestData(): void + public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expected): void { - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => PosInterface::CURRENCY_TRY, - 'lang' => PosInterface::LANG_TR, - ]; - $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $expectedData = $this->getSampleNonSecurePaymentPostRequestData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expected, $actual); } /** - * @return void + * @dataProvider nonSecurePaymentRequestDataProvider */ - public function testCreateNonSecurePaymentRequestData(): void + public function testCreateNonSecurePaymentRequestData(array $order, string $txType, array $expected): void { - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $this->order, PosInterface::TX_TYPE_PAY_AUTH, $this->card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData( + $this->account, + $order, + $txType, + $this->card + ); - $expectedData = $this->getSampleNonSecurePaymentRequestData($this->account, $this->order, $this->card); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expected, $actual); } /** - * @return void + * @dataProvider createCancelRequestDataDataProvider */ - public function testCreateCancelRequestData(): void + public function testCreateCancelRequestData(array $order, array $expected): void { - $order = [ - 'id' => '2020110828BC', - 'currency' => PosInterface::CURRENCY_TRY, - ]; - $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $expectedData = $this->getSampleCancelXMLData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expected, $actual); } /** @@ -191,19 +180,13 @@ public function testCreateHistoryRequestData(array $data, array $expectedData): } /** - * @return void + * @dataProvider create3DPaymentRequestDataDataProvider */ - public function testCreate3DPaymentRequestData(): void + public function testCreate3DPaymentRequestData(array $order, array $responseData, array $expected): void { - $order = [ - 'id' => '2020110828BC', - ]; - $responseData = ['RequestGuid' => '1000000057437884']; - $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, '', $responseData); - $expectedData = $this->getSample3DPaymentRequestData($this->account, $order, $responseData); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expected, $actual); } /** @@ -245,22 +228,17 @@ public function testGet3DFormData( $card ); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** - * @return void + * @dataProvider createStatusRequestDataDataProvider */ - public function testCreateStatusRequestData(): void + public function testCreateStatusRequestData(array $order, array $expected): void { - $order = [ - 'id' => '2020110828BC', - ]; - $actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $expectedData = $this->getSampleStatusRequestData($this->account, $order); - $this->assertEquals($expectedData, $actualData); + $this->assertSame($expected, $actualData); } /** @@ -275,113 +253,129 @@ public function testCreateRefundRequestData(array $order, string $txType, array $this->assertSame($expectedData, $actual); } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * @param array $responseData - * - * @return array - */ - private function getSample3DPaymentRequestData(AbstractPosAccount $posAccount, array $order, array $responseData): array + public static function create3DPaymentRequestDataDataProvider(): array { return [ - 'RequestGuid' => $responseData['RequestGuid'], - 'UserCode' => $posAccount->getUsername(), - 'UserPass' => $posAccount->getPassword(), - 'OrderId' => $order['id'], - 'SecureType' => '3DModelPayment', + [ + 'order' => [ + 'id' => '2020110828BC', + + ], + 'response_data' => [ + 'RequestGuid' => '1000000057437884', + ], + 'expected' => [ + 'RequestGuid' => '1000000057437884', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + 'OrderId' => '2020110828BC', + 'SecureType' => '3DModelPayment', + ], + ], ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleCancelXMLData(AbstractPosAccount $posAccount, array $order): array + public static function createCancelRequestDataDataProvider(): array { return [ - 'MbrId' => '5', - 'MerchantId' => $posAccount->getClientId(), - 'UserCode' => $posAccount->getUsername(), - 'UserPass' => $posAccount->getPassword(), - 'OrgOrderId' => $order['id'], - 'SecureType' => 'NonSecure', - 'Lang' => 'tr', - 'TxnType' => 'Void', - 'Currency' => 949, + [ + 'order' => [ + 'id' => '2020110828BC', + 'currency' => PosInterface::CURRENCY_TRY, + ], + 'expected' => [ + 'MerchantId' => '085300000009704', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + 'MbrId' => '5', + 'OrgOrderId' => '2020110828BC', + 'SecureType' => 'NonSecure', + 'TxnType' => 'Void', + 'Currency' => '949', + 'Lang' => 'tr', + ], + ], ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * @param CreditCardInterface $creditCard - * - * @return array - */ - private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $posAccount, array $order, CreditCardInterface $creditCard): array + public static function nonSecurePaymentRequestDataProvider(): array { return [ - 'MbrId' => '5', - 'MerchantId' => $posAccount->getClientId(), - 'UserCode' => $posAccount->getUsername(), - 'UserPass' => $posAccount->getPassword(), - 'MOTO' => '0', - 'OrderId' => $order['id'], - 'SecureType' => 'NonSecure', - 'TxnType' => 'Auth', - 'PurchAmount' => $order['amount'], - 'Currency' => 949, - 'InstallmentCount' => 0, - 'Lang' => 'tr', - 'CardHolderName' => $creditCard->getHolderName(), - 'Pan' => $creditCard->getNumber(), - 'Expiry' => '0122', - 'Cvv2' => $creditCard->getCvv(), + [ + 'order' => [ + 'id' => '2020110828BC', + 'amount' => 100.01, + ], + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'expected' => [ + 'MerchantId' => '085300000009704', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + 'MbrId' => '5', + 'MOTO' => '0', + 'OrderId' => '2020110828BC', + 'SecureType' => 'NonSecure', + 'TxnType' => 'Auth', + 'PurchAmount' => '100.01', + 'Currency' => '949', + 'InstallmentCount' => '0', + 'Lang' => 'tr', + 'CardHolderName' => 'ahmet', + 'Pan' => '5555444433332222', + 'Expiry' => '0122', + 'Cvv2' => '123', + ], + ], ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $posAccount, array $order): array + public static function createNonSecurePostAuthPaymentRequestDataDataProvider(): array { return [ - 'MbrId' => '5', - 'MerchantId' => $posAccount->getClientId(), - 'UserCode' => $posAccount->getUsername(), - 'UserPass' => $posAccount->getPassword(), - 'OrgOrderId' => $order['id'], - 'SecureType' => 'NonSecure', - 'TxnType' => 'PostAuth', - 'PurchAmount' => $order['amount'], - 'Currency' => 949, - 'Lang' => 'tr', + [ + 'order' => [ + 'id' => '2020110828BC', + 'amount' => 100.01, + 'installment' => 0, + 'currency' => PosInterface::CURRENCY_TRY, + 'lang' => PosInterface::LANG_TR, + ], + 'expected' => [ + 'MerchantId' => '085300000009704', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + 'MbrId' => '5', + 'OrgOrderId' => '2020110828BC', + 'SecureType' => 'NonSecure', + 'TxnType' => 'PostAuth', + 'PurchAmount' => '100.01', + 'Currency' => '949', + 'Lang' => 'tr', + ], + ], ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleStatusRequestData(AbstractPosAccount $posAccount, array $order): array + + public static function createStatusRequestDataDataProvider(): array { return [ - 'MbrId' => '5', - 'MerchantId' => $posAccount->getClientId(), - 'UserCode' => $posAccount->getUsername(), - 'UserPass' => $posAccount->getPassword(), - 'OrgOrderId' => $order['id'], - 'SecureType' => 'Inquiry', - 'Lang' => 'tr', - 'TxnType' => 'OrderInquiry', + [ + 'order' => [ + 'id' => '2020110828BC', + ], + 'expected' => [ + 'MerchantId' => '085300000009704', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + 'MbrId' => '5', + 'OrgOrderId' => '2020110828BC', + 'SecureType' => 'Inquiry', + 'Lang' => 'tr', + 'TxnType' => 'OrderInquiry', + ], + ], + ]; } @@ -490,11 +484,11 @@ public static function threeDFormDataProvider(): array 'OkUrl' => 'http://localhost/finansbank-payfor/3d/success.php', 'FailUrl' => 'http://localhost/finansbank-payfor/3d/fail.php', 'Rnd' => '1deda47050cd38112cbf91f4', - 'Hash' => 'BSj3xu8dYQbdw5YM4JvTS+vmyUI=', 'CardHolderName' => 'ahmet', 'Pan' => '5555444433332222', 'Expiry' => '0122', 'Cvv2' => '123', + 'Hash' => 'BSj3xu8dYQbdw5YM4JvTS+vmyUI=', ], ], ], diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php index ebfe9653..6aa18ec8 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php @@ -166,7 +166,7 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra { $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -176,7 +176,7 @@ public function testCreateNonSecurePaymentRequestData(array $order, string $txTy { $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, $txType, $this->card); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -186,7 +186,7 @@ public function testCreateCancelRequestData(array $order, array $expectedData): { $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -210,7 +210,7 @@ public function testCreate3DPaymentRequestData(array $order, array $mappedOrder, public function testCreate3DEnrollmentCheckRequestData(array $order, string $txType, array $expectedData): void { $actual = $this->requestDataMapper->create3DEnrollmentCheckRequestData($this->account, $order, $txType, $this->card); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } @@ -285,7 +285,7 @@ public function testCreateStatusRequestData(array $order, array $expectedData): { $actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $this->assertEquals($expectedData, $actualData); + $this->assertSame($expectedData, $actualData); } /** @@ -462,7 +462,7 @@ public static function nonSecurePaymentRequestDataProvider(): array 'tranDateRequired' => '1', 'sale' => [ 'orderID' => 'TST_190620093100_024', - 'installment' => 0, + 'installment' => '00', 'amount' => 175, 'currencyCode' => 'TL', 'ccno' => '5555444433332222', @@ -516,6 +516,19 @@ public static function statusRequestDataProvider(): array ], ], ], + [ + 'order' => [ + 'id' => '2020110828BC', + 'payment_model' => PosInterface::MODEL_NON_SECURE, + ], + 'expected' => [ + 'mid' => '6706598320', + 'tid' => '67005551', + 'agreement' => [ + 'orderID' => '0000000000002020110828BC', + ], + ], + ], ]; } diff --git a/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php index f39e28da..2556f59f 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php @@ -117,7 +117,7 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra ->willReturn($expected['hash']); $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -133,7 +133,7 @@ public function testCreate3DEnrollmentCheckRequestData(array $order, string $pay ->willReturn($expected['hash']); $actual = $this->requestDataMapper->create3DEnrollmentCheckRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -149,7 +149,7 @@ public function testCreateNonSecurePaymentRequestData(array $order, string $txTy ->willReturn($expected['hash']); $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, $txType, $this->card); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -166,7 +166,7 @@ public function testCreateCancelRequestData(array $order, array $expected): void $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } /** @@ -183,7 +183,7 @@ public function testCreateOrderHistoryRequestData(array $order, array $expected) $actual = $this->requestDataMapper->createOrderHistoryRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } @@ -229,7 +229,7 @@ public function testCreateStatusRequestData(array $order, array $expected): void $actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $this->assertEquals($expected, $actualData); + $this->assertSame($expected, $actualData); } /** diff --git a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php index 31480e48..8348bfea 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php @@ -180,7 +180,9 @@ public function testMap3DPaymentData(array $order, string $txType, array $threeD unset($actualData['transaction_time'], $expectedData['transaction_time']); unset($actualData['all'], $actualData['3d_all']); - $this->assertEquals($expectedData, $actualData); + \ksort($actualData); + \ksort($expectedData); + $this->assertSame($expectedData, $actualData); } public function testMap3DPayResponseData(): void diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php index 97559120..000e5383 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php @@ -6,7 +6,6 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; use Mews\Pos\Crypt\CryptInterface; -use Mews\Pos\Crypt\PayForPosCrypt; use Mews\Pos\DataMapper\RequestDataMapper\PayForPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayForPosResponseDataMapper; use Mews\Pos\PosInterface; diff --git a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php index 93c4a6d3..7b8f7e7e 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php @@ -118,7 +118,9 @@ public function testMap3DPaymentData(array $order, string $txType, array $threeD unset($actualData['transaction_time'], $expectedData['transaction_time']); unset($actualData['all'], $actualData['3d_all']); - $this->assertEquals($expectedData, $actualData); + ksort($expectedData); + ksort($actualData); + $this->assertSame($expectedData, $actualData); } /** diff --git a/tests/Unit/Gateways/ToslaPosTest.php b/tests/Unit/Gateways/ToslaPosTest.php index acb3aa5c..3a86ad52 100644 --- a/tests/Unit/Gateways/ToslaPosTest.php +++ b/tests/Unit/Gateways/ToslaPosTest.php @@ -119,8 +119,8 @@ protected function setUp(): void public function testInit(): void { - $this->assertEquals($this->config, $this->pos->getConfig()); - $this->assertEquals($this->account, $this->pos->getAccount()); + $this->assertSame($this->config, $this->pos->getConfig()); + $this->assertSame($this->account, $this->pos->getAccount()); } /** @@ -360,8 +360,6 @@ public function testGet3DFormDataWithoutCard(): void } /** - * @return void - * * @dataProvider registerFailResponseDataProvider */ public function testGet3DFormDataRegisterPaymentFail(array $response): void diff --git a/tests/Unit/Serializer/PosNetSerializerTest.php b/tests/Unit/Serializer/PosNetSerializerTest.php index 811324c2..30442bc6 100644 --- a/tests/Unit/Serializer/PosNetSerializerTest.php +++ b/tests/Unit/Serializer/PosNetSerializerTest.php @@ -39,7 +39,7 @@ public function testEncode(array $data, string $expected): void $result = $this->serializer->encode($data); $expected = str_replace(["\r"], '', $expected); - $this->assertEquals($expected, $result); + $this->assertSame($expected, $result); } /**