From 09248b6a409a9ddba04ad8e1ca01f3417c773277 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 21 Jan 2024 20:49:55 +0100 Subject: [PATCH] ran rector --- .../EstPosResponseDataMapper.php | 9 ++++++--- .../GarantiPosResponseDataMapper.php | 1 + .../KuveytPosResponseDataMapper.php | 1 + .../PayFlexV4PosResponseDataMapper.php | 1 + .../PayForPosResponseDataMapper.php | 4 ++++ .../PosNetResponseDataMapper.php | 2 ++ .../PosNetV1PosResponseDataMapper.php | 1 + tests/Functional/PaymentTestTrait.php | 1 + .../AkOdePosResponseDataMapperTest.php | 2 ++ .../EstPosResponseDataMapperTest.php | 5 ++++- .../GarantiPosResponseDataMapperTest.php | 4 +++- .../PayForPosResponseDataMapperTest.php | 16 ++++++++-------- 12 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php index 366713b7..946a3dd6 100644 --- a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php @@ -329,6 +329,7 @@ public function mapStatusResponse(array $rawResponseData): array if (isset($extra['RECURRINGID'])) { return $this->mapRecurringStatusResponse($rawResponseData); } + $defaultResponse = $this->getDefaultStatusResponse($rawResponseData); $defaultResponse['order_id'] = $rawResponseData['OrderId']; @@ -405,10 +406,10 @@ public function mapHistoryResponse(array $rawResponseData): array $transactions = []; $i = 1; - while (isset($rawResponseData['Extra']["TRX$i"])) { - $rawTx = \explode("\t", $rawResponseData['Extra']["TRX$i"]); + while (isset($rawResponseData['Extra']['TRX'.$i])) { + $rawTx = \explode("\t", $rawResponseData['Extra']['TRX'.$i]); $transactions[] = $this->mapSingleHistoryTransaction($rawTx); - $i++; + ++$i; } return [ @@ -493,6 +494,7 @@ private function mapSingleHistoryTransaction(array $rawTx): array if (self::PROCEDURE_SUCCESS_CODE === $transaction['proc_return_code']) { $transaction['status'] = self::TX_APPROVED; } + $transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']); $transaction['trans_id'] = $rawTx[10]; /** @@ -525,6 +527,7 @@ private function mapSingleRecurringOrderStatus(array $extra, int $i): array } elseif (null === $procReturnCode) { $status = null; } + $recurringOrder = [ 'order_id' => $extra[\sprintf('ORD_ID_%d', $i)], 'masked_number' => $extra[\sprintf('PAN_%d', $i)], diff --git a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php index 572ea871..afcb1431 100644 --- a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php @@ -251,6 +251,7 @@ public function mapStatusResponse(array $rawResponseData): array if ('WAITINGPOSTAUTH' === $orderInqResult['Status']) { $orderStatus = PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; } + $result = [ 'order_id' => $rawResponseData['Order']['OrderID'] ?? null, 'auth_code' => $orderInqResult['AuthCode'] ?? null, diff --git a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php index ed4bebd7..67a3f370 100644 --- a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php @@ -153,6 +153,7 @@ public function mapStatusResponse(array $rawResponseData): array if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { $status = self::TX_APPROVED; } + $defaultResponse['status'] = $status; $defaultResponse['proc_return_code'] = $procReturnCode; diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php index 4b00907b..5f77f77e 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php @@ -154,6 +154,7 @@ public function mapStatusResponse(array $rawResponseData): array if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { $status = self::TX_APPROVED; } + $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode); if (self::TX_DECLINED === $status) { diff --git a/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php index 5553e67f..71919cb2 100644 --- a/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php @@ -258,9 +258,11 @@ public function mapStatusResponse(array $rawResponseData): array if ('true' === $rawResponseData['IsVoided']) { $orderStatus = PosInterface::PAYMENT_STATUS_CANCELED; } + if ('true' === $rawResponseData['IsRefunded']) { $orderStatus = PosInterface::PAYMENT_STATUS_FULLY_REFUNDED; } + $defaultResponse['order_status'] = $orderStatus; } else { $defaultResponse['error_message'] = $rawResponseData['ErrMsg']; @@ -289,6 +291,7 @@ public function mapHistoryResponse(array $rawResponseData): array $status = self::TX_APPROVED; $mappedTransactions[] = $this->mapSingleHistoryTransaction($paymentRequest); } + $orderId = $paymentRequest['OrderId']; } else { foreach ($rawResponseData['PaymentRequestExtended'] as $tx) { @@ -481,6 +484,7 @@ private function mapSingleHistoryTransaction(array $rawTx): array $defaultResponse['capture'] = false; $orderStatus = PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; } + $defaultResponse['order_status'] = $orderStatus; } diff --git a/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php index d3a346e8..05532900 100644 --- a/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php @@ -98,6 +98,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && $this->getStatusDetail($procReturnCode) === self::TX_APPROVED) { $status = self::TX_APPROVED; } + $defaultResponse = $this->getDefaultPaymentResponse($txType, PosInterface::MODEL_3D_SECURE); if (!isset($raw3DAuthResponseData['oosResolveMerchantDataResponse'])) { @@ -231,6 +232,7 @@ public function mapStatusResponse(array $rawResponseData): array if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && isset($rawResponseData['transactions']) && !$errorCode) { $status = self::TX_APPROVED; } + $txResults = []; $defaultResponse = $this->getDefaultStatusResponse($rawResponseData); diff --git a/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php index 855bc0a5..9bb72eb5 100644 --- a/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php @@ -235,6 +235,7 @@ public function mapStatusResponse(array $rawResponseData): array break; } } + if (null === $rawTx) { return $defaultResponse; } diff --git a/tests/Functional/PaymentTestTrait.php b/tests/Functional/PaymentTestTrait.php index b79e49b0..b5b26d10 100644 --- a/tests/Functional/PaymentTestTrait.php +++ b/tests/Functional/PaymentTestTrait.php @@ -193,6 +193,7 @@ private function createHistoryOrder(string $gatewayClass, array $lastResponse, a 'pageSize' => 10, // optional, default: 10 ]; } + if (PayForPos::class === $gatewayClass) { if (isset($extraData['reqDate'])) { $order = [ diff --git a/tests/Unit/DataMapper/ResponseDataMapper/AkOdePosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/AkOdePosResponseDataMapperTest.php index 40b0d2e8..8fc84c06 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/AkOdePosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/AkOdePosResponseDataMapperTest.php @@ -130,6 +130,7 @@ public function testMapHistoryResponse(array $responseData, array $expectedData) $actualData['transactions'][1]['trans_time'], ); } + foreach ($responseData['Transactions'] as $key => $tx) { if (isset($tx['CreateDate'])) { $this->assertSame($actualData['transactions'][$key]['trans_time']->format('YmdHis'), $tx['CreateDate']); @@ -137,6 +138,7 @@ public function testMapHistoryResponse(array $responseData, array $expectedData) unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']); unset($actualData['transactions'][$key]['capture_time'], $expectedData['transactions'][$key]['capture_time']); } + \ksort($actualData['transactions'][$key]); \ksort($expectedData['transactions'][$key]); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php index 19f20b60..1f842075 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php @@ -156,15 +156,18 @@ public function testMapHistoryResponse(array $responseData, array $expectedData) $actualData['transactions'][1]['trans_time'], ); } - foreach ($actualData['transactions'] as $key => $tx) { + + foreach (array_keys($actualData['transactions']) as $key) { $this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time']); $this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time']); unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']); \ksort($actualData['transactions'][$key]); \ksort($expectedData['transactions'][$key]); } + $this->assertCount($actualData['trans_count'], $actualData['transactions']); } + unset($actualData['all']); \ksort($expectedData); \ksort($actualData); diff --git a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php index 60dfc42d..213977a2 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php @@ -106,7 +106,8 @@ public function testMapHistoryResponse(array $responseData, array $expectedData) $actualData['transactions'][1]['trans_time'], ); } - foreach ($actualData['transactions'] as $key => $tx) { + + foreach (array_keys($actualData['transactions']) as $key) { $this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time']); $this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time']); unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']); @@ -114,6 +115,7 @@ public function testMapHistoryResponse(array $responseData, array $expectedData) \ksort($actualData['transactions'][$key]); \ksort($expectedData['transactions'][$key]); } + $this->assertCount($actualData['trans_count'], $actualData['transactions']); unset($actualData['all']); diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php index 6f80eef2..bfd72627 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php @@ -121,9 +121,9 @@ public function testMapHistoryResponse(array $responseData, array $expectedData) $this->assertCount($actualData['trans_count'], $actualData['transactions']); - foreach ($actualData['transactions'] as $key => $tx) { - $this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time'], "tx: $key"); - $this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time'], "tx: $key"); + foreach (array_keys($actualData['transactions']) as $key) { + $this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time'], 'tx: '.$key); + $this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time'], 'tx: '.$key); unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']); unset($actualData['transactions'][$key]['capture_time'], $expectedData['transactions'][$key]['capture_time']); \ksort($actualData['transactions'][$key]); @@ -2172,7 +2172,7 @@ public static function historyTestDataProvider(): array 'status' => 'approved', 'error_code' => null, 'status_detail' => 'approved', - 'capture' => false, + 'capture' => false, 'currency' => 'TRY', 'masked_number' => '415565******6111', ], @@ -2217,7 +2217,7 @@ public static function historyTestDataProvider(): array ], ], ], - 'success_pay' => [ + 'success_pay' => [ 'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/success_pay_response.json'), true), 'expectedData' => [ 'order_id' => '202401212A22', @@ -2250,7 +2250,7 @@ public static function historyTestDataProvider(): array ], ], ], - 'success_pre_pay' => [ + 'success_pre_pay' => [ 'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/success_pre_pay_response.json'), true), 'expectedData' => [ 'order_id' => '2024012186F9', @@ -2283,7 +2283,7 @@ public static function historyTestDataProvider(): array ], ], ], - 'success_pay_refund_fail' => [ + 'success_pay_refund_fail' => [ 'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/success_pay_refund_fail_response.json'), true), 'expectedData' => [ 'order_id' => '202401211C79', @@ -2335,7 +2335,7 @@ public static function historyTestDataProvider(): array ], ], ], - 'fail_order_not_found' => [ + 'fail_order_not_found' => [ 'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/fail_order_not_found_response.json'), true), 'expectedData' => [ 'order_id' => '202401010C2022',