Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(connector): [BOA/CYBERSOURCE] Update error handling (#3156)

DEEPANSHU BANSAL8e484ddab8d3
diff --git a/crates/router/src/connector/bankofamerica.rs b/crates/router/src/connector/bankofamerica.rs
index cac3bacc21..b13bb299c2 100644
--- a/crates/router/src/connector/bankofamerica.rs
+++ b/crates/router/src/connector/bankofamerica.rs
@@ -203,37 +203,50 @@ impl ConnectorCommon for Bankofamerica {
} 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::<Vec<_>>()
- .join(", "),
- None => message.clone(),
- };
-
- Ok(ErrorResponse {
- status_code: res.status_code,
- code,
- message,
- reason: Some(connector_reason),
- attempt_status: None,
- connector_transaction_id: None,
- })
+ match response {
+ transformers::BankOfAmericaErrorResponse::StandardError(response) => {
+ 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::<Vec<_>>()
+ .join(", "),
+ None => message.clone(),
+ };
+
+ Ok(ErrorResponse {
+ status_code: res.status_code,
+ code,
+ message,
+ reason: Some(connector_reason),
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ }
+ transformers::BankOfAmericaErrorResponse::AuthenticationError(response) => {
+ Ok(ErrorResponse {
+ status_code: res.status_code,
+ code: consts::NO_ERROR_CODE.to_string(),
+ message: response.response.rmsg.clone(),
+ reason: Some(response.response.rmsg),
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ }
+ }
}
}
diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs
index bbec902283..e7c0c7a579 100644
--- a/crates/router/src/connector/bankofamerica/transformers.rs
+++ b/crates/router/src/connector/bankofamerica/transformers.rs
@@ -1016,32 +1016,24 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, BankOfAmericaRsyncResp
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
-pub struct BankOfAmericaErrorResponse {
+pub struct BankOfAmericaStandardErrorResponse {
pub error_information: Option<ErrorInformation>,
pub status: Option<String>,
pub message: Option<String>,
- pub reason: Option<Reason>,
+ pub reason: Option<String>,
pub details: Option<Vec<Details>>,
}
-#[derive(Debug, Deserialize, strum::Display)]
-#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
-pub enum Reason {
- MissingField,
- InvalidData,
- DuplicateRequest,
- InvalidCard,
- AuthAlreadyReversed,
- CardTypeNotAccepted,
- InvalidMerchantConfiguration,
- ProcessorUnavailable,
- InvalidAmount,
- InvalidCardType,
- InvalidPaymentId,
- NotSupported,
- SystemError,
- ServerTimeout,
- ServiceTimeout,
+#[derive(Debug, Deserialize)]
+pub struct BankOfAmericaAuthenticationErrorResponse {
+ pub response: AuthenticationErrorInformation,
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(untagged)]
+pub enum BankOfAmericaErrorResponse {
+ StandardError(BankOfAmericaStandardErrorResponse),
+ AuthenticationError(BankOfAmericaAuthenticationErrorResponse),
}
#[derive(Debug, Deserialize, Clone)]
@@ -1056,3 +1048,8 @@ pub struct ErrorInformation {
pub message: String,
pub reason: String,
}
+
+#[derive(Debug, Default, Deserialize)]
+pub struct AuthenticationErrorInformation {
+ pub rmsg: String,
+}
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs
index 06be499fae..1347fbfc93 100644
--- a/crates/router/src/connector/cybersource.rs
+++ b/crates/router/src/connector/cybersource.rs
@@ -109,44 +109,60 @@ impl ConnectorCommon for Cybersource {
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
- let response: cybersource::ErrorResponse = res
+ let response: cybersource::CybersourceErrorResponse = 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::<Vec<_>>()
- .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: None,
- })
+ match response {
+ transformers::CybersourceErrorResponse::StandardError(response) => {
+ 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::<Vec<_>>()
+ .join(", "),
+ None => message.clone(),
+ };
+
+ Ok(types::ErrorResponse {
+ status_code: res.status_code,
+ code,
+ message,
+ reason: Some(connector_reason),
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ }
+ transformers::CybersourceErrorResponse::AuthenticationError(response) => {
+ Ok(types::ErrorResponse {
+ status_code: res.status_code,
+ code: consts::NO_ERROR_CODE.to_string(),
+ message: response.response.rmsg.clone(),
+ reason: Some(response.response.rmsg),
+ attempt_status: None,
+ connector_transaction_id: None,
+ })
+ }
+ }
}
}
diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs
index 21dbed5e5e..f99c90989d 100644
--- a/crates/router/src/connector/cybersource/transformers.rs
+++ b/crates/router/src/connector/cybersource/transformers.rs
@@ -1286,49 +1286,6 @@ impl<F>
}
}
-#[derive(Debug, Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ErrorResponse {
- pub error_information: Option<ErrorInformation>,
- pub status: Option<String>,
- pub message: Option<String>,
- pub reason: Option<Reason>,
- pub details: Option<Vec<Details>>,
-}
-
-#[derive(Debug, Deserialize, strum::Display)]
-#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
-pub enum Reason {
- MissingField,
- InvalidData,
- DuplicateRequest,
- InvalidCard,
- AuthAlreadyReversed,
- CardTypeNotAccepted,
- InvalidMerchantConfiguration,
- ProcessorUnavailable,
- InvalidAmount,
- InvalidCardType,
- InvalidPaymentId,
- NotSupported,
- SystemError,
- ServerTimeout,
- ServiceTimeout,
-}
-
-#[derive(Debug, Deserialize, Clone)]
-#[serde(rename_all = "camelCase")]
-pub struct Details {
- pub field: String,
- pub reason: String,
-}
-
-#[derive(Debug, Deserialize)]
-pub struct ErrorInformation {
- pub message: String,
- pub reason: String,
-}
-
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CybersourceRefundRequest {
@@ -1428,3 +1385,43 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, CybersourceRsyncRespon
})
}
}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CybersourceStandardErrorResponse {
+ pub error_information: Option<ErrorInformation>,
+ pub status: Option<String>,
+ pub message: Option<String>,
+ pub reason: Option<String>,
+ pub details: Option<Vec<Details>>,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct CybersourceAuthenticationErrorResponse {
+ pub response: AuthenticationErrorInformation,
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(untagged)]
+pub enum CybersourceErrorResponse {
+ StandardError(CybersourceStandardErrorResponse),
+ AuthenticationError(CybersourceAuthenticationErrorResponse),
+}
+
+#[derive(Debug, Deserialize, Clone)]
+#[serde(rename_all = "camelCase")]
+pub struct Details {
+ pub field: String,
+ pub reason: String,
+}
+
+#[derive(Debug, Default, Deserialize)]
+pub struct ErrorInformation {
+ pub message: String,
+ pub reason: String,
+}
+
+#[derive(Debug, Default, Deserialize)]
+pub struct AuthenticationErrorInformation {
+ pub rmsg: String,
+}