From 2cd6f90eacf87f768ae9c82d9af2a6f2a3f5b9f5 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Mon, 12 Aug 2024 13:49:42 +0200 Subject: [PATCH 1/8] fix issue #229 payflexv4pos status request undefined index CurrencyAmount --- config/pos_production.php | 2 +- .../ResponseDataMapper/PayFlexV4PosResponseDataMapper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/pos_production.php b/config/pos_production.php index 76ff7c0d..5a428e4a 100644 --- a/config/pos_production.php +++ b/config/pos_production.php @@ -119,7 +119,7 @@ 'gateway_endpoints' => [ 'payment_api' => 'https://onlineodeme.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx', 'gateway_3d' => 'https://3dsecure.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspx', - 'query_api' => 'https://sanalpos.vakifbank.com.tr/v4/UIWebService/Search.aspx', + 'query_api' => 'https://onlineodeme.vakifbank.com.tr:4443/UIService/Search.aspx', ], ], 'ziraat-vpos' => [ diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php index 90c48f5d..693e35dc 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php @@ -185,7 +185,7 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['order_status'] = $orderStatus; $defaultResponse['transaction_type'] = $this->mapTxType($txResultInfo['TransactionType']); $defaultResponse['currency'] = $this->mapCurrency($txResultInfo['AmountCode']); - $defaultResponse['first_amount'] = $this->formatAmount($txResultInfo['CurrencyAmount']); + $defaultResponse['first_amount'] = $this->formatAmount($txResultInfo['CurrencyAmount'] ?? $txResultInfo['Amount']); $defaultResponse['capture_amount'] = null; $defaultResponse['status'] = self::PROCEDURE_SUCCESS_CODE === $orderProcCode ? self::TX_APPROVED : self::TX_DECLINED; $defaultResponse['error_code'] = self::PROCEDURE_SUCCESS_CODE !== $orderProcCode ? $txResultInfo['HostResultCode'] : null; From bd10da28784e056a21a4b27ee927b981d973948e Mon Sep 17 00:00:00 2001 From: mustapayev Date: Mon, 12 Aug 2024 13:56:53 +0200 Subject: [PATCH 2/8] fix issue #230 payflexv4pos payment hostdate format error --- .../PayFlexV4PosResponseDataMapper.php | 6 ++- .../PayFlexV4PosResponseDataMapperTest.php | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php index 693e35dc..5a3503ca 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php @@ -209,7 +209,11 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType if (self::TX_APPROVED === $commonResponse['status']) { $commonResponse['transaction_id'] = $rawPaymentResponseData['TransactionId']; - $commonResponse['transaction_time'] = new \DateTimeImmutable($rawPaymentResponseData['HostDate']); + $txTime = $rawPaymentResponseData['HostDate']; + if (\strlen($txTime) === 10) { // ziraat is sending host date without year + $txTime = date('Y').$txTime; + } + $commonResponse['transaction_time'] = new \DateTimeImmutable($txTime); $commonResponse['auth_code'] = $rawPaymentResponseData['AuthCode']; $commonResponse['ref_ret_num'] = $rawPaymentResponseData['TransactionId']; $commonResponse['batch_num'] = $rawPaymentResponseData['BatchNo']; diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php index 1b1f35c5..4e5e8f2b 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php @@ -401,6 +401,57 @@ public static function paymentDataProvider(): iterable ], ]; + yield 'success_with_short_host_date' => [ + 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, + 'responseData' => [ + 'MerchantId' => '000100000013506', + 'TransactionType' => 'Sale', + 'TransactionId' => '9972767117b3400eb2acafc0018643df', + 'ResultCode' => '0000', + 'ResultDetail' => 'İŞLEM BAŞARILI', + 'CustomItems' => [ + 'Item' => [ + '@name' => 'CardHolderName', + '@value' => 'AR* ÖZ*', + '#' => null, + ], + ], + 'InstallmentTable' => null, + 'CampaignResult' => null, + 'AuthCode' => '961451', + 'HostDate' => '0309234054', + 'Rrn' => '306823971358', + 'TerminalNo' => 'VP000579', + 'GainedPoint' => '10.00', + 'TotalPoint' => '103032.52', + 'CurrencyAmount' => '1.01', + 'CurrencyCode' => '949', + 'OrderId' => '202303095646', + 'ThreeDSecureType' => '1', + 'TransactionDeviceSource' => '0', + 'BatchNo' => '300', + 'TLAmount' => '1.01', + ], + 'expectedData' => [ + 'transaction_id' => '9972767117b3400eb2acafc0018643df', + 'transaction_type' => 'pay', + 'transaction_time' => new \DateTimeImmutable('2024-03-09 23:40:54'), + 'auth_code' => '961451', + 'ref_ret_num' => '9972767117b3400eb2acafc0018643df', + 'batch_num' => '300', + 'order_id' => '202303095646', + 'proc_return_code' => '0000', + 'status' => 'approved', + 'status_detail' => 'approved', + 'error_code' => null, + 'error_message' => null, + 'currency' => 'TRY', + 'amount' => 1.01, + 'payment_model' => 'regular', + 'installment_count' => null, + ], + ]; + yield 'fail_1' => [ 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, 'responseData' => [ From c90143faf20ddd984d19407d3847cb8512f6b913 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Mon, 12 Aug 2024 14:09:44 +0200 Subject: [PATCH 3/8] fix issue #230 payflexv4pos host date format error --- .../ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php index 4e5e8f2b..d20782d4 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php @@ -435,7 +435,7 @@ public static function paymentDataProvider(): iterable 'expectedData' => [ 'transaction_id' => '9972767117b3400eb2acafc0018643df', 'transaction_type' => 'pay', - 'transaction_time' => new \DateTimeImmutable('2024-03-09 23:40:54'), + 'transaction_time' => new \DateTimeImmutable(date('Y').'-03-09 23:40:54'), 'auth_code' => '961451', 'ref_ret_num' => '9972767117b3400eb2acafc0018643df', 'batch_num' => '300', From d936c4e8ac923d2f29616c3c6164a3f6ce9f2fab Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 17 Aug 2024 10:07:52 +0200 Subject: [PATCH 4/8] tests - more test coverage --- tests/Unit/Crypt/AkbankPosCryptTest.php | 1 + tests/Unit/Crypt/InterPosCryptTest.php | 22 ++ tests/Unit/Crypt/PosNetV1PosCryptTest.php | 12 + .../InterPosRequestDataMapperTest.php | 333 +++++++++--------- .../InterPosResponseDataMapperTest.php | 138 +++++--- 5 files changed, 283 insertions(+), 223 deletions(-) diff --git a/tests/Unit/Crypt/AkbankPosCryptTest.php b/tests/Unit/Crypt/AkbankPosCryptTest.php index 6ce0e6c4..11347c8a 100644 --- a/tests/Unit/Crypt/AkbankPosCryptTest.php +++ b/tests/Unit/Crypt/AkbankPosCryptTest.php @@ -17,6 +17,7 @@ /** * @covers \Mews\Pos\Crypt\AkbankPosCrypt + * @covers \Mews\Pos\Crypt\AbstractCrypt */ class AkbankPosCryptTest extends TestCase { diff --git a/tests/Unit/Crypt/InterPosCryptTest.php b/tests/Unit/Crypt/InterPosCryptTest.php index 6367a962..dda54c6b 100644 --- a/tests/Unit/Crypt/InterPosCryptTest.php +++ b/tests/Unit/Crypt/InterPosCryptTest.php @@ -6,7 +6,9 @@ namespace Mews\Pos\Tests\Unit\Crypt; use Mews\Pos\Crypt\InterPosCrypt; +use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\InterPosAccount; +use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\PosInterface; use PHPUnit\Framework\TestCase; @@ -14,6 +16,7 @@ /** * @covers \Mews\Pos\Crypt\InterPosCrypt + * @covers \Mews\Pos\Crypt\AbstractCrypt */ class InterPosCryptTest extends TestCase { @@ -48,6 +51,9 @@ protected function setUp(): void public function testCheck3DHash(array $responseData): void { $this->assertTrue($this->crypt->check3DHash($this->account, $responseData)); + + $responseData['PurchAmount'] = ''; + $this->assertFalse($this->crypt->check3DHash($this->account, $responseData)); } /** @@ -60,6 +66,22 @@ public function testCreate3DHash(array $requestData, string $expected): void $this->assertSame($expected, $actual); } + public function testCreateHash(): void + { + $this->expectException(NotImplementedException::class); + $this->crypt->createHash($this->account, []); + } + + /** + * @dataProvider threeDHashCheckDataProvider + */ + public function testCheck3DHashException(): void + { + $account = $this->createMock(AbstractPosAccount::class); + $this->expectException(\LogicException::class); + $this->crypt->check3DHash($account, []); + } + public function threeDHashCheckDataProvider(): array { return [ diff --git a/tests/Unit/Crypt/PosNetV1PosCryptTest.php b/tests/Unit/Crypt/PosNetV1PosCryptTest.php index cf935c03..474ee33c 100644 --- a/tests/Unit/Crypt/PosNetV1PosCryptTest.php +++ b/tests/Unit/Crypt/PosNetV1PosCryptTest.php @@ -13,6 +13,7 @@ /** * @covers \Mews\Pos\Crypt\PosNetV1PosCrypt + * @covers \Mews\Pos\Crypt\AbstractCrypt */ class PosNetV1PosCryptTest extends TestCase { @@ -44,6 +45,17 @@ public function testHashFromParams(string $storeKey, array $data, string $expect $this->assertSame($expected, $this->crypt->hashFromParams($storeKey, $data, 'MACParams', ':')); } + public function testHashFromParamsWhenNotFound(): void + { + $data = self::hashFromParamsDataProvider()[0]; + $this->assertSame('', $this->crypt->hashFromParams( + $data['storeKey'], + $data, + 'NonExistingField', + ':' + )); + } + /** * @dataProvider hashCreateDataProvider */ diff --git a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php index e26d72a2..d6529a59 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php @@ -21,6 +21,7 @@ /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper + * @covers \Mews\Pos\DataMapper\RequestDataMapper\AbstractRequestDataMapper */ class InterPosRequestDataMapperTest extends TestCase { @@ -36,8 +37,6 @@ class InterPosRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; - private array $order; - protected function setUp(): void { parent::setUp(); @@ -56,18 +55,7 @@ protected function setUp(): void $merchantPass ); - $this->order = [ - 'id' => 'order222', - 'amount' => '100.25', - 'installment' => 0, - 'currency' => PosInterface::CURRENCY_TRY, - 'success_url' => 'https://domain.com/success', - 'fail_url' => 'https://domain.com/fail_url', - 'lang' => PosInterface::LANG_TR, - ]; - - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); $this->crypt = $this->createMock(CryptInterface::class); $this->requestDataMapper = new InterPosRequestDataMapper($this->dispatcher, $this->crypt); @@ -125,74 +113,53 @@ public function testMapInstallment($installment, $expected): void } /** - * @return void + * @dataProvider nonSecurePaymentPostRequestDataDataProvider */ - public function testCreateNonSecurePostAuthPaymentRequestData(): void + public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'amount' => 320, - 'currency' => PosInterface::CURRENCY_TRY, - ]; - $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $expectedData = $this->getSampleNonSecurePaymentPostRequestData($order, $this->account); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** - * @return void + * @dataProvider createNonSecurePaymentRequestDataDataProvider */ - public function testCreateNonSecurePaymentRequestData(): void + public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $card, 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, + PosInterface::TX_TYPE_PAY_AUTH, + $card + ); - $expectedData = $this->getSampleNonSecurePaymentRequestData($this->order, $this->card, $this->account); - $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', - 'lang' => PosInterface::LANG_EN, - ]; - $actual = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $expectedData = $this->getSampleCancelXMLData($order, $this->account); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expected, $actual); } /** - * @return void + * @dataProvider create3DPaymentRequestDataDataProvider */ - public function testCreate3DPaymentRequestData(): void + public function testCreate3DPaymentRequestData(array $order, array $responseData, array $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => 0, - 'currency' => PosInterface::CURRENCY_TRY, - 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'lang' => PosInterface::LANG_EN, - ]; - $responseData = [ - 'MD' => '1', - 'PayerTxnId' => '2', - 'Eci' => '3', - 'PayerAuthenticationCode' => '4', - ]; - - $actual = $this->requestDataMapper->create3DPaymentRequestData($this->account, $order, PosInterface::TX_TYPE_PAY_AUTH, $responseData); + $actual = $this->requestDataMapper->create3DPaymentRequestData( + $this->account, + $order, + PosInterface::TX_TYPE_PAY_AUTH, + $responseData + ); - $expectedData = $this->getSample3DPaymentRequestData($order, $this->account, $responseData); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -234,23 +201,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 $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'lang' => PosInterface::LANG_EN, - ]; - $actual = $this->requestDataMapper->createStatusRequestData($this->account, $order); - $expectedData = $this->getSampleStatusRequestData($order, $this->account); - $this->assertEquals($expectedData, $actual); + $this->assertSame($expectedData, $actual); } /** @@ -265,124 +226,162 @@ public function testCreateRefundRequestData(array $order, string $txType, array $this->assertSame($expectedData, $actual); } - /** - * @param array $order - * @param InterPosAccount $interPosAccount - * @param array $responseData - * - * @return array - */ - private function getSample3DPaymentRequestData(array $order, InterPosAccount $interPosAccount, array $responseData): array + public function testCreateOrderHistoryRequestData(): void { - return [ - 'UserCode' => $interPosAccount->getUsername(), - 'UserPass' => $interPosAccount->getPassword(), - 'ShopCode' => $interPosAccount->getClientId(), - 'TxnType' => 'Auth', - 'SecureType' => 'NonSecure', - 'OrderId' => $order['id'], - 'PurchAmount' => $order['amount'], - 'Currency' => '949', - 'InstallmentCount' => '', - 'MD' => $responseData['MD'], - 'PayerTxnId' => $responseData['PayerTxnId'], - 'Eci' => $responseData['Eci'], - 'PayerAuthenticationCode' => $responseData['PayerAuthenticationCode'], - 'MOTO' => '0', - 'Lang' => $order['lang'], - ]; + $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); + $this->requestDataMapper->createOrderHistoryRequestData($this->account, []); } - /** - * @param array $order - * @param InterPosAccount $interPosAccount - * - * @return array - */ - private function getSampleCancelXMLData(array $order, InterPosAccount $interPosAccount): array + public function testCreateHistoryRequestData(): void + { + $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); + $this->requestDataMapper->createHistoryRequestData($this->account, []); + } + + public static function create3DPaymentRequestDataDataProvider(): array { return [ - 'UserCode' => $interPosAccount->getUsername(), - 'UserPass' => $interPosAccount->getPassword(), - 'ShopCode' => $interPosAccount->getClientId(), - 'OrderId' => null, - 'orgOrderId' => $order['id'], - 'TxnType' => 'Void', - 'SecureType' => 'NonSecure', - 'Lang' => $order['lang'], + [ + 'order' => [ + 'id' => 'order222', + 'amount' => '100.25', + 'lang' => PosInterface::LANG_TR, + ], + 'responseData' => [ + 'MD' => '1', + 'PayerTxnId' => '2', + 'Eci' => '3', + 'PayerAuthenticationCode' => '4', + ], + 'expected' => [ + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'ShopCode' => '3123', + 'TxnType' => 'Auth', + 'SecureType' => 'NonSecure', + 'OrderId' => 'order222', + 'PurchAmount' => '100.25', + 'Currency' => '949', + 'InstallmentCount' => '', + 'MD' => '1', + 'PayerTxnId' => '2', + 'Eci' => '3', + 'PayerAuthenticationCode' => '4', + 'MOTO' => '0', + 'Lang' => PosInterface::LANG_TR, + ], + ], ]; } - /** - * @param array $order - * @param CreditCardInterface $creditCard - * @param InterPosAccount $interPosAccount - * - * @return array - */ - private function getSampleNonSecurePaymentRequestData(array $order, CreditCardInterface $creditCard, InterPosAccount $interPosAccount): array + public static function createCancelRequestDataDataProvider(): array { - $requestData = [ - 'UserCode' => $interPosAccount->getUsername(), - 'UserPass' => $interPosAccount->getPassword(), - 'ShopCode' => $interPosAccount->getClientId(), - 'TxnType' => 'Auth', - 'SecureType' => 'NonSecure', - 'OrderId' => $order['id'], - 'PurchAmount' => $order['amount'], - 'Currency' => '949', - 'InstallmentCount' => '', - 'MOTO' => '0', - 'Lang' => $order['lang'], + return [ + [ + 'order' => [ + 'id' => '2020110828BC', + 'lang' => PosInterface::LANG_EN, + ], + 'expected' => [ + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'ShopCode' => '3123', + 'OrderId' => null, + 'orgOrderId' => '2020110828BC', + 'TxnType' => 'Void', + 'SecureType' => 'NonSecure', + 'Lang' => PosInterface::LANG_EN, + ], + ], ]; + } - $requestData['CardType'] = '0'; - $requestData['Pan'] = $creditCard->getNumber(); - $requestData['Expiry'] = '1221'; - $requestData['Cvv2'] = $creditCard->getCvv(); - return $requestData; + public static function createNonSecurePaymentRequestDataDataProvider(): array + { + $card = CreditCardFactory::create( + '5555444433332222', + '21', + '12', + '122', + 'ahmet', + CreditCardInterface::CARD_TYPE_VISA + ); + + return [ + [ + 'order' => [ + 'id' => 'order222', + 'amount' => '100.25', + 'installment' => 0, + 'currency' => PosInterface::CURRENCY_TRY, + 'lang' => PosInterface::LANG_TR, + ], + 'card' => $card, + 'expected' => [ + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'ShopCode' => '3123', + 'TxnType' => 'Auth', + 'SecureType' => 'NonSecure', + 'OrderId' => 'order222', + 'PurchAmount' => '100.25', + 'Currency' => '949', + 'InstallmentCount' => '', + 'MOTO' => '0', + 'Lang' => PosInterface::LANG_TR, + 'CardType' => '0', + 'Pan' => $card->getNumber(), + 'Expiry' => '1221', + 'Cvv2' => $card->getCvv(), + ], + ], + ]; } - /** - * @param array $order - * @param InterPosAccount $interPosAccount - * - * @return array - */ - private function getSampleNonSecurePaymentPostRequestData(array $order, InterPosAccount $interPosAccount): array + public static function nonSecurePaymentPostRequestDataDataProvider(): array { return [ - 'UserCode' => $interPosAccount->getUsername(), - 'UserPass' => $interPosAccount->getPassword(), - 'ShopCode' => $interPosAccount->getClientId(), - 'TxnType' => 'PostAuth', - 'SecureType' => 'NonSecure', - 'OrderId' => null, - 'orgOrderId' => $order['id'], - 'PurchAmount' => $order['amount'], - 'Currency' => '949', - 'MOTO' => '0', + [ + 'order' => [ + 'id' => 'order222', + 'amount' => 10.0, + ], + 'expected' => [ + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'ShopCode' => '3123', + 'TxnType' => 'PostAuth', + 'SecureType' => 'NonSecure', + 'OrderId' => null, + 'orgOrderId' => 'order222', + 'PurchAmount' => '10', + 'Currency' => '949', + 'MOTO' => '0', + ], + ], ]; } - /** - * @param array $order - * @param InterPosAccount $interPosAccount - * - * @return array - */ - private function getSampleStatusRequestData(array $order, InterPosAccount $interPosAccount): array + public static function createStatusRequestDataDataProvider(): array { return [ - 'UserCode' => $interPosAccount->getUsername(), - 'UserPass' => $interPosAccount->getPassword(), - 'ShopCode' => $interPosAccount->getClientId(), - 'OrderId' => null, - 'orgOrderId' => $order['id'], - 'TxnType' => 'StatusHistory', - 'SecureType' => 'NonSecure', - 'Lang' => $order['lang'], + [ + 'order' => [ + 'id' => 'order222', + 'lang' => PosInterface::LANG_TR, + ], + 'expected' => [ + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'ShopCode' => '3123', + 'OrderId' => null, + 'orgOrderId' => 'order222', + 'TxnType' => 'StatusHistory', + 'SecureType' => 'NonSecure', + 'Lang' => PosInterface::LANG_TR, + ], + ], ]; } @@ -446,11 +445,11 @@ public static function threeDFormDataProvider(): array 'Lang' => 'tr', 'Currency' => '949', 'InstallmentCount' => '', - 'Hash' => 'vEbwP8wnsGrBR9oCjfxP9wlho1g=', 'CardType' => '0', 'Pan' => '5555444433332222', 'Expiry' => '1221', 'Cvv2' => '122', + 'Hash' => 'vEbwP8wnsGrBR9oCjfxP9wlho1g=', ], ], ], diff --git a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php index 384025b3..e0e41ea2 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php @@ -73,6 +73,7 @@ public function testMapPaymentResponse(array $order, string $txType, array $resp $actualData = $this->responseDataMapper->mapPaymentResponse($responseData, $txType, $order); $this->assertEquals($expectedData['transaction_time'], $actualData['transaction_time']); unset($actualData['transaction_time'], $expectedData['transaction_time']); + $this->assertArrayHasKey('all', $actualData); unset($actualData['all']); \ksort($expectedData); \ksort($actualData); @@ -210,64 +211,89 @@ public function threeDHashCheckDataProvider(): array } - public function paymentTestDataProvider(): array + public static function paymentTestDataProvider(): array { - return - [ - 'fail1' => [ - 'order' => [ - 'currency' => PosInterface::CURRENCY_TRY, - 'amount' => 1.01, - ], - 'txType' => PosInterface::TX_TYPE_PAY_AUTH, - 'responseData' => [ - 'OrderId' => '20221225662C', - 'ProcReturnCode' => '81', - 'HostRefNum' => 'hostid', - 'AuthCode' => '', - 'TxnResult' => 'Failed', - 'ErrorMessage' => 'Terminal Aktif Degil', - 'CampanyId' => '', - 'CampanyInstallCount' => '0', - 'CampanyShiftDateCount' => '0', - 'CampanyTxnId' => '', - 'CampanyType' => '', - 'CampanyInstallment' => '0', - 'CampanyDate' => '0', - 'CampanyAmnt' => '0', - 'TRXDATE' => '', - 'TransId' => '', - 'ErrorCode' => 'B810002', - 'EarnedBonus' => '0', - 'UsedBonus' => '0', - 'AvailableBonus' => '0', - 'BonusToBonus' => '0', - 'CampaignBonus' => '0', - 'FoldedBonus' => '0', - 'SurchargeAmount' => '0', - 'Amount' => '1,01', - 'CardHolderName' => '', - ], - 'expectedData' => [ - 'order_id' => '20221225662C', - 'transaction_id' => null, - 'transaction_type' => 'pay', - 'currency' => 'TRY', - 'amount' => 1.01, - 'payment_model' => 'regular', - 'auth_code' => null, - 'ref_ret_num' => 'hostid', - 'batch_num' => null, - 'proc_return_code' => '81', - 'status' => 'declined', - 'status_detail' => 'invalid_credentials', - 'error_code' => 'B810002', - 'error_message' => 'Terminal Aktif Degil', - 'installment_count' => null, - 'transaction_time' => null, - ], + return [ + 'fail1' => [ + 'order' => [ + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 1.01, + ], + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'responseData' => [ + 'OrderId' => '20221225662C', + 'ProcReturnCode' => '81', + 'HostRefNum' => 'hostid', + 'AuthCode' => '', + 'TxnResult' => 'Failed', + 'ErrorMessage' => 'Terminal Aktif Degil', + 'CampanyId' => '', + 'CampanyInstallCount' => '0', + 'CampanyShiftDateCount' => '0', + 'CampanyTxnId' => '', + 'CampanyType' => '', + 'CampanyInstallment' => '0', + 'CampanyDate' => '0', + 'CampanyAmnt' => '0', + 'TRXDATE' => '', + 'TransId' => '', + 'ErrorCode' => 'B810002', + 'EarnedBonus' => '0', + 'UsedBonus' => '0', + 'AvailableBonus' => '0', + 'BonusToBonus' => '0', + 'CampaignBonus' => '0', + 'FoldedBonus' => '0', + 'SurchargeAmount' => '0', + 'Amount' => '1,01', + 'CardHolderName' => '', + ], + 'expectedData' => [ + 'order_id' => '20221225662C', + 'transaction_id' => null, + 'transaction_type' => 'pay', + 'currency' => 'TRY', + 'amount' => 1.01, + 'payment_model' => 'regular', + 'auth_code' => null, + 'ref_ret_num' => 'hostid', + 'batch_num' => null, + 'proc_return_code' => '81', + 'status' => 'declined', + 'status_detail' => 'invalid_credentials', + 'error_code' => 'B810002', + 'error_message' => 'Terminal Aktif Degil', + 'installment_count' => null, + 'transaction_time' => null, ], - ]; + ], + 'empty' => [ + 'order' => [ + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 1.01, + ], + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'responseData' => [], + 'expectedData' => [ + 'order_id' => null, + 'transaction_id' => null, + 'transaction_time' => null, + 'transaction_type' => PosInterface::TX_TYPE_PAY_AUTH, + 'installment_count' => null, + 'currency' => null, + 'amount' => null, + 'payment_model' => 'regular', + 'auth_code' => null, + 'ref_ret_num' => null, + 'batch_num' => null, + 'proc_return_code' => null, + 'status' => 'declined', + 'status_detail' => null, + 'error_code' => null, + 'error_message' => null, + ], + ], + ]; } From b3338501b4748087dde6de1e2b2a61e40fe17383 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 17 Aug 2024 11:27:56 +0200 Subject: [PATCH 5/8] payflexv4pos - throw exception for unimplemented methods --- src/Crypt/PayFlexCPV4Crypt.php | 2 +- .../PayFlexV4PosResponseDataMapper.php | 4 ++-- tests/Unit/Crypt/PayFlexCP4CryptTest.php | 19 +++++++++++++++++-- .../PayFlexV4PosRequestDataMapperTest.php | 12 ++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Crypt/PayFlexCPV4Crypt.php b/src/Crypt/PayFlexCPV4Crypt.php index e1572770..b1d4f40b 100644 --- a/src/Crypt/PayFlexCPV4Crypt.php +++ b/src/Crypt/PayFlexCPV4Crypt.php @@ -37,7 +37,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $requestData) */ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool { - return true; + throw new NotImplementedException(); } /** diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php index 5a3503ca..bd72e345 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php @@ -91,7 +91,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen */ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txType, array $order): array { - return $this->map3DPaymentData($raw3DAuthResponseData, $raw3DAuthResponseData, $txType, $order); + throw new NotImplementedException(); } /** @@ -99,7 +99,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp */ public function map3DHostResponseData(array $raw3DAuthResponseData, string $txType, array $order): array { - return $this->map3DPayResponseData($raw3DAuthResponseData, $txType, $order); + throw new NotImplementedException(); } /** diff --git a/tests/Unit/Crypt/PayFlexCP4CryptTest.php b/tests/Unit/Crypt/PayFlexCP4CryptTest.php index 4c5ed83c..2aa9f976 100644 --- a/tests/Unit/Crypt/PayFlexCP4CryptTest.php +++ b/tests/Unit/Crypt/PayFlexCP4CryptTest.php @@ -7,6 +7,7 @@ use Mews\Pos\Crypt\PayFlexCPV4Crypt; use Mews\Pos\Entity\Account\PayFlexAccount; +use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\PosInterface; use PHPUnit\Framework\TestCase; @@ -14,6 +15,7 @@ /** * @covers \Mews\Pos\Crypt\PayFlexCPV4Crypt + * @covers \Mews\Pos\Crypt\AbstractCrypt */ class PayFlexCP4CryptTest extends TestCase { @@ -47,7 +49,20 @@ public function testCreate3DHash(array $requestData, string $expected): void $this->assertSame($expected, $actual); } - public function hashCreateDataProvider(): array + public function testCreateHash(): void + { + $this->expectException(NotImplementedException::class); + $this->crypt->createHash($this->account, []); + } + + public function testCheck3DHash(): void + { + $this->expectException(NotImplementedException::class); + + $this->crypt->check3DHash($this->account, []); + } + + public static function hashCreateDataProvider(): array { return [ [ @@ -62,7 +77,7 @@ public function hashCreateDataProvider(): array ]; } - public function threeDHashCreateDataProvider(): array + public static function threeDHashCreateDataProvider(): array { return [ [ diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php index a24f0afa..05053f6a 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php @@ -248,6 +248,18 @@ public function testCreate3DFormData(): void $this->assertEquals($expectedValue, $actualData); } + public function testCreateOrderHistoryRequestData(): void + { + $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); + $this->requestDataMapper->createOrderHistoryRequestData($this->account, []); + } + + public function testCreateHistoryRequestData(): void + { + $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); + $this->requestDataMapper->createHistoryRequestData($this->account, []); + } + /** * @return array */ From ff4a3c6ca54fd63b38cab4817007f912a5e96f9a Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 17 Aug 2024 11:33:42 +0200 Subject: [PATCH 6/8] payflexv4pos - fix order status request with transaction_id --- .../PayFlexV4PosRequestDataMapper.php | 3 +- .../PayFlexV4PosRequestDataMapperTest.php | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php index c2637081..ea7eea68 100644 --- a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php @@ -341,7 +341,8 @@ protected function preparePostPaymentOrder(array $order): array protected function prepareStatusOrder(array $order): array { return [ - 'id' => $order['id'], + 'id' => $order['id'], + 'transaction_id' => $order['transaction_id'] ?? null, ]; } diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php index 05053f6a..dfe56a2d 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php @@ -248,6 +248,16 @@ public function testCreate3DFormData(): void $this->assertEquals($expectedValue, $actualData); } + /** + * @dataProvider createStatusRequestDataDataProvider + */ + public function testCreateStatusRequestData(array $order, array $expectedData): void + { + $actual = $this->requestDataMapper->createStatusRequestData($this->account, $order); + + $this->assertSame($expectedData, $actual); + } + public function testCreateOrderHistoryRequestData(): void { $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); @@ -260,6 +270,45 @@ public function testCreateHistoryRequestData(): void $this->requestDataMapper->createHistoryRequestData($this->account, []); } + public static function createStatusRequestDataDataProvider(): array + { + return [ + 'only_with_order_id' => [ + 'order' => [ + 'id' => 'order222', + ], + 'expected' => [ + 'MerchantCriteria' => [ + 'HostMerchantId' => '000000000111111', + 'MerchantPassword' => '3XTgER89as', + ], + 'TransactionCriteria' => [ + 'TransactionId' => '', + 'OrderId' => 'order222', + 'AuthCode' => '', + ], + ], + ], + 'with_order_id_and_tx_id' => [ + 'order' => [ + 'id' => 'order222', + 'transaction_id' => 'tx222', + ], + 'expected' => [ + 'MerchantCriteria' => [ + 'HostMerchantId' => '000000000111111', + 'MerchantPassword' => '3XTgER89as', + ], + 'TransactionCriteria' => [ + 'TransactionId' => 'tx222', + 'OrderId' => 'order222', + 'AuthCode' => '', + ], + ], + ], + ]; + } + /** * @return array */ From d2cfa26e334bcf94c586139547d0c7c901ca9616 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 17 Aug 2024 11:35:57 +0200 Subject: [PATCH 7/8] test - more coverage --- .../InterPosRequestDataMapperTest.php | 4 +- .../PayFlexV4PosRequestDataMapperTest.php | 213 +++++++++--------- .../PayFlexV4PosResponseDataMapperTest.php | 26 +++ 3 files changed, 140 insertions(+), 103 deletions(-) diff --git a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php index d6529a59..76d20879 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php @@ -125,13 +125,13 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra /** * @dataProvider createNonSecurePaymentRequestDataDataProvider */ - public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $card, array $expected): void + public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $creditCard, array $expected): void { $actual = $this->requestDataMapper->createNonSecurePaymentRequestData( $this->account, $order, PosInterface::TX_TYPE_PAY_AUTH, - $card + $creditCard ); $this->assertSame($expected, $actual); diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php index dfe56a2d..df96798a 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php @@ -21,13 +21,12 @@ /** * @covers \Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper + * @covers \Mews\Pos\DataMapper\RequestDataMapper\AbstractRequestDataMapper */ class PayFlexV4PosRequestDataMapperTest extends TestCase { public PayFlexAccount $account; - private CreditCardInterface $card; - private PayFlexV4PosRequestDataMapper $requestDataMapper; /** @var CryptInterface & MockObject */ @@ -36,8 +35,6 @@ class PayFlexV4PosRequestDataMapperTest extends TestCase /** @var EventDispatcherInterface & MockObject */ private EventDispatcherInterface $dispatcher; - private array $order; - protected function setUp(): void { parent::setUp(); @@ -50,22 +47,9 @@ protected function setUp(): void PosInterface::MODEL_3D_SECURE ); - - $this->order = [ - 'id' => 'order222', - 'amount' => 100.00, - 'installment' => 0, - 'currency' => PosInterface::CURRENCY_TRY, - 'success_url' => 'https://domain.com/success', - 'fail_url' => 'https://domain.com/fail_url', - 'ip' => '127.0.0.1', - ]; - - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); - + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); $this->crypt = $this->createMock(CryptInterface::class); $this->requestDataMapper = new PayFlexV4PosRequestDataMapper($this->dispatcher, $this->crypt); - $this->card = CreditCardFactory::create('5555444433332222', '2021', '12', '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA); } /** @@ -174,43 +158,38 @@ public function testCreate3DEnrollmentCheckData(array $order, ?CreditCardInterfa /** - * @return void + * @dataProvider createNonSecurePaymentRequestDataDataProvider */ - public function testCreateNonSecurePaymentRequestData(): void + public function testCreateNonSecurePaymentRequestData(array $order, CreditCardInterface $creditCard, string $txType, array $expected): void { - $order = $this->order; - $txType = PosInterface::TX_TYPE_PAY_AUTH; - $order['amount'] = 1000; - - $expectedValue = $this->getSampleNonSecurePaymentRequestData($this->account, $order, $txType, $this->card); - $actualData = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, $txType, $this->card); + $actualData = $this->requestDataMapper->createNonSecurePaymentRequestData( + $this->account, + $order, + $txType, + $creditCard + ); - $this->assertEquals($expectedValue, $actualData); + $this->assertSame($expected, $actualData); } /** - * @return void + * @dataProvider createNonSecurePostAuthPaymentRequestDataDataProvider */ - public function testCreateNonSecurePostAuthPaymentRequestData(): void + public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expected): void { - $order = $this->order; - $order['amount'] = 1000; + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - $expectedValue = $this->getSampleNonSecurePaymentPostRequestData($this->account, $order); - $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order); - - $this->assertEquals($expectedValue, $actual); + $this->assertSame($expected, $actual); } - public function testCreateCancelRequestData(): void + /** + * @dataProvider createCancelRequestDataDataProvider + */ + public function testCreateCancelRequestData(array $order, array $expected): void { - $order = $this->order; - $order['transaction_id'] = '7022b92e-3aa1-44fb-86d4-33658c700c80'; - - $expectedValue = $this->getSampleCancelRequestData(); - $actualData = $this->requestDataMapper->createCancelRequestData($this->account, $order); + $actualData = $this->requestDataMapper->createCancelRequestData($this->account, $order); - $this->assertEquals($expectedValue, $actualData); + $this->assertSame($expected, $actualData); } /** @@ -226,12 +205,10 @@ public function testCreateRefundRequestData(array $order, string $txType, array } /** - * @return void + * @dataProvider create3DFormDataDataProvider */ - public function testCreate3DFormData(): void + public function testCreate3DFormData(array $bankResponse, array $expected): void { - $expectedValue = $this->getSample3DFormDataFromEnrollmentResponse(); - $this->dispatcher->expects(self::never()) ->method('dispatch'); @@ -242,10 +219,10 @@ public function testCreate3DFormData(): void null, null, null, - $this->getSampleEnrollmentSuccessResponseDataProvider()['Message']['VERes'] + $bankResponse ); - $this->assertEquals($expectedValue, $actualData); + $this->assertSame($expected, $actualData); } /** @@ -329,14 +306,22 @@ public static function getSampleEnrollmentSuccessResponseDataProvider(): array ]; } - private function getSampleCancelRequestData(): array + public static function createCancelRequestDataDataProvider(): array { return [ - 'MerchantId' => '000000000111111', - 'Password' => '3XTgER89as', - 'TransactionType' => 'Cancel', - 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', - 'ClientIp' => '127.0.0.1', + [ + 'order' => [ + 'transaction_id' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'ip' => '127.0.0.1', + ], + 'expected' => [ + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'TransactionType' => 'Cancel', + 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'ClientIp' => '127.0.0.1', + ], + ], ]; } @@ -438,7 +423,14 @@ public static function three3DEnrollmentRequestDataDataProvider(): \Generator 'ip' => '127.0.0.1', ]; - $card = new CreditCard('5555444433332222', new \DateTimeImmutable('2021-12-01'), '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA); + $card = CreditCardFactory::create( + '5555444433332222', + '2021', + '12', + '122', + 'ahmet', + CreditCardInterface::CARD_TYPE_VISA + ); yield [ 'order' => $order, @@ -550,67 +542,86 @@ public static function refundRequestDataProvider(): array ]; } - /** - * @param PayFlexAccount $posAccount - * @param array $order - * @param string $txType - * @param CreditCardInterface $creditCard - * - * @return array - */ - private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, CreditCardInterface $creditCard): array + public static function createNonSecurePaymentRequestDataDataProvider(): array { + $creditCard = CreditCardFactory::create( + '5555444433332222', + '2021', + '12', + '122', + 'ahmet', + CreditCardInterface::CARD_TYPE_VISA + ); + return [ - 'MerchantId' => $posAccount->getClientId(), - 'Password' => $posAccount->getPassword(), - 'TerminalNo' => $posAccount->getTerminalId(), - 'TransactionType' => $this->requestDataMapper->mapTxType($txType), - 'OrderId' => $order['id'], - 'CurrencyAmount' => '1000.00', - 'CurrencyCode' => 949, - 'ClientIp' => $order['ip'], - 'TransactionDeviceSource' => 0, - 'Pan' => $creditCard->getNumber(), - 'Expiry' => '202112', - 'Cvv' => $creditCard->getCvv(), + [ + 'order' => [ + 'id' => 'order123', + 'amount' => 5, + 'ip' => '127.0.0.1', + ], + 'card' => $creditCard, + 'tx_type' => PosInterface::TX_TYPE_PAY_AUTH, + 'expected' => [ + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'TerminalNo' => 'VP999999', + 'TransactionType' => 'Sale', + 'OrderId' => 'order123', + 'CurrencyAmount' => '5.00', + 'CurrencyCode' => '949', + 'ClientIp' => '127.0.0.1', + 'TransactionDeviceSource' => '0', + 'Pan' => $creditCard->getNumber(), + 'Expiry' => '202112', + 'Cvv' => $creditCard->getCvv(), + ], + ], ]; } - /** - * @param PayFlexAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $posAccount, array $order): array + public static function createNonSecurePostAuthPaymentRequestDataDataProvider(): array { return [ - 'MerchantId' => $posAccount->getClientId(), - 'Password' => $posAccount->getPassword(), - 'TerminalNo' => $posAccount->getTerminalId(), - 'TransactionType' => 'Capture', - 'ReferenceTransactionId' => $order['id'], - 'CurrencyAmount' => '1000.00', - 'CurrencyCode' => '949', - 'ClientIp' => $order['ip'], + [ + 'order' => [ + 'id' => 'order123', + 'amount' => 1000, + 'ip' => '127.0.0.1', + ], + 'expected' => [ + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'TerminalNo' => 'VP999999', + 'TransactionType' => 'Capture', + 'ReferenceTransactionId' => 'order123', + 'CurrencyAmount' => '1000.00', + 'CurrencyCode' => '949', + 'ClientIp' => '127.0.0.1', + ], + ], ]; } /** * @return array */ - private function getSample3DFormDataFromEnrollmentResponse(): array + public static function create3DFormDataDataProvider(): array { - $inputs = [ - 'PaReq' => 'PaReq2', - 'TermUrl' => 'TermUrl2', - 'MD' => 'MD3', - ]; - return [ - 'gateway' => 'http', - 'method' => 'POST', - 'inputs' => $inputs, + [ + 'response' => self::getSampleEnrollmentSuccessResponseDataProvider()['Message']['VERes'], + 'expected' => [ + 'gateway' => 'http', + 'method' => 'POST', + 'inputs' => [ + + 'PaReq' => 'PaReq2', + 'TermUrl' => 'TermUrl2', + 'MD' => 'MD3', + ], + ], + ], ]; } } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php index d20782d4..9396002e 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php @@ -8,6 +8,7 @@ use Mews\Pos\Crypt\CryptInterface; use Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper; +use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; @@ -15,6 +16,7 @@ /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class PayFlexV4PosResponseDataMapperTest extends TestCase { @@ -131,6 +133,30 @@ public function testMapStatusResponse(array $responseData, array $expectedData): $this->assertSame($expectedData, $actualData); } + public function testMap3DPayResponseData(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->map3DPayResponseData([], PosInterface::TX_TYPE_PAY_AUTH, []); + } + + public function testMap3DHostResponseData(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->map3DHostResponseData([], PosInterface::TX_TYPE_PAY_AUTH, []); + } + + public function testMapHistoryResponse(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->mapHistoryResponse([]); + } + + public function testMapOrderHistoryResponse(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->mapOrderHistoryResponse([]); + } + public static function statusTestDataProvider(): iterable { yield 'fail1' => [ From d740c95784a9bc057ac2859aaa219673d0f08e23 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 17 Aug 2024 11:50:30 +0200 Subject: [PATCH 8/8] styling - run rector --- .../GarantiPosResponseDataMapper.php | 5 ++++ .../PayFlexV4PosResponseDataMapper.php | 1 + src/Gateways/AbstractGateway.php | 1 + .../GarantiPosResponseDataMapperTest.php | 2 ++ .../InterPosResponseDataMapperTest.php | 1 + .../VakifKatilimPosResponseDataMapperTest.php | 23 ++++++++++++------- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php index 62a89917..556873a5 100644 --- a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php @@ -638,6 +638,7 @@ private function mapHistoryOrderStatus(string $txStatus, ?string $txType): ?stri if (null === $txType) { return null; } + // txStatus possible values: // Basarili // Basarisiz @@ -648,19 +649,23 @@ private function mapHistoryOrderStatus(string $txStatus, ?string $txType): ?stri if (PosInterface::TX_TYPE_CANCEL === $txType) { return PosInterface::PAYMENT_STATUS_CANCELED; } + if (PosInterface::TX_TYPE_REFUND === $txType) { // todo how can we decide if order is partially or fully refunded? return PosInterface::PAYMENT_STATUS_FULLY_REFUNDED; } + if (PosInterface::TX_TYPE_PAY_AUTH === $txType || PosInterface::TX_TYPE_PAY_POST_AUTH === $txType) { return PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED; } + if (PosInterface::TX_TYPE_PAY_PRE_AUTH === $txType) { return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; } return null; } + if ('Iptal' === $txStatus) { return null; } diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php index bd72e345..fc36f6e2 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php @@ -213,6 +213,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType if (\strlen($txTime) === 10) { // ziraat is sending host date without year $txTime = date('Y').$txTime; } + $commonResponse['transaction_time'] = new \DateTimeImmutable($txTime); $commonResponse['auth_code'] = $rawPaymentResponseData['AuthCode']; $commonResponse['ref_ret_num'] = $rawPaymentResponseData['TransactionId']; diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index 3d4fc245..32c44c0f 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -314,6 +314,7 @@ public function refund(array $order): PosInterface if (isset($order['order_amount']) && $order['amount'] < $order['order_amount']) { $txType = PosInterface::TX_TYPE_REFUND_PARTIAL; } + $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); $event = new RequestDataPreparedEvent( diff --git a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php index d33877b4..758c58ab 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php @@ -17,6 +17,7 @@ /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class GarantiPosResponseDataMapperTest extends TestCase { @@ -1789,6 +1790,7 @@ public static function historyTestDataProvider(): \Generator new \DateTimeZone($item['transaction_time']['timezone']) ); } + if (null !== $item['capture_time']) { $item['capture_time'] = new \DateTimeImmutable( $item['capture_time']['date'], diff --git a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php index e0e41ea2..e5b66544 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php @@ -96,6 +96,7 @@ public function testMap3DPaymentData(array $order, string $txType, array $threeD } else { $this->assertEquals($expectedData['transaction_time'], $actualData['transaction_time']); } + unset($actualData['transaction_time'], $expectedData['transaction_time']); $this->assertArrayHasKey('3d_all', $actualData); diff --git a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php index d8a2a945..e748dff6 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php @@ -17,6 +17,7 @@ /** * @covers \Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper + * @covers \Mews\Pos\DataMapper\ResponseDataMapper\AbstractResponseDataMapper */ class VakifKatilimPosResponseDataMapperTest extends TestCase { @@ -220,16 +221,22 @@ public function testMapHistoryResponseWithALotOfTxs(): void $actualData = $this->responseDataMapper->mapHistoryResponse(json_decode($responseData, true)); $this->assertCount(31, $actualData['transactions']); + if (count($actualData['transactions']) <= 1) { + return; + } - if (count($actualData['transactions']) > 1 - && null !== $actualData['transactions'][0]['transaction_time'] - && null !== $actualData['transactions'][1]['transaction_time'] - ) { - $this->assertGreaterThan( - $actualData['transactions'][0]['transaction_time'], - $actualData['transactions'][1]['transaction_time'], - ); + if (null === $actualData['transactions'][0]['transaction_time']) { + return; + } + + if (null === $actualData['transactions'][1]['transaction_time']) { + return; } + + $this->assertGreaterThan( + $actualData['transactions'][0]['transaction_time'], + $actualData['transactions'][1]['transaction_time'], + ); }