diff --git a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php index 2c5165f0..5f9c3e47 100644 --- a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php @@ -88,7 +88,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType 'group_id' => $rawPaymentResponseData['GroupId'], 'transaction_id' => $rawPaymentResponseData['TransId'], 'transaction_time' => self::TX_APPROVED === $status ? new \DateTimeImmutable($extra['TRXDATE']) : null, - 'auth_code' => $rawPaymentResponseData['AuthCode'], + 'auth_code' => $rawPaymentResponseData['AuthCode'] ?? null, 'ref_ret_num' => $rawPaymentResponseData['HostRefNum'], 'proc_return_code' => $procReturnCode, 'status' => $status, @@ -262,20 +262,30 @@ public function mapRefundResponse(array $rawResponseData): array $status = self::TX_APPROVED; } - return [ + $result = [ 'order_id' => $rawResponseData['OrderId'], - 'group_id' => $rawResponseData['GroupId'], - 'auth_code' => $rawResponseData['AuthCode'], + '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' => $rawResponseData['Extra']['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; } /** @@ -305,20 +315,30 @@ public function mapCancelResponse(array $rawResponseData): array ]; } - return [ + $result = [ 'order_id' => $rawResponseData['OrderId'], - 'group_id' => $rawResponseData['GroupId'], - 'auth_code' => $rawResponseData['AuthCode'], + '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/src/Gateways/VakifKatilimPos.php b/src/Gateways/VakifKatilimPos.php index 7af9b902..795b5699 100644 --- a/src/Gateways/VakifKatilimPos.php +++ b/src/Gateways/VakifKatilimPos.php @@ -250,10 +250,6 @@ private function getRequestURIByTransactionType(string $txType, string $paymentM PosInterface::TX_TYPE_HISTORY => 'SelectOrder', ]; - if (!isset($arr[$txType])) { - throw new UnsupportedTransactionTypeException(); - } - if (\is_string($arr[$txType])) { return $arr[$txType]; } diff --git a/tests/Functional/EstV3PosTest.php b/tests/Functional/EstV3PosTest.php index 4d0e9e25..17cf8ea2 100644 --- a/tests/Functional/EstV3PosTest.php +++ b/tests/Functional/EstV3PosTest.php @@ -80,9 +80,9 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro $this->card ); - $this->assertTrue($this->pos->isSuccess()); - $response = $this->pos->getResponse(); + $this->assertTrue($this->pos->isSuccess(), $response['error_message'] ?? null); + $this->assertIsArray($response); $this->assertNotEmpty($response); $this->assertTrue($eventIsThrown); diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php index d81a6999..c75c6ce8 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php @@ -422,7 +422,7 @@ public static function paymentTestDataProvider(): iterable public static function threeDPaymentDataProvider(): array { return [ - '3d_auth_fail' => [ + '3d_auth_fail' => [ 'order' => [ 'currency' => PosInterface::CURRENCY_TRY, 'amount' => 1.01, @@ -497,7 +497,7 @@ public static function threeDPaymentDataProvider(): array 'installment_count' => 0, ], ], - '3d_auth_success_payment_fail' => [ + '3d_auth_success_payment_fail' => [ 'order' => [ 'currency' => PosInterface::CURRENCY_TRY, 'amount' => 1.01, @@ -591,7 +591,106 @@ public static function threeDPaymentDataProvider(): array 'payment_model' => '3d', ], ], - 'success1' => [ + '3d_auth_success_payment_fail_wong_cvv' => [ + 'order' => [ + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 1.01, + ], + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'threeDResponseData' => [ + 'TRANID' => '', + 'PAResSyntaxOK' => 'true', + 'firmaadi' => 'John Doe', + 'islemtipi' => 'Auth', + 'lang' => 'tr', + 'merchantID' => '190100000', + 'maskedCreditCard' => '4355 08** **** 4358', + 'amount' => '1.01', + 'sID' => '1', + 'ACQBIN' => '454672', + 'Ecom_Payment_Card_ExpDate_Year' => '26', + 'Email' => 'mail@customer.com', + 'MaskedPan' => '435508***4358', + 'merchantName' => 'Ziraat 3D', + 'clientIp' => '89.244.149.137', + 'okUrl' => 'http://localhost/akbank/3d/response.php', + 'md' => '435508:9716234382F9D9B630CC01452A6F160D31A2E1DBD41706C6AF8B8E6F730FE65D:3677:##190100000', + 'taksit' => '12', + 'Ecom_Payment_Card_ExpDate_Month' => '12', + 'storetype' => '3d', + 'mdErrorMsg' => 'Y-status/Challenge authentication via ACS: https://3ds-acs.test.modirum.com/mdpayacs/creq?token=214704701.1667119495.sIHzA7ckv-0', + 'PAResVerified' => 'true', + 'cavv' => 'ABABA##################AEJI=', + 'digest' => 'digest', + 'callbackCall' => 'true', + 'failUrl' => 'http://localhost/akbank/3d/response.php', + 'xid' => '2aeoSfQde3NyV2XjSeTL0sGNYSg=', + 'encoding' => 'ISO-8859-9', + 'currency' => '949', + 'oid' => '20221030FE4C', + 'mdStatus' => '1', + 'dsId' => '1', + 'eci' => '05', + 'version' => '2.0', + 'clientid' => '190100000', + 'txstatus' => 'Y', + 'HASH' => '+NYQKADaaWWUIAIg6U77nGIK+8k=', + 'rnd' => 'IXa1XnlaOxpMCacqG/cB', + 'HASHPARAMS' => 'clientid:oid:mdStatus:cavv:eci:md:rnd:', + 'HASHPARAMSVAL' => '19010000020221030FE4C1ABABA##################AEJI=05435508:9716234382F9D9B630CC01452A6F160D31A2E1DBD41706C6AF8B8E6F730FE65D:3677:##190100000IXa1XnlaOxpMCacqG/cB', + ], + 'paymentData' => [ + 'OrderId' => '4c4', + 'GroupId' => '4aa841c4', + 'Response' => 'Declined', + 'HostRefNum' => '4139489', + 'ProcReturnCode' => '82', + 'TransId' => '24138rt2596', + 'ErrMsg' => 'CVV Hatasi veya girilen CVV gecersiz.', + 'Extra' => [ + 'KULLANILANPUAN' => '000000000000', + 'CARDBRAND' => 'VISA', + 'CARDISSUER' => 'ZİRAAT BANKASI', + 'ERRORCODE' => 'ISO8583-82', + 'TRXDATE' => '20240517 13:17:31', + 'KULLANILABILIRPUAN' => '000000000000', + 'ACQSTAN' => '769489', + 'KAZANILANPUAN' => '000000000105', + 'TRACEID' => '2c4e0abd4560418ace038267fa57f5c9', + 'NUMCODE' => '82', + ], + ], + 'expectedData' => [ + 'transaction_id' => '24138rt2596', + 'transaction_type' => 'pay', + 'transaction_time' => null, + 'transaction_security' => 'Full 3D Secure', + 'md_status' => '1', + 'masked_number' => '4355 08** **** 4358', + 'month' => '12', + 'year' => '26', + 'amount' => 1.01, + 'currency' => PosInterface::CURRENCY_TRY, + 'eci' => '05', + 'tx_status' => null, + 'cavv' => 'ABABA##################AEJI=', + 'md_error_message' => null, + 'group_id' => '4aa841c4', + 'auth_code' => null, + 'ref_ret_num' => '4139489', + 'batch_num' => null, + 'proc_return_code' => '82', + 'status' => 'declined', + 'status_detail' => null, + 'error_code' => 'ISO8583-82', + 'error_message' => 'CVV Hatasi veya girilen CVV gecersiz.', + 'recurring_id' => null, + 'installment_count' => 12, + 'order_id' => '4c4', + 'payment_model' => '3d', + ], + ], + 'success1' => [ 'order' => [ 'currency' => PosInterface::CURRENCY_TRY, 'amount' => 1.01, @@ -1476,7 +1575,7 @@ public static function cancelTestDataProvider(): array { return [ - 'success1' => [ + 'success1' => [ 'responseData' => [ 'OrderId' => '20221030B3FF', 'GroupId' => '20221030B3FF', @@ -1512,7 +1611,44 @@ public static function cancelTestDataProvider(): array 'status_detail' => 'approved', ], ], - 'fail1' => [ + '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' => '', @@ -1537,14 +1673,44 @@ 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' => [ + 'responseData' => [ + 'OrderId' => 'a1a7d184', + 'GroupId' => 'a1a7d184', + 'Response' => 'Declined', + 'HostRefNum' => '413719757716', + 'ProcReturnCode' => '99', + 'TransId' => '', + 'ErrMsg' => 'İptal edilmeye uygun satış işlemi bulunamadı.', + 'Extra' => [ + 'TRXDATE' => '20240516 22:56:09', + 'EXTENDED_ERROR_CODE' => '215001', + 'TRACEID' => '3f423f86e9d886bf1cffae49d93268be', + 'NUMCODE' => '99', + 'ERRORCODE' => 'CORE-2008', + ], + ], + 'expectedData' => [ + 'order_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' => null, 'error_message' => 'İptal edilmeye uygun satış işlemi bulunamadı.', 'status' => 'declined', 'status_detail' => 'general_error', ], ], - [ - // recurring success case + 'success_recurring_1' => [ 'responseData' => [ 'RECURRINGOPERATION' => 'CANCEL', 'RECORDTYPE' => 'ORDER', @@ -1562,40 +1728,104 @@ 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' => null, + 'auth_code' => null, + 'ref_ret_num' => null, + 'proc_return_code' => '99', + 'transaction_id' => '22303M8rC11328', + '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, + ], + ], + ]; } public static function orderHistoryTestDataProvider(): array diff --git a/tests/Unit/Gateways/EstPosTest.php b/tests/Unit/Gateways/EstPosTest.php index f6baaeb0..3273fe3e 100644 --- a/tests/Unit/Gateways/EstPosTest.php +++ b/tests/Unit/Gateways/EstPosTest.php @@ -619,8 +619,8 @@ public static function cancelDataProvider(): array { return [ 'fail_1' => [ - 'bank_response' => EstPosResponseDataMapperTest::cancelTestDataProvider()['fail1']['responseData'], - 'expected_data' => EstPosResponseDataMapperTest::cancelTestDataProvider()['fail1']['expectedData'], + 'bank_response' => EstPosResponseDataMapperTest::cancelTestDataProvider()['fail_order_not_found_1']['responseData'], + 'expected_data' => EstPosResponseDataMapperTest::cancelTestDataProvider()['fail_order_not_found_1']['expectedData'], 'isSuccess' => false, ], 'success_1' => [