From ae27a4f4c5c59cc1c7a0656f9ac77a1597e69bab Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 4 Dec 2023 19:09:45 +0530 Subject: [PATCH] remove connector_transaction_id in capture error --- crates/router/src/connector/bankofamerica.rs | 44 +++++++++- .../connector/bankofamerica/transformers.rs | 5 +- crates/router/src/connector/cybersource.rs | 85 ++++++++++++++++++- .../src/connector/cybersource/transformers.rs | 28 ++++-- 4 files changed, 147 insertions(+), 15 deletions(-) diff --git a/crates/router/src/connector/bankofamerica.rs b/crates/router/src/connector/bankofamerica.rs index fb04f7676af1..742141609f68 100644 --- a/crates/router/src/connector/bankofamerica.rs +++ b/crates/router/src/connector/bankofamerica.rs @@ -233,7 +233,7 @@ impl ConnectorCommon for Bankofamerica { message, reason: Some(connector_reason), attempt_status: None, - connector_transaction_id: response.id, + connector_transaction_id: None, }) } } @@ -362,7 +362,47 @@ impl ConnectorIntegration CustomResult { - self.build_error_response(res) + let response: bankofamerica::BankOfAmericaErrorResponse = res + .response + .parse_struct("BankOfAmerica ErrorResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + + let error_message = if res.status_code == 401 { + consts::CONNECTOR_UNAUTHORIZED_ERROR + } else { + consts::NO_ERROR_MESSAGE + }; + + let (code, message) = match response.error_information { + Some(ref error_info) => (error_info.reason.clone(), error_info.message.clone()), + None => ( + response + .reason + .map_or(consts::NO_ERROR_CODE.to_string(), |reason| { + reason.to_string() + }), + response + .message + .map_or(error_message.to_string(), |message| message), + ), + }; + let connector_reason = match response.details { + Some(details) => details + .iter() + .map(|det| format!("{} : {}", det.field, det.reason)) + .collect::>() + .join(", "), + None => message.clone(), + }; + + Ok(ErrorResponse { + status_code: res.status_code, + code, + message, + reason: Some(connector_reason), + attempt_status: None, + connector_transaction_id: response.id, + }) } } diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 1cc1e9bfadb7..3b19a0439b56 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -606,7 +606,7 @@ impl reason: error_response.error_information.reason, status_code: item.http_code, attempt_status: None, - connector_transaction_id: Some(error_response.id), + connector_transaction_id: None, }), ..item.data }), @@ -664,7 +664,7 @@ impl reason: error_response.error_information.reason, status_code: item.http_code, attempt_status: None, - connector_transaction_id: Some(error_response.id), + connector_transaction_id: None, }), ..item.data }), @@ -967,6 +967,7 @@ pub enum Reason { SystemError, ServerTimeout, ServiceTimeout, + ExceedsAuthAmount, } #[derive(Debug, Deserialize, Clone)] diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs index 0593d9f52769..7521189a3401 100644 --- a/crates/router/src/connector/cybersource.rs +++ b/crates/router/src/connector/cybersource.rs @@ -137,7 +137,7 @@ impl ConnectorCommon for Cybersource { message, reason: Some(connector_reason), attempt_status: None, - connector_transaction_id: response.id, + connector_transaction_id: None, }) } } @@ -322,7 +322,45 @@ impl &self, res: types::Response, ) -> CustomResult { - self.build_error_response(res) + let response: cybersource::ErrorResponse = res + .response + .parse_struct("Cybersource ErrorResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + let details = response.details.unwrap_or_default(); + let connector_reason = details + .iter() + .map(|det| format!("{} : {}", det.field, det.reason)) + .collect::>() + .join(", "); + + let error_message = if res.status_code == 401 { + consts::CONNECTOR_UNAUTHORIZED_ERROR + } else { + consts::NO_ERROR_MESSAGE + }; + + let (code, message) = match response.error_information { + Some(ref error_info) => (error_info.reason.clone(), error_info.message.clone()), + None => ( + response + .reason + .map_or(consts::NO_ERROR_CODE.to_string(), |reason| { + reason.to_string() + }), + response + .message + .map_or(error_message.to_string(), |message| message), + ), + }; + + Ok(types::ErrorResponse { + status_code: res.status_code, + code, + message, + reason: Some(connector_reason), + attempt_status: None, + connector_transaction_id: response.id, + }) } } @@ -425,6 +463,7 @@ impl ConnectorIntegration CustomResult { - self.build_error_response(res) + let response: cybersource::ErrorResponse = res + .response + .parse_struct("Cybersource ErrorResponse") + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + let details = response.details.unwrap_or_default(); + let connector_reason = details + .iter() + .map(|det| format!("{} : {}", det.field, det.reason)) + .collect::>() + .join(", "); + + let error_message = if res.status_code == 401 { + consts::CONNECTOR_UNAUTHORIZED_ERROR + } else { + consts::NO_ERROR_MESSAGE + }; + + let (code, message) = match response.error_information { + Some(ref error_info) => (error_info.reason.clone(), error_info.message.clone()), + None => ( + response + .reason + .map_or(consts::NO_ERROR_CODE.to_string(), |reason| { + reason.to_string() + }), + response + .message + .map_or(error_message.to_string(), |message| message), + ), + }; + + Ok(types::ErrorResponse { + status_code: res.status_code, + code, + message, + reason: Some(connector_reason), + attempt_status: None, + connector_transaction_id: response.id, + }) } } @@ -694,6 +772,7 @@ impl ConnectorIntegration TryFrom<( types::ResponseRouterData, bool, + bool, )> for types::RouterData { type Error = error_stack::Report; @@ -543,10 +544,12 @@ impl types::PaymentsResponseData, >, bool, + bool, ), ) -> Result { let item = data.0; let is_capture = data.1; + let is_auth_call = data.2; let mandate_reference = item.response .token_information @@ -558,14 +561,22 @@ impl Ok(Self { status, response: match item.response.error_information { - Some(error) => Err(types::ErrorResponse { - code: consts::NO_ERROR_CODE.to_string(), - message: error.message, - reason: Some(error.reason), - status_code: item.http_code, - attempt_status: None, - connector_transaction_id: Some(item.response.id), - }), + Some(error) => { + let result = Err(types::ErrorResponse { + code: consts::NO_ERROR_CODE.to_string(), + message: error.message, + reason: Some(error.reason), + status_code: item.http_code, + attempt_status: None, + connector_transaction_id: if is_auth_call { + Some(item.response.id) + } else { + None + }, + }); + + result + } _ => Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( item.response.id.clone(), @@ -755,6 +766,7 @@ pub enum Reason { SystemError, ServerTimeout, ServiceTimeout, + ExceedsAuthAmount, } #[derive(Debug, Deserialize, Clone)]