mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
fix(connector): [BOA] Display 2XX Failure Errors (#3200)
This commit is contained in:
@ -309,7 +309,7 @@ impl From<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ClientReferenceInformation {
|
pub struct ClientReferenceInformation {
|
||||||
code: Option<String>,
|
code: Option<String>,
|
||||||
@ -541,7 +541,7 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
pub enum BankofamericaPaymentStatus {
|
pub enum BankofamericaPaymentStatus {
|
||||||
Authorized,
|
Authorized,
|
||||||
@ -594,12 +594,13 @@ pub enum BankOfAmericaPaymentsResponse {
|
|||||||
ErrorInformation(BankOfAmericaErrorInformationResponse),
|
ErrorInformation(BankOfAmericaErrorInformationResponse),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct BankOfAmericaClientReferenceResponse {
|
pub struct BankOfAmericaClientReferenceResponse {
|
||||||
id: String,
|
id: String,
|
||||||
status: BankofamericaPaymentStatus,
|
status: BankofamericaPaymentStatus,
|
||||||
client_reference_information: ClientReferenceInformation,
|
client_reference_information: ClientReferenceInformation,
|
||||||
|
error_information: Option<BankOfAmericaErrorInformation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@ -609,12 +610,101 @@ pub struct BankOfAmericaErrorInformationResponse {
|
|||||||
error_information: BankOfAmericaErrorInformation,
|
error_information: BankOfAmericaErrorInformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct BankOfAmericaErrorInformation {
|
pub struct BankOfAmericaErrorInformation {
|
||||||
reason: Option<String>,
|
reason: Option<String>,
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_error_response_if_failure(
|
||||||
|
(info_response, status, http_code): (
|
||||||
|
&BankOfAmericaClientReferenceResponse,
|
||||||
|
enums::AttemptStatus,
|
||||||
|
u16,
|
||||||
|
),
|
||||||
|
) -> Option<types::ErrorResponse> {
|
||||||
|
if is_payment_failure(status) {
|
||||||
|
let (message, reason) = match info_response.error_information.as_ref() {
|
||||||
|
Some(error_info) => (
|
||||||
|
error_info
|
||||||
|
.message
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
|
||||||
|
error_info.reason.clone(),
|
||||||
|
),
|
||||||
|
None => (consts::NO_ERROR_MESSAGE.to_string(), None),
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(types::ErrorResponse {
|
||||||
|
code: consts::NO_ERROR_CODE.to_string(),
|
||||||
|
message,
|
||||||
|
reason,
|
||||||
|
status_code: http_code,
|
||||||
|
attempt_status: Some(enums::AttemptStatus::Failure),
|
||||||
|
connector_transaction_id: Some(info_response.id.clone()),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_payment_failure(status: enums::AttemptStatus) -> bool {
|
||||||
|
match status {
|
||||||
|
common_enums::AttemptStatus::AuthenticationFailed
|
||||||
|
| common_enums::AttemptStatus::AuthorizationFailed
|
||||||
|
| common_enums::AttemptStatus::CaptureFailed
|
||||||
|
| common_enums::AttemptStatus::VoidFailed
|
||||||
|
| common_enums::AttemptStatus::Failure => true,
|
||||||
|
common_enums::AttemptStatus::Started
|
||||||
|
| common_enums::AttemptStatus::RouterDeclined
|
||||||
|
| common_enums::AttemptStatus::AuthenticationPending
|
||||||
|
| common_enums::AttemptStatus::AuthenticationSuccessful
|
||||||
|
| common_enums::AttemptStatus::Authorized
|
||||||
|
| common_enums::AttemptStatus::Charged
|
||||||
|
| common_enums::AttemptStatus::Authorizing
|
||||||
|
| common_enums::AttemptStatus::CodInitiated
|
||||||
|
| common_enums::AttemptStatus::Voided
|
||||||
|
| common_enums::AttemptStatus::VoidInitiated
|
||||||
|
| common_enums::AttemptStatus::CaptureInitiated
|
||||||
|
| common_enums::AttemptStatus::AutoRefunded
|
||||||
|
| common_enums::AttemptStatus::PartialCharged
|
||||||
|
| common_enums::AttemptStatus::PartialChargedAndChargeable
|
||||||
|
| common_enums::AttemptStatus::Unresolved
|
||||||
|
| common_enums::AttemptStatus::Pending
|
||||||
|
| common_enums::AttemptStatus::PaymentMethodAwaited
|
||||||
|
| common_enums::AttemptStatus::ConfirmationAwaited
|
||||||
|
| common_enums::AttemptStatus::DeviceDataCollectionPending => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_payment_response(
|
||||||
|
(info_response, status, http_code): (
|
||||||
|
&BankOfAmericaClientReferenceResponse,
|
||||||
|
enums::AttemptStatus,
|
||||||
|
u16,
|
||||||
|
),
|
||||||
|
) -> Result<types::PaymentsResponseData, types::ErrorResponse> {
|
||||||
|
let error_response = get_error_response_if_failure((info_response, status, http_code));
|
||||||
|
match error_response {
|
||||||
|
Some(error) => Err(error),
|
||||||
|
None => Ok(types::PaymentsResponseData::TransactionResponse {
|
||||||
|
resource_id: types::ResponseId::ConnectorTransactionId(info_response.id.clone()),
|
||||||
|
redirection_data: None,
|
||||||
|
mandate_reference: None,
|
||||||
|
connector_metadata: None,
|
||||||
|
network_txn_id: None,
|
||||||
|
connector_response_reference_id: Some(
|
||||||
|
info_response
|
||||||
|
.client_reference_information
|
||||||
|
.code
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(info_response.id.clone()),
|
||||||
|
),
|
||||||
|
incremental_authorization_allowed: None,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<F>
|
impl<F>
|
||||||
TryFrom<
|
TryFrom<
|
||||||
types::ResponseRouterData<
|
types::ResponseRouterData<
|
||||||
@ -635,29 +725,18 @@ impl<F>
|
|||||||
>,
|
>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
match item.response {
|
match item.response {
|
||||||
BankOfAmericaPaymentsResponse::ClientReferenceInformation(info_response) => Ok(Self {
|
BankOfAmericaPaymentsResponse::ClientReferenceInformation(info_response) => {
|
||||||
status: enums::AttemptStatus::foreign_from((
|
let status = enums::AttemptStatus::foreign_from((
|
||||||
info_response.status,
|
info_response.status.clone(),
|
||||||
item.data.request.is_auto_capture()?,
|
item.data.request.is_auto_capture()?,
|
||||||
)),
|
));
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
let response = get_payment_response((&info_response, status, item.http_code));
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(
|
Ok(Self {
|
||||||
info_response.id.clone(),
|
status,
|
||||||
),
|
response,
|
||||||
redirection_data: None,
|
|
||||||
mandate_reference: None,
|
|
||||||
connector_metadata: 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
|
..item.data
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self {
|
BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self {
|
||||||
response: Err(types::ErrorResponse {
|
response: Err(types::ErrorResponse {
|
||||||
code: consts::NO_ERROR_CODE.to_string(),
|
code: consts::NO_ERROR_CODE.to_string(),
|
||||||
@ -697,26 +776,16 @@ impl<F>
|
|||||||
>,
|
>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
match item.response {
|
match item.response {
|
||||||
BankOfAmericaPaymentsResponse::ClientReferenceInformation(info_response) => Ok(Self {
|
BankOfAmericaPaymentsResponse::ClientReferenceInformation(info_response) => {
|
||||||
status: enums::AttemptStatus::foreign_from((info_response.status, true)),
|
let status =
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
enums::AttemptStatus::foreign_from((info_response.status.clone(), true));
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(
|
let response = get_payment_response((&info_response, status, item.http_code));
|
||||||
info_response.id.clone(),
|
Ok(Self {
|
||||||
),
|
status,
|
||||||
redirection_data: None,
|
response,
|
||||||
mandate_reference: None,
|
|
||||||
connector_metadata: 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
|
..item.data
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self {
|
BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self {
|
||||||
response: Err(types::ErrorResponse {
|
response: Err(types::ErrorResponse {
|
||||||
code: consts::NO_ERROR_CODE.to_string(),
|
code: consts::NO_ERROR_CODE.to_string(),
|
||||||
@ -755,26 +824,16 @@ impl<F>
|
|||||||
>,
|
>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
match item.response {
|
match item.response {
|
||||||
BankOfAmericaPaymentsResponse::ClientReferenceInformation(info_response) => Ok(Self {
|
BankOfAmericaPaymentsResponse::ClientReferenceInformation(info_response) => {
|
||||||
status: enums::AttemptStatus::foreign_from((info_response.status, false)),
|
let status =
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
enums::AttemptStatus::foreign_from((info_response.status.clone(), false));
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(
|
let response = get_payment_response((&info_response, status, item.http_code));
|
||||||
info_response.id.clone(),
|
Ok(Self {
|
||||||
),
|
status,
|
||||||
redirection_data: None,
|
response,
|
||||||
mandate_reference: None,
|
|
||||||
connector_metadata: 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
|
..item.data
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self {
|
BankOfAmericaPaymentsResponse::ErrorInformation(error_response) => Ok(Self {
|
||||||
response: Err(types::ErrorResponse {
|
response: Err(types::ErrorResponse {
|
||||||
code: consts::NO_ERROR_CODE.to_string(),
|
code: consts::NO_ERROR_CODE.to_string(),
|
||||||
@ -806,6 +865,7 @@ pub struct BankOfAmericaApplicationInfoResponse {
|
|||||||
id: String,
|
id: String,
|
||||||
application_information: ApplicationInformation,
|
application_information: ApplicationInformation,
|
||||||
client_reference_information: Option<ClientReferenceInformation>,
|
client_reference_information: Option<ClientReferenceInformation>,
|
||||||
|
error_information: Option<BankOfAmericaErrorInformation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@ -834,13 +894,40 @@ impl<F>
|
|||||||
>,
|
>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
match item.response {
|
match item.response {
|
||||||
BankOfAmericaTransactionResponse::ApplicationInformation(app_response) => Ok(Self {
|
BankOfAmericaTransactionResponse::ApplicationInformation(app_response) => {
|
||||||
status: enums::AttemptStatus::foreign_from((
|
let status = enums::AttemptStatus::foreign_from((
|
||||||
app_response.application_information.status,
|
app_response.application_information.status,
|
||||||
item.data.request.is_auto_capture()?,
|
item.data.request.is_auto_capture()?,
|
||||||
)),
|
));
|
||||||
|
if is_payment_failure(status) {
|
||||||
|
let (message, reason) = match app_response.error_information {
|
||||||
|
Some(error_info) => (
|
||||||
|
error_info
|
||||||
|
.message
|
||||||
|
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
|
||||||
|
error_info.reason,
|
||||||
|
),
|
||||||
|
None => (consts::NO_ERROR_MESSAGE.to_string(), None),
|
||||||
|
};
|
||||||
|
Ok(Self {
|
||||||
|
response: Err(types::ErrorResponse {
|
||||||
|
code: consts::NO_ERROR_CODE.to_string(),
|
||||||
|
message,
|
||||||
|
reason,
|
||||||
|
status_code: item.http_code,
|
||||||
|
attempt_status: Some(enums::AttemptStatus::Failure),
|
||||||
|
connector_transaction_id: Some(app_response.id),
|
||||||
|
}),
|
||||||
|
status: enums::AttemptStatus::Failure,
|
||||||
|
..item.data
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Ok(Self {
|
||||||
|
status,
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(app_response.id.clone()),
|
resource_id: types::ResponseId::ConnectorTransactionId(
|
||||||
|
app_response.id.clone(),
|
||||||
|
),
|
||||||
redirection_data: None,
|
redirection_data: None,
|
||||||
mandate_reference: None,
|
mandate_reference: None,
|
||||||
connector_metadata: None,
|
connector_metadata: None,
|
||||||
@ -852,7 +939,9 @@ impl<F>
|
|||||||
incremental_authorization_allowed: None,
|
incremental_authorization_allowed: None,
|
||||||
}),
|
}),
|
||||||
..item.data
|
..item.data
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
BankOfAmericaTransactionResponse::ErrorInformation(error_response) => Ok(Self {
|
BankOfAmericaTransactionResponse::ErrorInformation(error_response) => Ok(Self {
|
||||||
status: item.data.status,
|
status: item.data.status,
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user