diff --git a/tests/Unit/Gateways/EstPosTest.php b/tests/Unit/Gateways/EstPosTest.php index 9e459ca0..8e793276 100644 --- a/tests/Unit/Gateways/EstPosTest.php +++ b/tests/Unit/Gateways/EstPosTest.php @@ -12,6 +12,7 @@ use Mews\Pos\Entity\Account\EstPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\RequestDataPreparedEvent; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; @@ -205,6 +206,23 @@ public function testMake3DHostPaymentSuccess(): void $this->assertTrue($pos->isSuccess()); } + public function testMake3DHostPaymentHashMismatchException(): void + { + $data = EstPosResponseDataMapperTest::threeDHostPaymentDataProvider()['success1']['paymentData']; + $request = Request::create('', 'POST', $data); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DHostResponseData'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DHostPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @return void */ @@ -233,6 +251,23 @@ public function testMake3DPayPaymentSuccess(): void $this->assertTrue($pos->isSuccess()); } + public function testMake3DPayPaymentHashMismatchException(): void + { + $data = EstPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; + $request = Request::create('', 'POST', $data); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPayResponseData'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @dataProvider statusDataProvider */ @@ -467,6 +502,36 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentHashMismatchException(): void + { + $data = EstPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['threeDResponseData']; + $request = Request::create('', 'POST', $data); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPaymentData'); + $this->requestMapperMock->expects(self::never()) + ->method('create3DPaymentRequestData'); + $this->serializerMock->expects(self::never()) + ->method('encode'); + $this->serializerMock->expects(self::never()) + ->method('decode'); + $this->eventDispatcherMock->expects(self::never()) + ->method('dispatch'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + + /** * @dataProvider makeRegularPaymentDataProvider */ diff --git a/tests/Unit/Gateways/GarantiPosTest.php b/tests/Unit/Gateways/GarantiPosTest.php index 9c5d4f7a..7bbedf68 100644 --- a/tests/Unit/Gateways/GarantiPosTest.php +++ b/tests/Unit/Gateways/GarantiPosTest.php @@ -12,6 +12,7 @@ use Mews\Pos\Entity\Account\GarantiPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\RequestDataPreparedEvent; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; @@ -244,6 +245,35 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentHashMismatchException(): void + { + $data = GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['threeDResponseData']; + $request = Request::create('', 'POST', $data); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPaymentData'); + $this->requestMapperMock->expects(self::never()) + ->method('create3DPaymentRequestData'); + $this->serializerMock->expects(self::never()) + ->method('encode'); + $this->serializerMock->expects(self::never()) + ->method('decode'); + $this->eventDispatcherMock->expects(self::never()) + ->method('dispatch'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + public function testMake3DHostPayment(): void { $request = Request::create('', 'POST'); @@ -522,7 +552,11 @@ public static function make3DPaymentDataProvider(): array '3d_auth_success_payment_fail' => [ 'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['order'], 'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['txType'], - 'request' => Request::create('', 'POST', GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['threeDResponseData']), + 'request' => Request::create( + '', + 'POST', + GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['threeDResponseData'] + ), 'paymentResponse' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['paymentData'], 'expected' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['expectedData'], 'is3DSuccess' => true, @@ -531,7 +565,11 @@ public static function make3DPaymentDataProvider(): array 'success' => [ 'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'], 'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'], - 'request' => Request::create('', 'POST', GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']), + 'request' => Request::create( + '', + 'POST', + GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData'] + ), 'paymentResponse' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'], 'expected' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'], 'is3DSuccess' => true, diff --git a/tests/Unit/Gateways/KuveytPosTest.php b/tests/Unit/Gateways/KuveytPosTest.php index 3aa3c70e..d2cea642 100644 --- a/tests/Unit/Gateways/KuveytPosTest.php +++ b/tests/Unit/Gateways/KuveytPosTest.php @@ -353,6 +353,34 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentException(): void + { + $request = Request::create(''); + + $this->cryptMock->expects(self::never()) + ->method('check3DHash'); + + $this->responseMapperMock->expects(self::never()) + ->method('extractMdStatus'); + + $this->responseMapperMock->expects(self::never()) + ->method('is3dAuthSuccess'); + + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPaymentData'); + + $this->requestMapperMock->expects(self::never()) + ->method('create3DPaymentRequestData'); + $this->serializerMock->expects(self::never()) + ->method('encode'); + $this->serializerMock->expects(self::never()) + ->method('decode'); + + $this->expectException(\LogicException::class); + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @dataProvider makeRegularPaymentDataProvider */ diff --git a/tests/Unit/Gateways/PayForTest.php b/tests/Unit/Gateways/PayForTest.php index ab1da4fe..34577dd3 100644 --- a/tests/Unit/Gateways/PayForTest.php +++ b/tests/Unit/Gateways/PayForTest.php @@ -12,6 +12,7 @@ use Mews\Pos\Entity\Account\PayForAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\RequestDataPreparedEvent; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; use Mews\Pos\Gateways\PayForPos; @@ -258,6 +259,35 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentHashMismatchException(): void + { + $data = PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']; + $request = Request::create('', 'POST', $data); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPaymentData'); + $this->requestMapperMock->expects(self::never()) + ->method('create3DPaymentRequestData'); + $this->serializerMock->expects(self::never()) + ->method('encode'); + $this->serializerMock->expects(self::never()) + ->method('decode'); + $this->eventDispatcherMock->expects(self::never()) + ->method('dispatch'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @return void */ @@ -556,7 +586,11 @@ public static function make3DPaymentDataProvider(): array 'auth_fail' => [ 'order' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['order'], 'txType' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['txType'], - 'request' => Request::create('', 'POST', PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['threeDResponseData']), + 'request' => Request::create( + '', + 'POST', + PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['threeDResponseData'] + ), 'paymentResponse' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['paymentData'], 'expected' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['auth_fail1']['expectedData'], 'is3DSuccess' => false, @@ -565,7 +599,11 @@ public static function make3DPaymentDataProvider(): array 'order_number_already_exist' => [ 'order' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['order'], 'txType' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['txType'], - 'request' => Request::create('', 'POST', PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['threeDResponseData']), + 'request' => Request::create( + '', + 'POST', + PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['threeDResponseData'] + ), 'paymentResponse' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['paymentData'], 'expected' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['order_number_already_exist']['expectedData'], 'is3DSuccess' => false, @@ -574,7 +612,11 @@ public static function make3DPaymentDataProvider(): array 'success' => [ 'order' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'], 'txType' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'], - 'request' => Request::create('', 'POST', PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']), + 'request' => Request::create( + '', + 'POST', + PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData'] + ), 'paymentResponse' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'], 'expected' => PayForPosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'], 'is3DSuccess' => true, diff --git a/tests/Unit/Gateways/PosNetTest.php b/tests/Unit/Gateways/PosNetTest.php index 4bcddf26..6b2cb712 100644 --- a/tests/Unit/Gateways/PosNetTest.php +++ b/tests/Unit/Gateways/PosNetTest.php @@ -15,6 +15,7 @@ use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\RequestDataPreparedEvent; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; @@ -394,6 +395,48 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentHashMismatchException(): void + { + $resolveResponse = PosNetResponseDataMapperTest::threeDPaymentDataProvider()['success1']['threeDResponseData']; + $request = Request::create( + '', + 'POST', + $resolveResponse + ); + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $resolveResponse['oosResolveMerchantDataResponse']) + ->willReturn(false); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $resolveMerchantRequestData = [ + 'resolveMerchantRequestData', + ]; + $this->requestMapperMock->expects(self::once()) + ->method('create3DResolveMerchantRequestData') + ->willReturn($resolveMerchantRequestData); + + $this->requestMapperMock->expects(self::never()) + ->method('create3DPaymentRequestData'); + + $this->configureClientResponse( + PosInterface::TX_TYPE_PAY_AUTH, + 'https://setmpos.ykb.com/PosnetWebService/XML', + $resolveMerchantRequestData, + 'request-body', + 'response-body', + $resolveResponse, + [], + PosInterface::MODEL_3D_SECURE + ); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + public function testMake3DHostPayment(): void { $request = Request::create('', 'POST'); diff --git a/tests/Unit/Gateways/PosNetV1PosTest.php b/tests/Unit/Gateways/PosNetV1PosTest.php index 19a0bcd8..92f69a5b 100644 --- a/tests/Unit/Gateways/PosNetV1PosTest.php +++ b/tests/Unit/Gateways/PosNetV1PosTest.php @@ -12,6 +12,7 @@ use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\RequestDataPreparedEvent; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; @@ -251,6 +252,36 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentHashMismatchException(): void + { + $dataSamples = iterator_to_array(PosNetV1PosResponseDataMapperTest::threeDPaymentDataProvider()); + $data = $dataSamples['3d_auth_success_payment_fail']['threeDResponseData']; + $request = Request::create('', 'POST', $data); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPaymentData'); + $this->requestMapperMock->expects(self::never()) + ->method('create3DPaymentRequestData'); + $this->serializerMock->expects(self::never()) + ->method('encode'); + $this->serializerMock->expects(self::never()) + ->method('decode'); + $this->eventDispatcherMock->expects(self::never()) + ->method('dispatch'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + public function testMake3DHostPayment(): void { $request = Request::create('', 'POST'); diff --git a/tests/Unit/Gateways/ToslaPosTest.php b/tests/Unit/Gateways/ToslaPosTest.php index 847ee0b1..82331291 100644 --- a/tests/Unit/Gateways/ToslaPosTest.php +++ b/tests/Unit/Gateways/ToslaPosTest.php @@ -12,6 +12,7 @@ use Mews\Pos\Entity\Account\ToslaPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\RequestDataPreparedEvent; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; @@ -192,6 +193,27 @@ public function testMake3DPayPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPayPaymentHashMismatchException(): void + { + $data = ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; + $request = Request::create('', 'POST', $data); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DPayResponseData'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DPayPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @dataProvider make3DPayPaymentDataProvider */ @@ -232,6 +254,27 @@ public function testMake3DHostPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DHostPaymentHashMismatchException(): void + { + $data = ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']; + $request = Request::create('', 'POST', $data); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->willReturn(true); + + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $data) + ->willReturn(false); + + $this->responseMapperMock->expects(self::never()) + ->method('map3DHostResponseData'); + + $this->expectException(HashMismatchException::class); + $this->pos->make3DHostPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @dataProvider make3DPayPaymentDataProvider */ @@ -559,7 +602,11 @@ public static function make3DPayPaymentDataProvider(): array 'auth_fail' => [ 'order' => ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['auth_fail']['order'], 'txType' => ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['auth_fail']['txType'], - 'request' => Request::create('', 'POST', ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['auth_fail']['paymentData']), + 'request' => Request::create( + '', + 'POST', + ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['auth_fail']['paymentData'] + ), 'expected' => ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['auth_fail']['expectedData'], 'is3DSuccess' => false, 'isSuccess' => false, @@ -567,7 +614,11 @@ public static function make3DPayPaymentDataProvider(): array 'success' => [ 'order' => ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['order'], 'txType' => ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['txType'], - 'request' => Request::create('', 'POST', ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData']), + 'request' => Request::create( + '', + 'POST', + ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['paymentData'] + ), 'expected' => ToslaPosResponseDataMapperTest::threeDPayPaymentDataProvider()['success1']['expectedData'], 'is3DSuccess' => true, 'isSuccess' => true,