Skip to content

Commit

Permalink
remove connector_transaction_id in capture error
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshayaFoiger committed Dec 4, 2023
1 parent e721317 commit ae27a4f
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 15 deletions.
44 changes: 42 additions & 2 deletions crates/router/src/connector/bankofamerica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down Expand Up @@ -362,7 +362,47 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
&self,
res: Response,
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
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::<Vec<_>>()
.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,
})
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ impl<F>
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
}),
Expand Down Expand Up @@ -664,7 +664,7 @@ impl<F>
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
}),
Expand Down Expand Up @@ -967,6 +967,7 @@ pub enum Reason {
SystemError,
ServerTimeout,
ServiceTimeout,
ExceedsAuthAmount,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down
85 changes: 82 additions & 3 deletions crates/router/src/connector/cybersource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down Expand Up @@ -322,7 +322,45 @@ impl
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
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::<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: response.id,
})
}
}

Expand Down Expand Up @@ -425,6 +463,7 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
http_code: res.status_code,
},
true,
false,
))
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
Expand Down Expand Up @@ -611,6 +650,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
http_code: res.status_code,
},
is_auto_capture,
true,
))
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
Expand All @@ -619,7 +659,45 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
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::<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: response.id,
})
}
}

Expand Down Expand Up @@ -694,6 +772,7 @@ impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsR
http_code: res.status_code,
},
false,
false,
))
.change_context(errors::ConnectorError::ResponseHandlingFailed)
}
Expand Down
28 changes: 20 additions & 8 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ impl<F, T>
TryFrom<(
types::ResponseRouterData<F, CybersourcePaymentsResponse, T, types::PaymentsResponseData>,
bool,
bool,
)> for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
Expand All @@ -543,10 +544,12 @@ impl<F, T>
types::PaymentsResponseData,
>,
bool,
bool,
),
) -> Result<Self, Self::Error> {
let item = data.0;
let is_capture = data.1;
let is_auth_call = data.2;
let mandate_reference =
item.response
.token_information
Expand All @@ -558,14 +561,22 @@ impl<F, T>
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(),
Expand Down Expand Up @@ -755,6 +766,7 @@ pub enum Reason {
SystemError,
ServerTimeout,
ServiceTimeout,
ExceedsAuthAmount,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down

0 comments on commit ae27a4f

Please sign in to comment.