Skip to content

Commit

Permalink
fix(connector): [BOA/CYBERSOURCE] Handle authentication error
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshu-iiitu committed Dec 18, 2023
1 parent d5135df commit fb9361d
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 84 deletions.
75 changes: 44 additions & 31 deletions crates/router/src/connector/bankofamerica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
reason: None,
attempt_status: None,
connector_transaction_id: None,
})
}
}
}
}

Expand Down
19 changes: 18 additions & 1 deletion crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,26 @@ 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<String>,
pub details: Option<Vec<Details>>,
}

#[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)]
#[serde(rename_all = "camelCase")]
pub struct Details {
Expand All @@ -1036,3 +1048,8 @@ pub struct ErrorInformation {
pub message: String,
pub reason: String,
}

#[derive(Debug, Default, Deserialize)]
pub struct AuthenticationErrorInformation {
pub rmsg: String,
}
74 changes: 45 additions & 29 deletions crates/router/src/connector/cybersource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
reason: None,
attempt_status: None,
connector_transaction_id: None,
})
}
}
}
}

Expand Down
63 changes: 40 additions & 23 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,29 +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<String>,
pub details: Option<Vec<Details>>,
}

#[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 {
Expand Down Expand Up @@ -1408,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,
}

0 comments on commit fb9361d

Please sign in to comment.