From a77233127ff4646ee0defd153b1595ecd382b9f0 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 17 May 2024 13:02:45 +0200 Subject: [PATCH] fix issue #207 - estpos undefined ERRORCODE index on refund --- .../EstPosResponseDataMapper.php | 5 +- .../EstPosResponseDataMapperTest.php | 99 +++++++++++++------ 2 files changed, 72 insertions(+), 32 deletions(-) diff --git a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php index bcee09d7..062965af 100644 --- a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php @@ -262,6 +262,9 @@ public function mapRefundResponse(array $rawResponseData): array $status = self::TX_APPROVED; } + $errorCode = $rawResponseData['Extra']['ERRORCODE'] ?? $rawResponseData['ERRORCODE']; + $errorCode = '' !== $errorCode ? $errorCode : null; + return [ 'order_id' => $rawResponseData['OrderId'], 'group_id' => $rawResponseData['GroupId'], @@ -270,7 +273,7 @@ public function mapRefundResponse(array $rawResponseData): array 'proc_return_code' => $procReturnCode, 'transaction_id' => $rawResponseData['TransId'], 'num_code' => $rawResponseData['Extra']['NUMCODE'], - 'error_code' => $rawResponseData['Extra']['ERRORCODE'], + 'error_code' => $errorCode, 'error_message' => $rawResponseData['ErrMsg'], 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php index aa966206..0e52bb88 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php @@ -1691,40 +1691,77 @@ public static function cancelTestDataProvider(): array public static function refundTestDataProvider(): array { - return - [ - 'fail1' => [ - 'responseData' => [ - 'OrderId' => '20221030B3FF', - 'GroupId' => '20221030B3FF', - 'Response' => 'Error', - 'AuthCode' => '', - 'HostRefNum' => '', - 'ProcReturnCode' => '99', - 'TransId' => '22303M8rC11328', - 'ErrMsg' => 'Iade yapilamaz, siparis gunsonuna girmemis.', - 'Extra' => [ - 'SETTLEID' => '', - 'TRXDATE' => '20221030 12:58:42', - 'ERRORCODE' => 'CORE-2508', - 'NUMCODE' => '992508', - ], + return [ + 'success1' => [ + 'responseData' => [ + 'OrderId' => 'df0e', + 'GroupId' => 'dfc36f0e', + 'Response' => 'Approved', + 'AuthCode' => '46', + 'HostRefNum' => '41', + 'ProcReturnCode' => '00', + 'TransId' => '24138', + 'ErrMsg' => '', + 'ERRORCODE' => '', + 'Extra' => [ + 'KULLANILANPUAN' => '000000000000', + 'CARDBRAND' => 'MASTERCARD', + 'CARDHOLDERNAME' => 'ME* DE*', + 'TRXDATE' => '20240517 13:30:43', + 'KULLANILABILIRPUAN' => '000000005450', + 'ACQSTAN' => '74', + 'KAZANILANPUAN' => '000000000000', + 'TRACEID' => 'e7ba2a6', + 'NUMCODE' => '00', + 'SETTLEID' => '', ], - 'expectedData' => [ - 'order_id' => '20221030B3FF', - 'group_id' => '20221030B3FF', - 'auth_code' => null, - 'ref_ret_num' => null, - 'proc_return_code' => '99', - 'transaction_id' => '22303M8rC11328', - 'num_code' => '992508', - 'error_code' => 'CORE-2508', - 'error_message' => 'Iade yapilamaz, siparis gunsonuna girmemis.', - 'status' => 'declined', - 'status_detail' => 'general_error', + ], + 'expectedData' => [ + 'order_id' => 'df0e', + 'group_id' => 'dfc36f0e', + 'auth_code' => '46', + 'ref_ret_num' => '41', + 'proc_return_code' => '00', + 'transaction_id' => '24138', + 'num_code' => '00', + 'error_code' => null, + 'error_message' => null, + 'status' => 'approved', + 'status_detail' => 'approved', + ], + ], + 'fail1' => [ + 'responseData' => [ + 'OrderId' => '20221030B3FF', + 'GroupId' => '20221030B3FF', + 'Response' => 'Error', + 'AuthCode' => '', + 'HostRefNum' => '', + 'ProcReturnCode' => '99', + 'TransId' => '22303M8rC11328', + 'ErrMsg' => 'Iade yapilamaz, siparis gunsonuna girmemis.', + 'Extra' => [ + 'SETTLEID' => '', + 'TRXDATE' => '20221030 12:58:42', + 'ERRORCODE' => 'CORE-2508', + 'NUMCODE' => '992508', ], ], - ]; + 'expectedData' => [ + 'order_id' => '20221030B3FF', + 'group_id' => '20221030B3FF', + 'auth_code' => null, + 'ref_ret_num' => null, + 'proc_return_code' => '99', + 'transaction_id' => '22303M8rC11328', + 'num_code' => '992508', + 'error_code' => 'CORE-2508', + 'error_message' => 'Iade yapilamaz, siparis gunsonuna girmemis.', + 'status' => 'declined', + 'status_detail' => 'general_error', + ], + ], + ]; } public static function orderHistoryTestDataProvider(): array