From 7685a933f0ebc87d31ce7e2b2b7d0016d6834119 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 1 Apr 2024 14:43:09 +0200 Subject: [PATCH] fix issue #196 PosNetV1 sending request to wrong url --- src/Gateways/PosNetV1Pos.php | 2 +- tests/Unit/Gateways/PosNetV1PosTest.php | 83 +++++++++++++++++-------- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/Gateways/PosNetV1Pos.php b/src/Gateways/PosNetV1Pos.php index cd3d9096..b046efec 100644 --- a/src/Gateways/PosNetV1Pos.php +++ b/src/Gateways/PosNetV1Pos.php @@ -158,7 +158,7 @@ public function orderHistory(array $order): PosInterface */ protected function send($contents, string $txType, string $paymentModel, ?string $url = null): array { - $url = $this->getApiURL(); + $url = $this->getApiURL($txType); $this->logger->debug('sending request', ['url' => $url]); if (!is_string($contents)) { diff --git a/tests/Unit/Gateways/PosNetV1PosTest.php b/tests/Unit/Gateways/PosNetV1PosTest.php index 3f117055..39de6f7e 100644 --- a/tests/Unit/Gateways/PosNetV1PosTest.php +++ b/tests/Unit/Gateways/PosNetV1PosTest.php @@ -68,11 +68,11 @@ protected function setUp(): void parent::setUp(); $this->config = [ - 'name' => 'Albaraka', - 'class' => PosNetV1Pos::class, - 'gateway_endpoints' => [ - 'payment_api' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', - 'gateway_3d' => 'https://epostest.albarakaturk.com.tr/ALBSecurePaymentUI/SecureProcess/SecureVerification.aspx', + 'name' => 'Albaraka', + 'class' => PosNetV1Pos::class, + 'gateway_endpoints' => [ + 'payment_api' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'gateway_3d' => 'https://epostest.albarakaturk.com.tr/ALBSecurePaymentUI/SecureProcess/SecureVerification.aspx', ], ]; @@ -145,11 +145,12 @@ public function testGetApiURL(string $txType, string $mappedTxType, string $expe */ public function testGet3DFormData( bool $isWithCard - ): void { - $card = $isWithCard ? $this->card : null; - $order = ['id' => '124']; + ): void + { + $card = $isWithCard ? $this->card : null; + $order = ['id' => '124']; $paymentModel = PosInterface::MODEL_3D_SECURE; - $txType = PosInterface::TX_TYPE_PAY_AUTH; + $txType = PosInterface::TX_TYPE_PAY_AUTH; $this->requestMapperMock->expects(self::once()) ->method('create3DFormData') @@ -202,6 +203,10 @@ public function testMake3DPayment( 'create3DPaymentRequestData', ]; if ($is3DSuccess) { + $this->requestMapperMock->expects(self::once()) + ->method('mapTxType') + ->with($txType) + ->willReturn('Sale'); $this->requestMapperMock->expects(self::once()) ->method('create3DPaymentRequestData') ->with($this->account, $order, $txType, $request->request->all()) @@ -209,7 +214,7 @@ public function testMake3DPayment( $this->prepareClient( $this->httpClientMock, 'response-body', - $this->config['gateway_endpoints']['payment_api'], + 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Sale', [ 'headers' => [ 'Content-Type' => 'application/json', @@ -270,11 +275,17 @@ public function testMake3DPayPayment(): void /** * @dataProvider makeRegularPaymentDataProvider */ - public function testMakeRegularPayment(array $order, string $txType, string $apiUrl): void + public function testMakeRegularPayment(array $order, string $txType, string $mappedTxType, string $apiUrl): void { $account = $this->pos->getAccount(); $card = $this->card; + $this->requestMapperMock->expects(self::once()) + ->method('mapTxType') + ->with($txType) + ->willReturn($mappedTxType); + + $this->requestMapperMock->expects(self::once()) ->method('createNonSecurePaymentRequestData') ->with($account, $order, $txType, $card) ->willReturn(['createNonSecurePaymentRequestData']); @@ -316,6 +327,11 @@ public function testMakeRegularPostAuthPayment(array $order, string $apiUrl): vo $account = $this->pos->getAccount(); $txType = PosInterface::TX_TYPE_PAY_POST_AUTH; + $this->requestMapperMock->expects(self::once()) + ->method('mapTxType') + ->with($txType) + ->willReturn('Capture'); + $this->requestMapperMock->expects(self::once()) ->method('createNonSecurePostAuthPaymentRequestData') ->with($account, $order) @@ -358,7 +374,12 @@ public function testMakeRegularPostAuthPayment(array $order, string $apiUrl): vo public function testStatusRequest(array $order, string $apiUrl): void { $account = $this->pos->getAccount(); - $txType = PosInterface::TX_TYPE_STATUS; + $txType = PosInterface::TX_TYPE_STATUS; + + $this->requestMapperMock->expects(self::once()) + ->method('mapTxType') + ->with($txType) + ->willReturn('TransactionInquiry'); $this->requestMapperMock->expects(self::once()) ->method('createStatusRequestData') @@ -402,7 +423,12 @@ public function testStatusRequest(array $order, string $apiUrl): void public function testCancelRequest(array $order, string $apiUrl): void { $account = $this->pos->getAccount(); - $txType = PosInterface::TX_TYPE_CANCEL; + $txType = PosInterface::TX_TYPE_CANCEL; + + $this->requestMapperMock->expects(self::once()) + ->method('mapTxType') + ->with($txType) + ->willReturn('Reverse'); $this->requestMapperMock->expects(self::once()) ->method('createCancelRequestData') @@ -445,7 +471,12 @@ public function testCancelRequest(array $order, string $apiUrl): void public function testRefundRequest(array $order, string $apiUrl): void { $account = $this->pos->getAccount(); - $txType = PosInterface::TX_TYPE_REFUND; + $txType = PosInterface::TX_TYPE_REFUND; + + $this->requestMapperMock->expects(self::once()) + ->method('mapTxType') + ->with($txType) + ->willReturn('Return'); $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') @@ -529,7 +560,7 @@ public static function getApiURLDataProvider(): iterable public static function make3DPaymentDataProvider(): array { - $dataSamples = iterator_to_array(PosNetV1PosResponseDataMapperTest::threeDPaymentDataProvider()); + $dataSamples = iterator_to_array(PosNetV1PosResponseDataMapperTest::threeDPaymentDataProvider()); return [ 'auth_fail' => [ @@ -574,18 +605,20 @@ public static function makeRegularPaymentDataProvider(): array { return [ [ - 'order' => [ + 'order' => [ 'id' => '2020110828BC', ], - 'txType' => PosInterface::TX_TYPE_PAY_AUTH, - 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'mappedTxType' => 'Sale', + 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Sale', ], [ - 'order' => [ + 'order' => [ 'id' => '2020110828BC', ], - 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, - 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, + 'mappedTxType' => 'Auth', + 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Auth', ], ]; } @@ -597,7 +630,7 @@ public static function makeRegularPostAuthPaymentDataProvider(): array 'order' => [ 'id' => '2020110828BC', ], - 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Capture', ], ]; } @@ -609,7 +642,7 @@ public static function statusRequestDataProvider(): array 'order' => [ 'id' => '2020110828BC', ], - 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/TransactionInquiry', ], ]; } @@ -621,7 +654,7 @@ public static function cancelRequestDataProvider(): array 'order' => [ 'id' => '2020110828BC', ], - 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Reverse', ], ]; } @@ -633,7 +666,7 @@ public static function refundRequestDataProvider(): array 'order' => [ 'id' => '2020110828BC', ], - 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc', + 'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Return', ], ]; }