From 926eb7e2337338e4dd3b5caec654a7de3fb7bb97 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Sat, 7 Sep 2024 16:47:39 +0200 Subject: [PATCH] tests - cover get3DFormData --- .../GarantiPosResponseDataMapperTest.php | 77 +++++++++++++++ tests/Unit/Gateways/GarantiPosTest.php | 13 +++ tests/Unit/Gateways/PayFlexV4PosTest.php | 94 ++++++++++++------- tests/Unit/Gateways/PosNetTest.php | 15 +++ tests/Unit/Gateways/ToslaPosTest.php | 70 +++++++++++++- 5 files changed, 231 insertions(+), 38 deletions(-) diff --git a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php index 758c58ab..5589809b 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php @@ -612,6 +612,83 @@ public static function threeDPaymentDataProvider(): array 'transaction_time' => null, ], ], + '3d_auth_fail_1' => [ + 'order' => [], + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'threeDResponseData' => [ + 'apiversion' => '512', + 'authcode' => '', + 'cavv' => '', + 'cavvalgorithm' => '', + 'clientid' => '30691298', + 'customeripaddress' => '192.168.0.1', + 'eci' => '', + 'errmsg' => '', + 'errorurl' => 'http://localhost:807/garanti/3d/response.php', + 'garanticardind' => '', + 'hash' => 'FD9BF014BFBC3D977B123AE84247CE3F639913644429304C4EE108C0F40212853628CAECAADB798EE73D467F50C3B5D90FE0F3B921EDAA94B6E2EA888F9FE9B7', + 'hashparams' => 'clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:', + 'hashparamsval' => '30691298202409078CF30aW5kZXg6MDIYjoYTHmZE91tOHZxS3PEkMcb8vBvm21xQz107TS6WKHVjLlrZP9AMx7KFu8jZRZA3WtZxMUuaUynWLxQGsVrw1vTKIofUQ0dw2P/jVVvPMX/RxI7Bpjvo/pZp3Nmbj2wd1W146UhNNmge7eA+hdrNSHuPp7PmjAihyZEPujAi3Q==6ga2Y3buKZ3ZcJSC7uE6', + 'hostmsg' => '', + 'hostrefnum' => '', + 'ireqcode' => '', + 'ireqdetail' => '', + 'MaskedPan' => '42822090****8012', + 'md' => 'aW5kZXg6MDIYjoYTHmZE91tOHZxS3PEkMcb8vBvm21xQz107TS6WKHVjLlrZP9AMx7KFu8jZRZA3WtZxMUuaUynWLxQGsVrw1vTKIofUQ0dw2P/jVVvPMX/RxI7Bpjvo/pZp3Nmbj2wd1W146UhNNmge7eA+hdrNSHuPp7PmjAihyZEPujAi3Q==', + 'mderrormessage' => '', + 'mdstatus' => '0', + 'mode' => 'TEST', + 'oid' => '202409078CF3', + 'orderid' => '202409078CF3', + 'paressyntaxok' => '', + 'paresverified' => '', + 'procreturncode' => '', + 'response' => '', + 'rnd' => '6ga2Y3buKZ3ZcJSC7uE6', + 'secure3dhash' => '9F3027C22FB3485484144993E5EE0B0B99FB30A7CF76EBF885F0F01BC0898FB54C3892F02FAB1BF8C16B0F8C868A6C6F7689381D0DBC882ABA786EA764B13DCA', + 'secure3dsecuritylevel' => '3D', + 'successurl' => 'http://localhost:807/garanti/3d/response.php', + 'terminalid' => '30691298', + 'terminalmerchantid' => '7000679', + 'terminalprovuserid' => 'PROVAUT', + 'terminaluserid' => 'PROVAUT', + 'transid' => '202409078CF3', + 'txnamount' => '1001', + 'txncurrencycode' => '949', + 'txninstallmentcount' => '', + 'txnstatus' => '', + 'txntype' => 'sales', + 'vendorcode' => '', + 'version' => '', + 'xid' => '9df81889-86f6-42bf-9129-8189d30e6fef', + ], + 'paymentData' => [], + 'expectedData' => [ + 'order_id' => '202409078CF3', + 'transaction_id' => null, + 'auth_code' => null, + 'ref_ret_num' => null, + 'transaction_security' => 'MPI fallback', + 'proc_return_code' => null, + 'md_status' => '0', + 'status' => 'declined', + 'status_detail' => null, + 'masked_number' => null, + 'amount' => 10.01, + 'currency' => 'TRY', + 'tx_status' => null, + 'eci' => null, + 'cavv' => null, + 'error_code' => null, + 'error_message' => null, + 'md_error_message' => null, + 'batch_num' => null, + 'transaction_type' => 'pay', + 'payment_model' => '3d', + 'installment_count' => 0, + 'transaction_time' => null, + ], + ], 'success1' => [ 'order' => [], 'txType' => PosInterface::TX_TYPE_PAY_AUTH, diff --git a/tests/Unit/Gateways/GarantiPosTest.php b/tests/Unit/Gateways/GarantiPosTest.php index 7bbedf68..7c226550 100644 --- a/tests/Unit/Gateways/GarantiPosTest.php +++ b/tests/Unit/Gateways/GarantiPosTest.php @@ -549,6 +549,19 @@ public function testOrderHistoryRequest(array $order, string $apiUrl): void public static function make3DPaymentDataProvider(): array { return [ + '3d_auth_fail_1' => [ + 'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['order'], + 'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['txType'], + 'request' => Request::create( + '', + 'POST', + GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['threeDResponseData'] + ), + 'paymentResponse' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['paymentData'], + 'expected' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['expectedData'], + 'is3DSuccess' => false, + 'isSuccess' => false, + ], '3d_auth_success_payment_fail' => [ 'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['order'], 'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['txType'], diff --git a/tests/Unit/Gateways/PayFlexV4PosTest.php b/tests/Unit/Gateways/PayFlexV4PosTest.php index d11c4844..1f359b55 100644 --- a/tests/Unit/Gateways/PayFlexV4PosTest.php +++ b/tests/Unit/Gateways/PayFlexV4PosTest.php @@ -75,12 +75,12 @@ protected function setUp(): void parent::setUp(); $this->config = [ - 'name' => 'VakifBank-VPOS', - 'class' => PayFlexV4Pos::class, - 'gateway_endpoints' => [ - 'payment_api' => 'https://onlineodemetest.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx', - 'gateway_3d' => 'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspxs', - 'query_api' => 'https://sanalpos.vakifbank.com.tr/v4/UIWebService/Search.aspx', + 'name' => 'VakifBank-VPOS', + 'class' => PayFlexV4Pos::class, + 'gateway_endpoints' => [ + 'payment_api' => 'https://onlineodemetest.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx', + 'gateway_3d' => 'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspxs', + 'query_api' => 'https://sanalpos.vakifbank.com.tr/v4/UIWebService/Search.aspx', ], ]; @@ -128,7 +128,14 @@ protected function setUp(): void $this->pos->setTestMode(true); - $this->card = CreditCardFactory::createForGateway($this->pos, '5555444433332222', '2021', '12', '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA); + $this->card = CreditCardFactory::create( + '5555444433332222', + '2021', + '12', + '122', + 'ahmet', + CreditCardInterface::CARD_TYPE_VISA + ); } /** @@ -147,11 +154,10 @@ public function testInit(): void /** * @return void * - * @throws Exception + * @dataProvider enrollmentFailResponseDataProvider */ - public function testGet3DFormDataEnrollmentFail(): void + public function testGet3DFormDataEnrollmentFail(array $response): void { - $this->expectException(Exception::class); $txType = PosInterface::TX_TYPE_PAY_AUTH; $requestData = ['request-data']; $order = $this->order; @@ -162,11 +168,11 @@ public function testGet3DFormDataEnrollmentFail(): void $this->configureClientResponse( $txType, - $this->config['gateway_endpoints']['gateway_3d'], + 'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspxs', $requestData, $requestData, 'response-body', - self::getSampleEnrollmentFailResponseDataProvider(), + $response, $order, PosInterface::MODEL_3D_SECURE ); @@ -174,9 +180,25 @@ public function testGet3DFormDataEnrollmentFail(): void $this->requestMapperMock->expects(self::never()) ->method('create3DFormData'); + $this->expectException(\RuntimeException::class); $this->pos->get3DFormData($order, PosInterface::MODEL_3D_SECURE, $txType, $this->card); } + public function testGet3DFormDataWithoutCard(): void + { + $this->requestMapperMock->expects(self::never()) + ->method('create3DEnrollmentCheckRequestData'); + + $this->httpClientMock->expects(self::never()) + ->method('post'); + + $this->requestMapperMock->expects(self::never()) + ->method('create3DFormData'); + + $this->expectException(\LogicException::class); + $this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @return void * @@ -496,17 +518,21 @@ public function testOrderHistoryRequest(): void $this->pos->orderHistory([]); } - public static function getSampleEnrollmentFailResponseDataProvider(): array + public static function enrollmentFailResponseDataProvider(): array { return [ - 'Message' => [ - 'VERes' => [ - 'Status' => 'E', + 'merchant_not_found' => [ + 'response' => [ + 'Message' => [ + 'VERes' => [ + 'Status' => 'E', + ], + ], + 'VerifyEnrollmentRequestId' => '0aebb0757acccae6fba75b2e4d78cecf', + 'MessageErrorCode' => '2005', + 'ErrorMessage' => 'Merchant cannot be found for this bank', ], ], - 'VerifyEnrollmentRequestId' => '0aebb0757acccae6fba75b2e4d78cecf', - 'MessageErrorCode' => '2005', - 'ErrorMessage' => 'Merchant cannot be found for this bank', ]; } @@ -595,28 +621,28 @@ public static function make3DPaymentDataProvider(): array 'isSuccess' => false, ], '3d_auth_success_payment_fail' => [ - 'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['order'], - 'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['txType'], - 'request' => Request::create( + 'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['order'], + 'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['txType'], + 'request' => Request::create( '', 'POST', PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['threeDResponseData'] - ), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['paymentData'], - 'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['expectedData'], - 'is3DSuccess' => true, - 'isSuccess' => false, + ), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['paymentData'], + 'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['expectedData'], + 'is3DSuccess' => true, + 'isSuccess' => false, ], 'success' => [ - 'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'], - 'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'], - 'request' => Request::create( + 'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'], + 'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'], + 'request' => Request::create( '', 'POST', PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['threeDResponseData'] - ), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'], - 'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'], - 'is3DSuccess' => true, - 'isSuccess' => true, + ), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'], + 'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'], + 'is3DSuccess' => true, + 'isSuccess' => true, ], ]; } @@ -625,7 +651,7 @@ private function configureClientResponse( string $txType, string $apiUrl, array $requestData, - $encodedRequestData, + $encodedRequestData, string $responseContent, array $decodedResponse, array $order, diff --git a/tests/Unit/Gateways/PosNetTest.php b/tests/Unit/Gateways/PosNetTest.php index 6b2cb712..9525d4f7 100644 --- a/tests/Unit/Gateways/PosNetTest.php +++ b/tests/Unit/Gateways/PosNetTest.php @@ -183,6 +183,21 @@ public function testGet3DFormDataOosTransactionFail(): void $this->pos->get3DFormData($order, PosInterface::MODEL_3D_SECURE, $txType, $this->card); } + public function testGet3DFormDataWithoutCard(): void + { + $this->requestMapperMock->expects(self::never()) + ->method('create3DEnrollmentCheckRequestData'); + + $this->httpClientMock->expects(self::never()) + ->method('post'); + + $this->requestMapperMock->expects(self::never()) + ->method('create3DFormData'); + + $this->expectException(\LogicException::class); + $this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @dataProvider make3DPaymentDataProvider */ diff --git a/tests/Unit/Gateways/ToslaPosTest.php b/tests/Unit/Gateways/ToslaPosTest.php index 4dd6f7c0..acb3aa5c 100644 --- a/tests/Unit/Gateways/ToslaPosTest.php +++ b/tests/Unit/Gateways/ToslaPosTest.php @@ -204,7 +204,7 @@ public function testMake3DPayPayment( public function testMake3DPayPaymentHashMismatchException(): void { - $data = ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; + $data = ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; $request = Request::create('', 'POST', $data); $this->responseMapperMock->expects(self::once()) @@ -265,7 +265,7 @@ public function testMake3DHostPayment( public function testMake3DHostPaymentHashMismatchException(): void { - $data = ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; + $data = ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; $request = Request::create('', 'POST', $data); $this->responseMapperMock->expects(self::once()) @@ -344,6 +344,54 @@ public function testGet3DFormData( $this->assertSame($actual, $formData); } + public function testGet3DFormDataWithoutCard(): void + { + $this->requestMapperMock->expects(self::never()) + ->method('create3DEnrollmentCheckRequestData'); + + $this->httpClientMock->expects(self::never()) + ->method('post'); + + $this->requestMapperMock->expects(self::never()) + ->method('create3DFormData'); + + $this->expectException(\LogicException::class); + $this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH); + } + + /** + * @return void + * + * @dataProvider registerFailResponseDataProvider + */ + public function testGet3DFormDataRegisterPaymentFail(array $response): void + { + $txType = PosInterface::TX_TYPE_PAY_AUTH; + $requestData = ['request-data']; + $order = ['order']; + $this->requestMapperMock->expects(self::once()) + ->method('create3DEnrollmentCheckRequestData') + ->with($this->pos->getAccount(), $order) + ->willReturn($requestData); + + $this->configureClientResponse( + $txType, + 'https://ent.akodepos.com/api/Payment/threeDPayment', + $requestData, + 'encoded-request', + 'response-body', + $response, + $order, + PosInterface::MODEL_3D_PAY + ); + + $this->requestMapperMock->expects(self::never()) + ->method('create3DFormData'); + + $this->expectException(\RuntimeException::class); + $this->pos->get3DFormData($order, PosInterface::MODEL_3D_PAY, $txType, $this->card); + } + /** * @dataProvider statusDataProvider */ @@ -491,8 +539,8 @@ public function testOrderHistory( bool $isSuccess ): void { - $account = $this->pos->getAccount(); - $txType = PosInterface::TX_TYPE_ORDER_HISTORY; + $account = $this->pos->getAccount(); + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $this->requestMapperMock->expects(self::once()) ->method('createOrderHistoryRequestData') @@ -961,6 +1009,20 @@ public static function refundRequestDataProvider(): array ]; } + public static function registerFailResponseDataProvider(): array + { + return [ + 'merchant_not_found' => [ + 'response' => [ + 'Code' => 202, + 'Message' => 'Üye İşyeri Kullanıcısı Bulunamadı', + 'ThreeDSessionId' => null, + 'TransactionId' => null, + ], + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl,