From 5d94ebb1046d796628534d7ff6077ba3ac5faa48 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 17 May 2024 13:53:59 +0200 Subject: [PATCH] fix issue #207 - estpos undefined index on cancel and refund --- .../EstPosResponseDataMapper.php | 43 +++++++--- .../EstPosResponseDataMapperTest.php | 82 +++++++++++++++++-- 2 files changed, 103 insertions(+), 22 deletions(-) diff --git a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php index 062965af..5f9c3e47 100644 --- a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php @@ -262,23 +262,30 @@ public function mapRefundResponse(array $rawResponseData): array $status = self::TX_APPROVED; } - $errorCode = $rawResponseData['Extra']['ERRORCODE'] ?? $rawResponseData['ERRORCODE']; - $errorCode = '' !== $errorCode ? $errorCode : null; - - return [ + $result = [ 'order_id' => $rawResponseData['OrderId'], - 'group_id' => $rawResponseData['GroupId'], - 'auth_code' => $rawResponseData['AuthCode'] ?? null, + 'group_id' => null, + 'auth_code' => null, 'ref_ret_num' => $rawResponseData['HostRefNum'], 'proc_return_code' => $procReturnCode, 'transaction_id' => $rawResponseData['TransId'], - 'num_code' => $rawResponseData['Extra']['NUMCODE'], - 'error_code' => $errorCode, + 'num_code' => null, + 'error_code' => null, 'error_message' => $rawResponseData['ErrMsg'], 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), 'all' => $rawResponseData, ]; + + if (self::TX_APPROVED === $status) { + $result['group_id'] = $rawResponseData['GroupId']; + $result['auth_code'] = $rawResponseData['AuthCode']; + $result['num_code'] = $rawResponseData['Extra']['NUMCODE']; + } else { + $result['error_code'] = $rawResponseData['Extra']['ERRORCODE'] ?? $rawResponseData['ERRORCODE'] ?? null; + } + + return $result; } /** @@ -308,20 +315,30 @@ public function mapCancelResponse(array $rawResponseData): array ]; } - return [ + $result = [ 'order_id' => $rawResponseData['OrderId'], - 'group_id' => $rawResponseData['GroupId'], - 'auth_code' => $rawResponseData['AuthCode'] ?? null, + 'group_id' => null, + 'auth_code' => null, 'ref_ret_num' => $rawResponseData['HostRefNum'], 'proc_return_code' => $procReturnCode, 'transaction_id' => $rawResponseData['TransId'], - 'error_code' => $rawResponseData['Extra']['ERRORCODE'], - 'num_code' => $rawResponseData['Extra']['NUMCODE'], + 'error_code' => null, + 'num_code' => null, 'error_message' => $rawResponseData['ErrMsg'], 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), 'all' => $rawResponseData, ]; + + if (self::TX_APPROVED === $status) { + $result['group_id'] = $rawResponseData['GroupId']; + $result['auth_code'] = $rawResponseData['AuthCode']; + $result['num_code'] = $rawResponseData['Extra']['NUMCODE']; + } else { + $result['error_code'] = $rawResponseData['Extra']['ERRORCODE'] ?? $rawResponseData['ERRORCODE'] ?? null; + } + + return $result; } /** diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php index 0e52bb88..c75c6ce8 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php @@ -1575,7 +1575,7 @@ public static function cancelTestDataProvider(): array { return [ - 'success1' => [ + 'success1' => [ 'responseData' => [ 'OrderId' => '20221030B3FF', 'GroupId' => '20221030B3FF', @@ -1611,7 +1611,44 @@ public static function cancelTestDataProvider(): array 'status_detail' => 'approved', ], ], - 'fail_order_not_found_1' => [ + 'success_without_extra_error_code' => [ + 'responseData' => [ + 'OrderId' => '230', + 'GroupId' => '800', + 'Response' => 'Approved', + 'AuthCode' => '160769', + 'HostRefNum' => '48', + 'ProcReturnCode' => '00', + 'TransId' => '2836', + 'ErrMsg' => '', + 'ERRORCODE' => '', + 'Extra' => [ + 'KULLANILANPUAN' => '000000000000', + 'CARDBRAND' => 'VISA', + 'TRXDATE' => '2017 13:14:06', + 'KULLANILABILIRPUAN' => '000000000380', + 'ACQSTAN' => '769388', + 'KAZANILANPUAN' => '000000000229', + 'TRACEID' => '4d68eab86e6', + 'NUMCODE' => '00', + 'SETTLEID' => '87', + ], + ], + 'expectedData' => [ + 'order_id' => '230', + 'group_id' => '800', + 'auth_code' => '160769', + 'ref_ret_num' => '48', + 'proc_return_code' => '00', + 'transaction_id' => '2836', + 'error_code' => null, + 'num_code' => '00', + 'error_message' => null, + 'status' => 'approved', + 'status_detail' => 'approved', + ], + ], + 'fail_order_not_found_1' => [ 'responseData' => [ 'OrderId' => '', 'GroupId' => '', @@ -1636,13 +1673,13 @@ public static function cancelTestDataProvider(): array 'proc_return_code' => '99', 'transaction_id' => '22303M5IA11121', 'error_code' => 'CORE-2008', - 'num_code' => '992008', + 'num_code' => null, 'error_message' => 'İptal edilmeye uygun satış işlemi bulunamadı.', 'status' => 'declined', 'status_detail' => 'general_error', ], ], - 'fail_order_not_found_2' => [ + 'fail_order_not_found_2' => [ 'responseData' => [ 'OrderId' => 'a1a7d184', 'GroupId' => 'a1a7d184', @@ -1661,19 +1698,19 @@ public static function cancelTestDataProvider(): array ], 'expectedData' => [ 'order_id' => 'a1a7d184', - 'group_id' => 'a1a7d184', + 'group_id' => null, 'auth_code' => null, 'ref_ret_num' => '413719757716', 'proc_return_code' => '99', 'transaction_id' => null, 'error_code' => 'CORE-2008', - 'num_code' => '99', + 'num_code' => null, 'error_message' => 'İptal edilmeye uygun satış işlemi bulunamadı.', 'status' => 'declined', 'status_detail' => 'general_error', ], ], - 'success_recurring_1' => [ + 'success_recurring_1' => [ 'responseData' => [ 'RECURRINGOPERATION' => 'CANCEL', 'RECORDTYPE' => 'ORDER', @@ -1749,18 +1786,45 @@ public static function refundTestDataProvider(): array ], 'expectedData' => [ 'order_id' => '20221030B3FF', - 'group_id' => '20221030B3FF', + 'group_id' => null, 'auth_code' => null, 'ref_ret_num' => null, 'proc_return_code' => '99', 'transaction_id' => '22303M8rC11328', - 'num_code' => '992508', + 'num_code' => null, 'error_code' => 'CORE-2508', 'error_message' => 'Iade yapilamaz, siparis gunsonuna girmemis.', 'status' => 'declined', 'status_detail' => 'general_error', ], ], + 'fail2' => [ + 'responseData' => [ + 'OrderId' => '2c544d', + 'Response' => 'Declined', + 'HostRefNum' => '413051', + 'TransId' => '24082', + 'ErrMsg' => 'Net Tutar 0.', + 'Extra' => [ + 'TRXDATE' => '20240517 14:28:33', + 'TRACEID' => '73631448ab0c1e', + 'ERRORCODE' => '215021', + ], + ], + 'expectedData' => [ + 'order_id' => '2c544d', + 'group_id' => null, + 'auth_code' => null, + 'ref_ret_num' => '413051', + 'proc_return_code' => null, + 'transaction_id' => '24082', + 'num_code' => null, + 'error_code' => '215021', + 'error_message' => 'Net Tutar 0.', + 'status' => 'declined', + 'status_detail' => null, + ], + ], ]; }