mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
refactor(router): miscellaneous cleanups (#134)
This commit is contained in:
@ -162,27 +162,7 @@ impl
|
||||
&self,
|
||||
res: Bytes,
|
||||
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
|
||||
let response: authorizedotnet::AuthorizedotnetPaymentsResponse = res
|
||||
.parse_struct("AuthorizedotnetPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
|
||||
let error = response
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.first().map(|error| types::ErrorResponse {
|
||||
code: error.error_code.clone(),
|
||||
message: error.error_text.clone(),
|
||||
reason: None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| types::ErrorResponse {
|
||||
code: consts::NO_ERROR_CODE.to_string(),
|
||||
message: consts::NO_ERROR_MESSAGE.to_string(),
|
||||
reason: None,
|
||||
});
|
||||
|
||||
Ok(error)
|
||||
get_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,27 +262,7 @@ impl
|
||||
&self,
|
||||
res: Bytes,
|
||||
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
|
||||
let response: authorizedotnet::AuthorizedotnetPaymentsResponse = res
|
||||
.parse_struct("AuthorizedotnetPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
|
||||
let error = response
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.first().map(|error| types::ErrorResponse {
|
||||
code: error.error_code.clone(),
|
||||
message: error.error_text.clone(),
|
||||
reason: None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| types::ErrorResponse {
|
||||
code: consts::NO_ERROR_CODE.to_string(),
|
||||
message: consts::NO_ERROR_MESSAGE.to_string(),
|
||||
reason: None,
|
||||
});
|
||||
|
||||
Ok(error)
|
||||
get_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,27 +353,7 @@ impl
|
||||
&self,
|
||||
res: Bytes,
|
||||
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
|
||||
let response: authorizedotnet::AuthorizedotnetPaymentsResponse = res
|
||||
.parse_struct("AuthorizedotnetPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
|
||||
let error = response
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.first().map(|error| types::ErrorResponse {
|
||||
code: error.error_code.clone(),
|
||||
message: error.error_text.clone(),
|
||||
reason: None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| types::ErrorResponse {
|
||||
code: consts::NO_ERROR_CODE.to_string(),
|
||||
message: consts::NO_ERROR_MESSAGE.to_string(),
|
||||
reason: None,
|
||||
});
|
||||
|
||||
Ok(error)
|
||||
get_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -506,28 +446,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
|
||||
&self,
|
||||
res: Bytes,
|
||||
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
|
||||
let response: authorizedotnet::AuthorizedotnetPaymentsResponse = res
|
||||
.parse_struct("AuthorizedotnetPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
logger::info!(response=?res);
|
||||
|
||||
let error = response
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.first().map(|error| types::ErrorResponse {
|
||||
code: error.error_code.clone(),
|
||||
message: error.error_text.clone(),
|
||||
reason: None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| types::ErrorResponse {
|
||||
code: consts::NO_ERROR_CODE.to_string(),
|
||||
message: consts::NO_ERROR_MESSAGE.to_string(),
|
||||
reason: None,
|
||||
});
|
||||
|
||||
Ok(error)
|
||||
get_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,27 +534,7 @@ impl services::ConnectorIntegration<api::RSync, types::RefundsData, types::Refun
|
||||
&self,
|
||||
res: Bytes,
|
||||
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
|
||||
let response: authorizedotnet::AuthorizedotnetPaymentsResponse = res
|
||||
.parse_struct("AuthorizedotnetPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
|
||||
let error = response
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.first().map(|error| types::ErrorResponse {
|
||||
code: error.error_code.clone(),
|
||||
message: error.error_text.clone(),
|
||||
reason: None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| types::ErrorResponse {
|
||||
code: consts::NO_ERROR_CODE.to_string(),
|
||||
message: consts::NO_ERROR_MESSAGE.to_string(),
|
||||
reason: None,
|
||||
});
|
||||
|
||||
Ok(error)
|
||||
get_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -664,3 +563,28 @@ impl api::IncomingWebhook for Authorizedotnet {
|
||||
}
|
||||
|
||||
impl services::ConnectorRedirectResponse for Authorizedotnet {}
|
||||
|
||||
#[inline]
|
||||
fn get_error_response(bytes: Bytes) -> CustomResult<ErrorResponse, errors::ConnectorError> {
|
||||
let response: authorizedotnet::AuthorizedotnetPaymentsResponse = bytes
|
||||
.parse_struct("AuthorizedotnetPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
|
||||
logger::info!(response=?response);
|
||||
|
||||
Ok(response
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.into_iter().next().map(|error| types::ErrorResponse {
|
||||
code: error.error_code,
|
||||
message: error.error_text,
|
||||
reason: None,
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| types::ErrorResponse {
|
||||
code: consts::NO_ERROR_CODE.to_string(),
|
||||
message: consts::NO_ERROR_MESSAGE.to_string(),
|
||||
reason: None,
|
||||
}))
|
||||
}
|
||||
|
||||
@ -287,9 +287,9 @@ impl<F, T>
|
||||
.transaction_response
|
||||
.errors
|
||||
.and_then(|errors| {
|
||||
errors.first().map(|error| types::ErrorResponse {
|
||||
code: error.error_code.clone(),
|
||||
message: error.error_text.clone(),
|
||||
errors.into_iter().next().map(|error| types::ErrorResponse {
|
||||
code: error.error_code,
|
||||
message: error.error_text,
|
||||
reason: None,
|
||||
})
|
||||
});
|
||||
|
||||
@ -273,11 +273,12 @@ pub struct StripeMetadata {
|
||||
pub txn_uuid: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Default, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StripePaymentStatus {
|
||||
Succeeded,
|
||||
Failed,
|
||||
#[default]
|
||||
Processing,
|
||||
#[serde(rename = "requires_action")]
|
||||
RequiresCustomerAction,
|
||||
@ -288,13 +289,6 @@ pub enum StripePaymentStatus {
|
||||
RequiresCapture,
|
||||
}
|
||||
|
||||
// Default should be Processing
|
||||
impl Default for StripePaymentStatus {
|
||||
fn default() -> Self {
|
||||
StripePaymentStatus::Processing
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StripePaymentStatus> for enums::AttemptStatus {
|
||||
fn from(item: StripePaymentStatus) -> Self {
|
||||
match item {
|
||||
|
||||
@ -17,10 +17,11 @@ use crate::{
|
||||
|
||||
#[inline]
|
||||
fn create_merchant_api_key() -> String {
|
||||
let id = Uuid::new_v4().simple();
|
||||
match env::which() {
|
||||
Env::Development => format!("dev_{}", &Uuid::new_v4().simple().to_string()),
|
||||
Env::Production => format!("prd_{}", &Uuid::new_v4().simple().to_string()),
|
||||
Env::Sandbox => format!("snd_{}", &Uuid::new_v4().simple().to_string()),
|
||||
Env::Development => format!("dev_{id}"),
|
||||
Env::Production => format!("prd_{id}"),
|
||||
Env::Sandbox => format!("snd_{id}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user