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

chore: address Rust 1.77 clippy lints (#4172)

Chethan Raof213c51b3e5c
diff --git a/add_connector.md b/add_connector.md
index ac9d3f8d84..96724cb1b0 100644
--- a/add_connector.md
+++ b/add_connector.md
@@ -514,28 +514,23 @@ Within the `ConnectorIntegration` trait, you'll find the following methods imple
}
```
-- `get_request_body` method calls transformers where hyperswitch payment request data is transformed into connector payment request. For constructing the request body have a function `log_and_get_request_body` that allows generic argument which is the struct that is passed as the body for connector integration, and a function that can be use to encode it into String. We log the request in this function, as the struct will be intact and the masked values will be masked.
+- `get_request_body` method calls transformers where hyperswitch payment request data is transformed into connector payment request. If the conversion and construction processes are successful, the function wraps the constructed connector_req in a Box and returns it as `RequestContent::Json`. The `RequestContent` enum defines different types of request content that can be sent. It includes variants for JSON, form-urlencoded, XML, raw bytes, and potentially other formats.
```rust
fn get_request_body(
- &self,
- req: &types::PaymentsAuthorizeRouterData,
- _connectors: &settings::Connectors,
- ) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
- let connector_router_data = checkout::CheckoutRouterData::try_from((
- &self.get_currency_unit(),
- req.request.currency,
- req.request.amount,
- req,
- ))?;
- let connector_req = checkout::PaymentsRequest::try_from(&connector_router_data)?;
- let checkout_req = types::RequestBody::log_and_get_request_body(
- &connector_req,
- utils::Encode::encode_to_string_of_json,
- )
- .change_context(errors::ConnectorError::RequestEncodingFailed)?;
- Ok(Some(checkout_req))
- }
+ &self,
+ req: &types::PaymentsAuthorizeRouterData,
+ _connectors: &settings::Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_router_data = checkout::CheckoutRouterData::try_from((
+ &self.get_currency_unit(),
+ req.request.currency,
+ req.request.amount,
+ req,
+ ))?;
+ let connector_req = checkout::PaymentsRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
```
- `build_request` method assembles the API request by providing the method, URL, headers, and request body as parameters.
diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs
index 3dbab96408..b1a708f7a0 100644
--- a/crates/common_utils/src/lib.rs
+++ b/crates/common_utils/src/lib.rs
@@ -35,9 +35,6 @@ pub mod date_time {
},
OffsetDateTime, PrimitiveDateTime,
};
- /// Struct to represent milliseconds in time sensitive data fields
- #[derive(Debug)]
- pub struct Milliseconds(i32);
/// Enum to represent date formats
#[derive(Debug)]
diff --git a/crates/common_utils/src/request.rs b/crates/common_utils/src/request.rs
index dfd890df79..47f280bc57 100644
--- a/crates/common_utils/src/request.rs
+++ b/crates/common_utils/src/request.rs
@@ -1,10 +1,6 @@
use masking::{Maskable, Secret};
-#[cfg(feature = "logs")]
-use router_env::logger;
use serde::{Deserialize, Serialize};
-use crate::errors;
-
pub type Headers = std::collections::HashSet<(String, Maskable<String>)>;
#[derive(
@@ -64,6 +60,18 @@ pub enum RequestContent {
RawBytes(Vec<u8>),
}
+impl RequestContent {
+ pub fn get_inner_value(&self) -> Secret<String> {
+ match self {
+ Self::Json(i) => serde_json::to_string(&i).unwrap_or_default().into(),
+ Self::FormUrlEncoded(i) => serde_urlencoded::to_string(i).unwrap_or_default().into(),
+ Self::Xml(i) => quick_xml::se::to_string(&i).unwrap_or_default().into(),
+ Self::FormData(_) => String::new().into(),
+ Self::RawBytes(_) => String::new().into(),
+ }
+ }
+}
+
impl Request {
pub fn new(method: Method, url: &str) -> Self {
Self {
@@ -176,33 +184,3 @@ impl Default for RequestBuilder {
Self::new()
}
}
-
-#[derive(Clone, Debug)]
-pub struct RequestBody(Secret<String>);
-
-impl RequestBody {
- pub fn log_and_get_request_body<T, F>(
- body: T,
- encoder: F,
- ) -> errors::CustomResult<Self, errors::ParsingError>
- where
- F: FnOnce(T) -> errors::CustomResult<String, errors::ParsingError>,
- T: std::fmt::Debug,
- {
- #[cfg(feature = "logs")]
- logger::info!(connector_request_body=?body);
- Ok(Self(Secret::new(encoder(body)?)))
- }
-
- pub fn get_inner_value(request_body: RequestContent) -> Secret<String> {
- match request_body {
- RequestContent::Json(i) => serde_json::to_string(&i).unwrap_or_default().into(),
- RequestContent::FormUrlEncoded(i) => {
- serde_urlencoded::to_string(&i).unwrap_or_default().into()
- }
- RequestContent::Xml(i) => quick_xml::se::to_string(&i).unwrap_or_default().into(),
- RequestContent::FormData(_) => String::new().into(),
- RequestContent::RawBytes(_) => String::new().into(),
- }
- }
-}
diff --git a/crates/diesel_models/src/process_tracker.rs b/crates/diesel_models/src/process_tracker.rs
index 74fa75a275..0c6aaa5922 100644
--- a/crates/diesel_models/src/process_tracker.rs
+++ b/crates/diesel_models/src/process_tracker.rs
@@ -190,27 +190,6 @@ impl From<ProcessTrackerUpdate> for ProcessTrackerUpdateInternal {
}
}
-#[allow(dead_code)]
-pub struct SchedulerOptions {
- looper_interval: common_utils::date_time::Milliseconds,
- db_name: String,
- cache_name: String,
- schema_name: String,
- cache_expiry: i32,
- runners: Vec<String>,
- fetch_limit: i32,
- fetch_limit_product_factor: i32,
- query_order: String,
-}
-
-#[derive(Debug, Clone)]
-#[allow(dead_code)]
-pub struct ProcessData {
- db_name: String,
- cache_name: String,
- process_tracker: ProcessTracker,
-}
-
#[derive(
serde::Serialize,
serde::Deserialize,
diff --git a/crates/router/src/connector/bankofamerica.rs b/crates/router/src/connector/bankofamerica.rs
index fefc80f806..aac441201e 100644
--- a/crates/router/src/connector/bankofamerica.rs
+++ b/crates/router/src/connector/bankofamerica.rs
@@ -140,11 +140,7 @@ where
.chars()
.skip(base_url.len() - 1)
.collect();
- let sha256 = self.generate_digest(
- types::RequestBody::get_inner_value(boa_req)
- .expose()
- .as_bytes(),
- );
+ let sha256 = self.generate_digest(boa_req.get_inner_value().expose().as_bytes());
let signature = self.generate_signature(
auth,
host.to_string(),
diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs
index 01ce57d10e..8004b3b5a1 100644
--- a/crates/router/src/connector/checkout/transformers.rs
+++ b/crates/router/src/connector/checkout/transformers.rs
@@ -1345,7 +1345,7 @@ pub fn construct_file_upload_request(
request.file_key,
request
.file_type
- .to_string()
+ .as_ref()
.split('/')
.last()
.unwrap_or_default()
diff --git a/crates/router/src/connector/cryptopay.rs b/crates/router/src/connector/cryptopay.rs
index af33ae21d7..a3335b2e22 100644
--- a/crates/router/src/connector/cryptopay.rs
+++ b/crates/router/src/connector/cryptopay.rs
@@ -77,10 +77,11 @@ where
| common_utils::request::Method::Put
| common_utils::request::Method::Delete
| common_utils::request::Method::Patch => {
- let body =
- types::RequestBody::get_inner_value(self.get_request_body(req, connectors)?)
- .peek()
- .to_owned();
+ let body = self
+ .get_request_body(req, connectors)?
+ .get_inner_value()
+ .peek()
+ .to_owned();
let md5_payload = crypto::Md5
.generate_digest(body.as_bytes())
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs
index 2b9b45cdda..e89810e79c 100644
--- a/crates/router/src/connector/cybersource.rs
+++ b/crates/router/src/connector/cybersource.rs
@@ -241,11 +241,7 @@ where
.chars()
.skip(base_url.len() - 1)
.collect();
- let sha256 = self.generate_digest(
- types::RequestBody::get_inner_value(cybersource_req)
- .expose()
- .as_bytes(),
- );
+ let sha256 = self.generate_digest(cybersource_req.get_inner_value().expose().as_bytes());
let http_method = self.get_http_method();
let signature = self.generate_signature(
auth,
diff --git a/crates/router/src/connector/dlocal.rs b/crates/router/src/connector/dlocal.rs
index 9fdb36ea1d..b158f239fd 100644
--- a/crates/router/src/connector/dlocal.rs
+++ b/crates/router/src/connector/dlocal.rs
@@ -68,9 +68,7 @@ where
"{}{}{}",
auth.x_login.peek(),
date,
- types::RequestBody::get_inner_value(dlocal_req)
- .peek()
- .to_owned()
+ dlocal_req.get_inner_value().peek().to_owned()
);
let authz = crypto::HmacSha256::sign_message(
&crypto::HmacSha256,
diff --git a/crates/router/src/connector/fiserv.rs b/crates/router/src/connector/fiserv.rs
index 7db63f5eee..fdd904ee73 100644
--- a/crates/router/src/connector/fiserv.rs
+++ b/crates/router/src/connector/fiserv.rs
@@ -78,7 +78,7 @@ where
.generate_authorization_signature(
auth,
&client_request_id,
- types::RequestBody::get_inner_value(fiserv_req).peek(),
+ fiserv_req.get_inner_value().peek(),
timestamp,
)
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
diff --git a/crates/router/src/connector/payeezy.rs b/crates/router/src/connector/payeezy.rs
index 04f180efd0..d24a42085a 100644
--- a/crates/router/src/connector/payeezy.rs
+++ b/crates/router/src/connector/payeezy.rs
@@ -44,8 +44,10 @@ where
connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
let auth = payeezy::PayeezyAuthType::try_from(&req.connector_auth_type)?;
- let request_payload =
- types::RequestBody::get_inner_value(self.get_request_body(req, connectors)?).expose();
+ let request_payload = self
+ .get_request_body(req, connectors)?
+ .get_inner_value()
+ .expose();
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.ok()
diff --git a/crates/router/src/connector/rapyd.rs b/crates/router/src/connector/rapyd.rs
index b487740d07..fd6de25304 100644
--- a/crates/router/src/connector/rapyd.rs
+++ b/crates/router/src/connector/rapyd.rs
@@ -222,7 +222,7 @@ impl
let auth: rapyd::RapydAuthType = rapyd::RapydAuthType::try_from(&req.connector_auth_type)?;
let body = types::PaymentsAuthorizeType::get_request_body(self, req, connectors)?;
- let req_body = types::RequestBody::get_inner_value(body).expose();
+ let req_body = body.get_inner_value().expose();
let signature =
self.generate_signature(&auth, "post", "/v1/payments", &req_body, &timestamp, &salt)?;
let headers = vec![
@@ -555,7 +555,7 @@ impl
req.request.connector_transaction_id
);
let body = types::PaymentsCaptureType::get_request_body(self, req, connectors)?;
- let req_body = types::RequestBody::get_inner_value(body).expose();
+ let req_body = body.get_inner_value().expose();
let signature =
self.generate_signature(&auth, "post", &url_path, &req_body, &timestamp, &salt)?;
let headers = vec![
@@ -691,7 +691,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
let salt = Alphanumeric.sample_string(&mut rand::thread_rng(), 12);
let body = types::RefundExecuteType::get_request_body(self, req, connectors)?;
- let req_body = types::RequestBody::get_inner_value(body).expose();
+ let req_body = body.get_inner_value().expose();
let auth: rapyd::RapydAuthType = rapyd::RapydAuthType::try_from(&req.connector_auth_type)?;
let signature =
self.generate_signature(&auth, "post", "/v1/refunds", &req_body, &timestamp, &salt)?;
diff --git a/crates/router/src/connector/riskified.rs b/crates/router/src/connector/riskified.rs
index 72a9f6dbdb..298f8fb156 100644
--- a/crates/router/src/connector/riskified.rs
+++ b/crates/router/src/connector/riskified.rs
@@ -63,7 +63,7 @@ where
let riskified_req = self.get_request_body(req, connectors)?;
- let binding = types::RequestBody::get_inner_value(riskified_req);
+ let binding = riskified_req.get_inner_value();
let payload = binding.peek();
let digest = self
diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs
index 2838edfbf9..6f022c9fca 100644
--- a/crates/router/src/core/mandate.rs
+++ b/crates/router/src/core/mandate.rs
@@ -400,7 +400,7 @@ where
resp.merchant_id.clone(),
resp.payment_id.clone(),
resp.connector.clone(),
- resp.request.get_setup_mandate_details().map(Clone::clone),
+ resp.request.get_setup_mandate_details().cloned(),
maybe_customer,
pm_id.get_required_value("payment_method_id")?,
mandate_ids,
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index 26f6d6db19..dd109e99cb 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -7,7 +7,6 @@ pub use api_models::enums::Connector;
use api_models::payments::CardToken;
#[cfg(feature = "payouts")]
pub use api_models::{enums::PayoutConnectors, payouts as payout_types};
-pub use common_utils::request::RequestBody;
use data_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent};
use diesel_models::enums;
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 67ad246ba7..e0ab813119 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -22,7 +22,7 @@ pub use api_models::{enums::Connector, mandates};
#[cfg(feature = "payouts")]
pub use api_models::{enums::PayoutConnectors, payouts as payout_types};
use common_enums::MandateStatus;
-pub use common_utils::request::{RequestBody, RequestContent};
+pub use common_utils::request::RequestContent;
use common_utils::{pii, pii::Email};
use data_models::mandates::{CustomerAcceptance, MandateData};
use error_stack::{IntoReport, ResultExt};