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): [ACI] Response Handling in case of `ErrorResponse` (#1870)

Sakil Mostak14f599d1be27
diff --git a/crates/router/src/connector/aci.rs b/crates/router/src/connector/aci.rs
index 80255985c2..ab6a6a4fb4 100644
--- a/crates/router/src/connector/aci.rs
+++ b/crates/router/src/connector/aci.rs
@@ -50,6 +50,33 @@ impl ConnectorCommon for Aci {
auth.api_key.into_masked(),
)])
}
+
+ fn build_error_response(
+ &self,
+ res: types::Response,
+ ) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
+ let response: aci::AciErrorResponse = res
+ .response
+ .parse_struct("AciErrorResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ Ok(types::ErrorResponse {
+ status_code: res.status_code,
+ code: response.result.code,
+ message: response.result.description,
+ reason: response.result.parameter_errors.map(|errors| {
+ errors
+ .into_iter()
+ .map(|error_description| {
+ format!(
+ "Field is {} and the message is {}",
+ error_description.name, error_description.message
+ )
+ })
+ .collect::<Vec<String>>()
+ .join("; ")
+ }),
+ })
+ }
}
impl api::Payment for Aci {}
@@ -198,23 +225,7 @@ impl
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
- let response: aci::AciPaymentsResponse =
- res.response
- .parse_struct("AciPaymentsResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- Ok(types::ErrorResponse {
- code: response.result.code,
- message: response.result.description,
- reason: response.result.parameter_errors.and_then(|errors| {
- errors.first().map(|error_description| {
- format!(
- "Field is {} and the message is {}",
- error_description.name, error_description.message
- )
- })
- }),
- status_code: res.status_code,
- })
+ self.build_error_response(res)
}
}
@@ -320,23 +331,7 @@ impl
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
- let response: aci::AciPaymentsResponse =
- res.response
- .parse_struct("AciPaymentsResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- Ok(types::ErrorResponse {
- status_code: res.status_code,
- code: response.result.code,
- message: response.result.description,
- reason: response.result.parameter_errors.and_then(|errors| {
- errors.first().map(|error_description| {
- format!(
- "Field is {} and the message is {}",
- error_description.name, error_description.message
- )
- })
- }),
- })
+ self.build_error_response(res)
}
}
@@ -425,23 +420,7 @@ impl
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
- let response: aci::AciPaymentsResponse =
- res.response
- .parse_struct("AciPaymentsResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- Ok(types::ErrorResponse {
- status_code: res.status_code,
- code: response.result.code,
- message: response.result.description,
- reason: response.result.parameter_errors.and_then(|errors| {
- errors.first().map(|error_description| {
- format!(
- "Field is {} and the message is {}",
- error_description.name, error_description.message
- )
- })
- }),
- })
+ self.build_error_response(res)
}
}
@@ -536,23 +515,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
&self,
res: types::Response,
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
- let response: aci::AciRefundResponse = res
- .response
- .parse_struct("AciRefundResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
- Ok(types::ErrorResponse {
- status_code: res.status_code,
- code: response.result.code,
- message: response.result.description,
- reason: response.result.parameter_errors.and_then(|errors| {
- errors.first().map(|error_description| {
- format!(
- "Field is {} and the message is {}",
- error_description.name, error_description.message
- )
- })
- }),
- })
+ self.build_error_response(res)
}
}
diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs
index 623ba5d51e..886008c46a 100644
--- a/crates/router/src/connector/aci/transformers.rs
+++ b/crates/router/src/connector/aci/transformers.rs
@@ -598,6 +598,15 @@ pub struct AciPaymentsResponse {
pub(super) redirect: Option<AciRedirectionData>,
}
+#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)]
+#[serde(rename_all = "camelCase")]
+pub struct AciErrorResponse {
+ ndc: String,
+ timestamp: String,
+ build_number: String,
+ pub(super) result: ResultCode,
+}
+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct AciRedirectionData {