diff --git a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php index 0dcdd71a..384025b3 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php @@ -7,6 +7,7 @@ use Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper; +use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\Factory\CryptFactory; use Mews\Pos\Gateways\InterPos; use Mews\Pos\PosInterface; @@ -171,6 +172,18 @@ public function testMapCancelResponse(array $responseData, array $expectedData): $this->assertSame($expectedData, $actualData); } + public function testMapHistoryResponse(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->mapHistoryResponse([]); + } + + public function testMapOrderHistoryResponse(): void + { + $this->expectException(NotImplementedException::class); + $this->responseDataMapper->mapOrderHistoryResponse([]); + } + public function threeDHashCheckDataProvider(): array { return [ diff --git a/tests/Unit/Gateways/InterPosTest.php b/tests/Unit/Gateways/InterPosTest.php index 4cac171b..59226a72 100644 --- a/tests/Unit/Gateways/InterPosTest.php +++ b/tests/Unit/Gateways/InterPosTest.php @@ -11,6 +11,7 @@ use Mews\Pos\Entity\Account\InterPosAccount; 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; @@ -193,6 +194,16 @@ public function testMake3DPayment( ->willReturn(true); } + $this->responseMapperMock->expects(self::once()) + ->method('extractMdStatus') + ->with($request->request->all()) + ->willReturn('3d-status'); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->with('3d-status') + ->willReturn($is3DSuccess); + $create3DPaymentRequestData = [ 'create3DPaymentRequestData', ]; @@ -240,6 +251,33 @@ public function testMake3DPayment( $this->assertSame($isSuccess, $this->pos->isSuccess()); } + public function testMake3DPaymentHashMismatchException(): void + { + $request = Request::create( + '', + 'POST', + ['data'] + ); + $this->cryptMock->expects(self::once()) + ->method('check3DHash') + ->with($this->account, $request->request->all()) + ->willReturn(false); + + $this->responseMapperMock->expects(self::once()) + ->method('extractMdStatus') + ->with($request->request->all()) + ->willReturn('3d-status'); + + $this->responseMapperMock->expects(self::once()) + ->method('is3dAuthSuccess') + ->with('3d-status') + ->willReturn(true); + + $this->expectException(HashMismatchException::class); + + $this->pos->make3DPayment($request, [], PosInterface::TX_TYPE_PAY_AUTH); + } + /** * @return void */ @@ -490,6 +528,16 @@ public static function make3DPaymentDataProvider(): array 'is3DSuccess' => false, 'isSuccess' => false, ], + 'success' => [ + 'order' => ['order'], + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'request' => Request::create('', 'POST', ['gateway_response']), + 'paymentResponse' => ['paymentResponse'], + 'expected' => ['status' => 'approved'], + 'check_hash' => true, + 'is3DSuccess' => true, + 'isSuccess' => true, + ], ]; } diff --git a/tests/Unit/Serializer/InterPosSerializerTest.php b/tests/Unit/Serializer/InterPosSerializerTest.php index 81d2bc26..49180247 100644 --- a/tests/Unit/Serializer/InterPosSerializerTest.php +++ b/tests/Unit/Serializer/InterPosSerializerTest.php @@ -37,4 +37,63 @@ public function testEncode(): void $this->assertSame($data, $result); } + + /** + * @dataProvider decodeDataProvider + */ + public function testDecode(string $input, array $expected): void + { + $result = $this->serializer->decode($input); + + $this->assertSame($expected, $result); + } + + public static function decodeDataProvider(): array + { + return [ + 'success_payment' => [ + 'input' => 'OrderId=33554969;;ProcReturnCode=00;;HostRefNum=hostid;;AuthCode=gizlendi;;TxnResult=Success;;ErrorMessage=;;CampanyId=;;CampanyInstallCount=0;;CampanyShiftDateCount=0;;CampanyTxnId=;;CampanyType=;;CampanyInstallment=0;;CampanyDate=0;;CampanyAmnt=0;;TRXDATE=09.08.2024 10:40:34;;TransId=gizlendi;;ErrorCode=;;EarnedBonus=0,00;;UsedBonus=0,00;;AvailableBonus=0,00;;BonusToBonus=0;;CampaignBonus=0,00;;FoldedBonus=0;;SurchargeAmount=0;;Amount=1,00;;CardHolderName=gizlendi;;QrReferenceNumber=;;QrCardToken=;;QrData=;;QrPayIsSucess=False;;QrIssuerPaymentMethod=;;QrFastMessageReferenceNo=;;QrFastParticipantReceiverCode=;;QrFastParticipantReceiverName=;;QrFastParticipantSenderCode=;;QrFastSenderIban=;;QrFastParticipantSenderName=;;QrFastPaymentResultDesc=', + 'expected' => [ + 'OrderId' => '33554969', + 'ProcReturnCode' => '00', + 'HostRefNum' => 'hostid', + 'AuthCode' => 'gizlendi', + 'TxnResult' => 'Success', + 'ErrorMessage' => '', + 'CampanyId' => '', + 'CampanyInstallCount' => '0', + 'CampanyShiftDateCount' => '0', + 'CampanyTxnId' => '', + 'CampanyType' => '', + 'CampanyInstallment' => '0', + 'CampanyDate' => '0', + 'CampanyAmnt' => '0', + 'TRXDATE' => '09.08.2024 10:40:34', + 'TransId' => 'gizlendi', + 'ErrorCode' => '', + 'EarnedBonus' => '0,00', + 'UsedBonus' => '0,00', + 'AvailableBonus' => '0,00', + 'BonusToBonus' => '0', + 'CampaignBonus' => '0,00', + 'FoldedBonus' => '0', + 'SurchargeAmount' => '0', + 'Amount' => '1,00', + 'CardHolderName' => 'gizlendi', + 'QrReferenceNumber' => '', + 'QrCardToken' => '', + 'QrData' => '', + 'QrPayIsSucess' => 'False', + 'QrIssuerPaymentMethod' => '', + 'QrFastMessageReferenceNo' => '', + 'QrFastParticipantReceiverCode' => '', + 'QrFastParticipantReceiverName' => '', + 'QrFastParticipantSenderCode' => '', + 'QrFastSenderIban' => '', + 'QrFastParticipantSenderName' => '', + 'QrFastPaymentResultDesc' => '', + ], + ], + ]; + } }