From 8122a40eecab1146f83fb49429da4203b91a9fa3 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 4 Dec 2023 12:42:39 +0530 Subject: [PATCH 1/8] add connector transaction id --- crates/router/src/connector/cybersource.rs | 2 +- crates/router/src/connector/cybersource/transformers.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs index 1de107af086d..0593d9f52769 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: None, + connector_transaction_id: response.id, }) } } diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 953f82c76a83..39eb77dd81b3 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -729,6 +729,7 @@ impl #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ErrorResponse { + pub id: Option, pub error_information: Option, pub status: Option, pub message: Option, From 1fc8307c0869d49df795319943d71e7154a9842d Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 4 Dec 2023 13:09:44 +0530 Subject: [PATCH 2/8] add connector transaction id to bank of america --- crates/router/src/connector/bankofamerica.rs | 2 +- crates/router/src/connector/bankofamerica/transformers.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/router/src/connector/bankofamerica.rs b/crates/router/src/connector/bankofamerica.rs index a01ea72338c5..fb04f7676af1 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: 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 e31a69669c6d..5c530f2a1728 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -941,6 +941,7 @@ impl TryFrom, pub error_information: Option, pub status: Option, pub message: Option, From e7213175af08ba8de94804d6337f76a39bfe64f3 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 4 Dec 2023 13:19:38 +0530 Subject: [PATCH 3/8] add connector transaction id for other calls --- crates/router/src/connector/bankofamerica/transformers.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 5c530f2a1728..1cc1e9bfadb7 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -548,7 +548,7 @@ impl reason: error_response.error_information.reason, status_code: item.http_code, attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: Some(error_response.id), }), ..item.data }), @@ -606,7 +606,7 @@ impl reason: error_response.error_information.reason, status_code: item.http_code, attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: Some(error_response.id), }), ..item.data }), @@ -664,7 +664,7 @@ impl reason: error_response.error_information.reason, status_code: item.http_code, attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: Some(error_response.id), }), ..item.data }), From ae27a4f4c5c59cc1c7a0656f9ac77a1597e69bab Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 4 Dec 2023 19:09:45 +0530 Subject: [PATCH 4/8] 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)] From d5ab9978337cb2b881b02e1c068510823acdb7da Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 4 Dec 2023 20:31:16 +0530 Subject: [PATCH 5/8] remove logger --- .../src/connector/cybersource/transformers.rs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 9ba9dcc80cdd..4b73296e12d8 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -561,22 +561,18 @@ impl Ok(Self { status, response: match item.response.error_information { - 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 - } + 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: if is_auth_call { + Some(item.response.id) + } else { + None + }, + }), _ => Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( item.response.id.clone(), From cdff9b3c8e586e25380c3d0f1dd41ed9337eade3 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 13 Dec 2023 12:03:52 +0530 Subject: [PATCH 6/8] introduce connector_metadata --- .../connector/bankofamerica/transformers.rs | 17 +++++++++++++-- .../src/connector/cybersource/transformers.rs | 21 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index eda854d47d3d..35506cbd7d81 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -1,6 +1,6 @@ use api_models::payments; use base64::Engine; -use common_utils::pii; +use common_utils::{pii, errors::CustomResult}; use masking::Secret; use serde::{Deserialize, Serialize}; @@ -571,6 +571,19 @@ pub struct BankOfAmericaErrorInformation { message: Option, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BOATransactionMetadata { + auth_id: String, +} + +pub fn get_connector_metadata( + auth_id: String +) -> CustomResult, errors::ConnectorError> { + common_utils::ext_traits::Encode::::encode_to_value( + &BOATransactionMetadata{auth_id} + ) +} + impl TryFrom< types::ResponseRouterData< @@ -602,7 +615,7 @@ impl ), redirection_data: None, mandate_reference: None, - connector_metadata: None, + connector_metadata: if item.data.request.is_auto_capture()? {get_connector_metadata(info_response.id.clone())} else {None}, network_txn_id: None, connector_response_reference_id: Some( info_response diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 669a6d6d8768..19ebde7edee3 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -1,5 +1,5 @@ use api_models::payments; -use common_utils::pii; +use common_utils::{pii, errors::CustomResult}; use masking::Secret; use serde::{Deserialize, Serialize}; @@ -612,6 +612,20 @@ pub struct CybersourceErrorInformation { message: String, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CybersourceTransactionMetadata { + auth_id: String, +} + +pub fn get_connector_metadata( + auth_id: String +) -> CustomResult, errors::ConnectorError> { + common_utils::ext_traits::Encode::::encode_to_value( + &CybersourceTransactionMetadata{auth_id} + ).change_context(errors::ConnectorError::ResponseHandlingFailed) +} + + impl TryFrom<( types::ResponseRouterData, @@ -643,6 +657,9 @@ impl payment_method_id: None, }); let status = get_payment_status(is_capture, item.response.status.into()); + + let connector_metadata = if is_auth_call && !is_capture {get_connector_metadata(item.response.id.clone())?} else {None}; + Ok(Self { status, response: match item.response.error_information { @@ -664,7 +681,7 @@ impl ), redirection_data: None, mandate_reference, - connector_metadata: None, + connector_metadata, network_txn_id: None, connector_response_reference_id: item .response From ddf9afd46fe54ce909c5a808a64ef442e8a90dbb Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 13 Dec 2023 14:42:25 +0530 Subject: [PATCH 7/8] fix get_connector_metadata() in trustpay --- .../connector/bankofamerica/transformers.rs | 51 +++++++++++-------- .../src/connector/cybersource/transformers.rs | 22 +++++--- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 35506cbd7d81..a58c55fa5411 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -1,6 +1,7 @@ use api_models::payments; use base64::Engine; -use common_utils::{pii, errors::CustomResult}; +use common_utils::{errors::CustomResult, pii}; +use error_stack::ResultExt; use masking::Secret; use serde::{Deserialize, Serialize}; @@ -577,11 +578,15 @@ pub struct BOATransactionMetadata { } pub fn get_connector_metadata( - auth_id: String + auth_id: String, ) -> CustomResult, errors::ConnectorError> { - common_utils::ext_traits::Encode::::encode_to_value( - &BOATransactionMetadata{auth_id} + Some( + common_utils::ext_traits::Encode::::encode_to_value( + &BOATransactionMetadata { auth_id }, + ), ) + .transpose() + .change_context(errors::ConnectorError::ResponseHandlingFailed) } impl @@ -609,22 +614,28 @@ impl info_response.status, item.data.request.is_auto_capture()?, )), - response: Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - info_response.id.clone(), - ), - redirection_data: None, - mandate_reference: None, - connector_metadata: if item.data.request.is_auto_capture()? {get_connector_metadata(info_response.id.clone())} else {None}, - network_txn_id: None, - connector_response_reference_id: Some( - info_response - .client_reference_information - .code - .unwrap_or(info_response.id), - ), - incremental_authorization_allowed: None, - }), + response: { + Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId( + info_response.id.clone(), + ), + redirection_data: None, + mandate_reference: None, + connector_metadata: if !item.data.request.is_auto_capture()? { + get_connector_metadata(info_response.id.clone())? + } else { + None + }, + network_txn_id: None, + connector_response_reference_id: Some( + info_response + .client_reference_information + .code + .unwrap_or(info_response.id), + ), + incremental_authorization_allowed: None, + }) + }, ..item.data }), BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self { diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 19ebde7edee3..ccd1ccc649fe 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -1,5 +1,6 @@ use api_models::payments; -use common_utils::{pii, errors::CustomResult}; +use common_utils::{errors::CustomResult, pii}; +use error_stack::ResultExt; use masking::Secret; use serde::{Deserialize, Serialize}; @@ -618,14 +619,17 @@ pub struct CybersourceTransactionMetadata { } pub fn get_connector_metadata( - auth_id: String + auth_id: String, ) -> CustomResult, errors::ConnectorError> { - common_utils::ext_traits::Encode::::encode_to_value( - &CybersourceTransactionMetadata{auth_id} - ).change_context(errors::ConnectorError::ResponseHandlingFailed) + Some(common_utils::ext_traits::Encode::< + CybersourceTransactionMetadata, + >::encode_to_value(&CybersourceTransactionMetadata { + auth_id, + })) + .transpose() + .change_context(errors::ConnectorError::ResponseHandlingFailed) } - impl TryFrom<( types::ResponseRouterData, @@ -658,7 +662,11 @@ impl }); let status = get_payment_status(is_capture, item.response.status.into()); - let connector_metadata = if is_auth_call && !is_capture {get_connector_metadata(item.response.id.clone())?} else {None}; + let connector_metadata = if is_auth_call && !is_capture { + get_connector_metadata(item.response.id.clone())? + } else { + None + }; Ok(Self { status, From c6592c0999ab9d76a3fd3492ed03edea0e650489 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 13 Dec 2023 16:22:32 +0530 Subject: [PATCH 8/8] update the error handler of auth and capture call --- crates/router/src/connector/bankofamerica.rs | 90 ++++++++++--------- .../connector/bankofamerica/transformers.rs | 2 +- crates/router/src/connector/cybersource.rs | 85 +++++++++--------- .../src/connector/cybersource/transformers.rs | 6 +- 4 files changed, 95 insertions(+), 88 deletions(-) diff --git a/crates/router/src/connector/bankofamerica.rs b/crates/router/src/connector/bankofamerica.rs index f21750cf1933..c55d2845f904 100644 --- a/crates/router/src/connector/bankofamerica.rs +++ b/crates/router/src/connector/bankofamerica.rs @@ -356,47 +356,7 @@ impl ConnectorIntegration CustomResult { - 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, - }) + build_auth_and_capture_error_response(res) } } @@ -557,7 +517,7 @@ impl ConnectorIntegration CustomResult { - self.build_error_response(res) + build_auth_and_capture_error_response(res) } } @@ -837,3 +797,49 @@ impl api::IncomingWebhook for Bankofamerica { Err(errors::ConnectorError::WebhooksNotImplemented).into_report() } } + +fn build_auth_and_capture_error_response( + res: Response, +) -> CustomResult { + 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 a58c55fa5411..0f9ae5f0ce1e 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -706,7 +706,7 @@ impl reason: error_response.error_information.reason, status_code: item.http_code, attempt_status: None, - connector_transaction_id: None, + connector_transaction_id: Some(error_response.id), }), ..item.data }), diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs index 83545682ccfe..e3e5e94a633e 100644 --- a/crates/router/src/connector/cybersource.rs +++ b/crates/router/src/connector/cybersource.rs @@ -464,7 +464,7 @@ impl ConnectorIntegration CustomResult { - self.build_error_response(res) + build_auth_and_capture_error_response(res) } } @@ -637,45 +637,7 @@ impl ConnectorIntegration CustomResult { - 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, - }) + build_auth_and_capture_error_response(res) } } @@ -1045,3 +1007,46 @@ impl api::IncomingWebhook for Cybersource { Err(errors::ConnectorError::WebhooksNotImplemented).into_report() } } + +fn build_auth_and_capture_error_response( + res: types::Response, +) -> CustomResult { + 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, + }) +} diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index ccd1ccc649fe..9049a0969f86 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -677,11 +677,7 @@ impl 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 - }, + connector_transaction_id: Some(item.response.id.clone()), }), _ => Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId(