Skip to content

Commit

Permalink
refactor: return optional request body from build_request_v2 in Conne…
Browse files Browse the repository at this point in the history
…ctorIntegrationV2 trait (#5865)
  • Loading branch information
hrithikesh026 committed Sep 13, 2024
1 parent 5e88185 commit 728825b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions crates/common_utils/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ impl RequestBuilder {
self
}

pub fn set_optional_body<T: Into<RequestContent>>(mut self, body: Option<T>) -> Self {
body.map(|body| self.body.replace(body.into()));
self
}

pub fn set_body<T: Into<RequestContent>>(mut self, body: T) -> Self {
self.body.replace(body.into());
self
Expand Down
34 changes: 22 additions & 12 deletions crates/hyperswitch_interfaces/src/connector_integration_v2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! definition of the new connector integration trait
use common_utils::{
errors::CustomResult,
request::{Method, Request, RequestContent},
request::{Method, Request, RequestBuilder, RequestContent},
};
use hyperswitch_domain_models::{router_data::ErrorResponse, router_data_v2::RouterDataV2};
use masking::Maskable;
Expand Down Expand Up @@ -65,15 +65,20 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>:
&self,
_req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>,
) -> CustomResult<String, errors::ConnectorError> {
metrics::UNIMPLEMENTED_FLOW.add(
&metrics::CONTEXT,
1,
&add_attributes([("connector", self.id())]),
);
Ok(String::new())
}

/// returns request body
fn get_request_body(
&self,
_req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>,
) -> CustomResult<RequestContent, errors::ConnectorError> {
Ok(RequestContent::Json(Box::new(json!(r#"{}"#))))
) -> CustomResult<Option<RequestContent>, errors::ConnectorError> {
Ok(None)
}

/// returns form data
Expand All @@ -87,14 +92,19 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>:
/// builds the request and returns it
fn build_request_v2(
&self,
_req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>,
req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>,
) -> CustomResult<Option<Request>, errors::ConnectorError> {
metrics::UNIMPLEMENTED_FLOW.add(
&metrics::CONTEXT,
1,
&add_attributes([("connector", self.id())]),
);
Ok(None)
Ok(Some(
RequestBuilder::new()
.method(self.get_http_method())
.url(self.get_url(req)?.as_str())
.attach_default_headers()
.headers(self.get_headers(req)?)
.set_optional_body(self.get_request_body(req)?)
.add_certificate(self.get_certificate(req)?)
.add_certificate_key(self.get_certificate_key(req)?)
.build(),
))
}

/// accepts the raw api response and decodes it
Expand Down Expand Up @@ -167,15 +177,15 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>:
fn get_certificate(
&self,
_req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>,
) -> CustomResult<Option<String>, errors::ConnectorError> {
) -> CustomResult<Option<masking::Secret<String>>, errors::ConnectorError> {
Ok(None)
}

/// returns private key string
fn get_certificate_key(
&self,
_req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>,
) -> CustomResult<Option<String>, errors::ConnectorError> {
) -> CustomResult<Option<masking::Secret<String>>, errors::ConnectorError> {
Ok(None)
}
}

0 comments on commit 728825b

Please sign in to comment.