mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	refactor: return optional request body from build_request_v2 in ConnectorIntegrationV2 trait (#5865)
This commit is contained in:
		| @ -152,6 +152,11 @@ impl RequestBuilder { | |||||||
|         self |         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 { |     pub fn set_body<T: Into<RequestContent>>(mut self, body: T) -> Self { | ||||||
|         self.body.replace(body.into()); |         self.body.replace(body.into()); | ||||||
|         self |         self | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| //! definition of the new connector integration trait | //! definition of the new connector integration trait | ||||||
| use common_utils::{ | use common_utils::{ | ||||||
|     errors::CustomResult, |     errors::CustomResult, | ||||||
|     request::{Method, Request, RequestContent}, |     request::{Method, Request, RequestBuilder, RequestContent}, | ||||||
| }; | }; | ||||||
| use hyperswitch_domain_models::{router_data::ErrorResponse, router_data_v2::RouterDataV2}; | use hyperswitch_domain_models::{router_data::ErrorResponse, router_data_v2::RouterDataV2}; | ||||||
| use masking::Maskable; | use masking::Maskable; | ||||||
| @ -65,6 +65,11 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>: | |||||||
|         &self, |         &self, | ||||||
|         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, |         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|  |         metrics::UNIMPLEMENTED_FLOW.add( | ||||||
|  |             &metrics::CONTEXT, | ||||||
|  |             1, | ||||||
|  |             &add_attributes([("connector", self.id())]), | ||||||
|  |         ); | ||||||
|         Ok(String::new()) |         Ok(String::new()) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -72,8 +77,8 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>: | |||||||
|     fn get_request_body( |     fn get_request_body( | ||||||
|         &self, |         &self, | ||||||
|         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, |         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, | ||||||
|     ) -> CustomResult<RequestContent, errors::ConnectorError> { |     ) -> CustomResult<Option<RequestContent>, errors::ConnectorError> { | ||||||
|         Ok(RequestContent::Json(Box::new(json!(r#"{}"#)))) |         Ok(None) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// returns form data |     /// returns form data | ||||||
| @ -87,14 +92,19 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>: | |||||||
|     /// builds the request and returns it |     /// builds the request and returns it | ||||||
|     fn build_request_v2( |     fn build_request_v2( | ||||||
|         &self, |         &self, | ||||||
|         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, |         req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, | ||||||
|     ) -> CustomResult<Option<Request>, errors::ConnectorError> { |     ) -> CustomResult<Option<Request>, errors::ConnectorError> { | ||||||
|         metrics::UNIMPLEMENTED_FLOW.add( |         Ok(Some( | ||||||
|             &metrics::CONTEXT, |             RequestBuilder::new() | ||||||
|             1, |                 .method(self.get_http_method()) | ||||||
|             &add_attributes([("connector", self.id())]), |                 .url(self.get_url(req)?.as_str()) | ||||||
|         ); |                 .attach_default_headers() | ||||||
|         Ok(None) |                 .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 |     /// accepts the raw api response and decodes it | ||||||
| @ -167,7 +177,7 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>: | |||||||
|     fn get_certificate( |     fn get_certificate( | ||||||
|         &self, |         &self, | ||||||
|         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, |         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, | ||||||
|     ) -> CustomResult<Option<String>, errors::ConnectorError> { |     ) -> CustomResult<Option<masking::Secret<String>>, errors::ConnectorError> { | ||||||
|         Ok(None) |         Ok(None) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -175,7 +185,7 @@ pub trait ConnectorIntegrationV2<Flow, ResourceCommonData, Req, Resp>: | |||||||
|     fn get_certificate_key( |     fn get_certificate_key( | ||||||
|         &self, |         &self, | ||||||
|         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, |         _req: &RouterDataV2<Flow, ResourceCommonData, Req, Resp>, | ||||||
|     ) -> CustomResult<Option<String>, errors::ConnectorError> { |     ) -> CustomResult<Option<masking::Secret<String>>, errors::ConnectorError> { | ||||||
|         Ok(None) |         Ok(None) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Hrithikesh
					Hrithikesh