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