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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(interfaces): add query_params functionality in microservice client (#11026)
Kashifc2630a4a0c5e
diff --git a/crates/hyperswitch_interfaces/src/micro_service/executor.rs b/crates/hyperswitch_interfaces/src/micro_service/executor.rsindex 47a1f5f917..ee2e4bb5b2 100644--- a/crates/hyperswitch_interfaces/src/micro_service/executor.rs+++ b/crates/hyperswitch_interfaces/src/micro_service/executor.rs@@ -39,6 +39,7 @@ impl<O: ClientOperation> Validated<O> {})?;Ok(TransformedRequest {op: self.op,+ v1_request: self.request,request,})}@@ -57,13 +58,13 @@ impl<O: ClientOperation> TransformedRequest<O> {// Step 1: Build path and URL.let path = {let mut path = O::PATH_TEMPLATE.to_string();- for (key, value) in self.op.path_params(&self.request) {+ for (key, value) in self.op.path_params(&self.v1_request) {let token = format!("{{{key}}}");path = path.replace(&token, &value);}path};- let url = base_url.join(&path).map_err(|e| {+ let mut url = base_url.join(&path).map_err(|e| {logger::error!(operation, error = ?e, "microservice URL join failed");MicroserviceClientError {operation: operation.to_string(),@@ -72,6 +73,13 @@ impl<O: ClientOperation> TransformedRequest<O> {)),}})?;+ let query_params = self.op.query_params(&self.v1_request);+ if !query_params.is_empty() {+ let mut query = url.query_pairs_mut();+ for (key, value) in query_params {+ query.append_pair(key, &value);+ }+ }// Step 2: Build headers and inject trace/request/tenant context.let mut http_request = Request::new(O::METHOD, url.as_str());diff --git a/crates/hyperswitch_interfaces/src/micro_service/macros.rs b/crates/hyperswitch_interfaces/src/micro_service/macros.rsindex c8cc52a0ef..8a50f4828f 100644--- a/crates/hyperswitch_interfaces/src/micro_service/macros.rs+++ b/crates/hyperswitch_interfaces/src/micro_service/macros.rs@@ -67,6 +67,7 @@ macro_rules! impl_microservice_flow {client = $client_ty:ty$(, body = $body_fn:expr)?$(, path_params = $path_params_fn:expr)?+ $(, query_params = $query_params_fn:expr)?$(, validate = $validate_fn:expr)?) => {#[async_trait::async_trait]@@ -117,11 +118,20 @@ macro_rules! impl_microservice_flow {$(fn path_params(&self,- request: &Self::V2Request,+ request: &Self::V1Request,) -> Vec<(&'static str, String)> {$path_params_fn(self, request)})?++ $(+ fn query_params(+ &self,+ request: &Self::V1Request,+ ) -> Vec<(&'static str, String)> {+ $query_params_fn(self, request)+ }+ )?}impl $flow {diff --git a/crates/hyperswitch_interfaces/src/micro_service/state.rs b/crates/hyperswitch_interfaces/src/micro_service/state.rsindex 9e2ecb451e..aff8914077 100644--- a/crates/hyperswitch_interfaces/src/micro_service/state.rs+++ b/crates/hyperswitch_interfaces/src/micro_service/state.rs@@ -33,7 +33,7 @@ pub trait ClientOperation {type V1Response;/// Modular service request payload produced by request transformation.///- /// This is not sent automatically; it is passed into `body()` and/or `path_params()`.+ /// This is not sent automatically; it is passed into `body()`.type V2Request;/// Modular service response payload returned by the upstream service.///@@ -68,7 +68,31 @@ pub trait ClientOperation {////// Keys should correspond to `{token}` placeholders in `PATH_TEMPLATE`./// This is typically used for resource IDs.- fn path_params(&self, _request: &Self::V2Request) -> Vec<(&'static str, String)> {+ ///+ /// # Example+ /// # impl ClientOperation for ExampleOp {+ /// # fn path_params(&self, request: &Self::V1Request) -> Vec<(&'static str, String)> {+ /// # vec![("id", request.payment_method_id.clone())]+ /// # }+ /// # }+ fn path_params(&self, _request: &Self::V1Request) -> Vec<(&'static str, String)> {+ Vec::new()+ }++ /// Optional query parameters appended to the request URL.+ ///+ /// Use this for filters or pagination, not for sensitive data.+ ///+ /// # Example+ /// # impl ClientOperation for ExampleOp {+ /// # fn query_params(&self, request: &Self::V1Request) -> Vec<(&'static str, String)> {+ /// # vec![+ /// # ("limit", request.limit.to_string()),+ /// # ("customer_id", request.customer_id.clone()),+ /// # ]+ /// # }+ /// # }+ fn query_params(&self, _request: &Self::V1Request) -> Vec<(&'static str, String)> {Vec::new()}@@ -94,6 +118,8 @@ pub struct Validated<O: ClientOperation> {pub struct TransformedRequest<O: ClientOperation> {/// Flow instance.pub(crate) op: O,+ /// V1 request payload.+ pub(crate) v1_request: O::V1Request,/// Transformed request payload.pub(crate) request: O::V2Request,}diff --git a/crates/payment_methods/src/client/delete.rs b/crates/payment_methods/src/client/delete.rsindex f990e9adbc..6a05e75c3f 100644--- a/crates/payment_methods/src/client/delete.rs+++ b/crates/payment_methods/src/client/delete.rs@@ -88,7 +88,7 @@ impl DeletePaymentMethod {fn build_path_params(&self,- request: &DeletePaymentMethodV2Request,+ request: &DeletePaymentMethodV1Request,) -> Vec<(&'static str, String)> {vec![("id", request.payment_method_id.payment_method_id.clone())]}diff --git a/crates/payment_methods/src/client/retrieve.rs b/crates/payment_methods/src/client/retrieve.rsindex 224fad3b40..fb9a3862aa 100644--- a/crates/payment_methods/src/client/retrieve.rs+++ b/crates/payment_methods/src/client/retrieve.rs@@ -88,7 +88,7 @@ impl RetrievePaymentMethod {fn build_path_params(&self,- request: &RetrievePaymentMethodV2Request,+ request: &RetrievePaymentMethodV1Request,) -> Vec<(&'static str, String)> {vec![("id", request.payment_method_id.payment_method_id.clone())]}diff --git a/crates/payment_methods/src/client/update.rs b/crates/payment_methods/src/client/update.rsindex 6440586881..9d073fe8c8 100644--- a/crates/payment_methods/src/client/update.rs+++ b/crates/payment_methods/src/client/update.rs@@ -94,7 +94,7 @@ impl UpdatePaymentMethod {fn build_path_params(&self,- request: &UpdatePaymentMethodV2Request,+ request: &UpdatePaymentMethodV1Request,) -> Vec<(&'static str, String)> {vec![("id", request.payment_method_id.payment_method_id.clone())]}