diff --git a/connector-template/mod.rs b/connector-template/mod.rs index 60c8992360..7bcf4d30fb 100644 --- a/connector-template/mod.rs +++ b/connector-template/mod.rs @@ -36,7 +36,7 @@ impl api::Refund for {{project-name | downcase | pascal_case}} {} impl api::RefundExecute for {{project-name | downcase | pascal_case}} {} impl api::RefundSync for {{project-name | downcase | pascal_case}} {} -impl ConnectorCommonExt for {{project-name | downcase | pascal_case}} +impl ConnectorCommonExt for {{project-name | downcase | pascal_case}} where Self: ConnectorIntegration,{ fn build_headers( @@ -132,7 +132,7 @@ impl fn get_url(&self, _req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors,) -> CustomResult { Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) } - + fn get_request_body(&self, req: &types::PaymentsAuthorizeRouterData) -> CustomResult,errors::ConnectorError> { let req_obj = {{project-name | downcase}}::{{project-name | downcase | pascal_case}}PaymentsRequest::try_from(req)?; let {{project-name | downcase}}_req = @@ -154,6 +154,7 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) @@ -214,6 +215,7 @@ impl services::RequestBuilder::new() .method(services::Method::Get) .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) .build(), )) @@ -287,6 +289,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsCaptureType::get_headers( self, req, connectors, )?) @@ -359,6 +362,7 @@ impl let request = services::RequestBuilder::new() .method(services::Method::Post) .url(&types::RefundExecuteType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::RefundExecuteType::get_headers(self, req, connectors)?) .body(types::RefundExecuteType::get_request_body(self, req)?) .build(); @@ -407,6 +411,7 @@ impl services::RequestBuilder::new() .method(services::Method::Get) .url(&types::RefundSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::RefundSyncType::get_headers(self, req, connectors)?) .body(types::RefundSyncType::get_request_body(self, req)?) .build(), diff --git a/connector-template/transformers.rs b/connector-template/transformers.rs index 3cc0c3d9e9..985c68a99c 100644 --- a/connector-template/transformers.rs +++ b/connector-template/transformers.rs @@ -38,7 +38,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for {{project-name | downcase }) } _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), - } + } } } diff --git a/crates/router/src/connector/aci.rs b/crates/router/src/connector/aci.rs index daa1236b0d..0a925eb251 100644 --- a/crates/router/src/connector/aci.rs +++ b/crates/router/src/connector/aci.rs @@ -103,13 +103,10 @@ impl req: &types::PaymentsSyncRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsSyncType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -147,6 +144,7 @@ impl services::RequestBuilder::new() .method(services::Method::Get) .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) .body(types::PaymentsSyncType::get_request_body(self, req)?) .build(), @@ -210,13 +208,10 @@ impl req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -259,10 +254,10 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsAuthorizeType::get_request_body(self, req)?) .build(), )) @@ -321,13 +316,10 @@ impl req: &types::PaymentsCancelRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -363,6 +355,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsVoidType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?) .body(types::PaymentsVoidType::get_request_body(self, req)?) .build(), @@ -422,13 +415,10 @@ impl services::ConnectorIntegration, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundExecuteType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundExecuteType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -469,6 +459,7 @@ impl services::ConnectorIntegration CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - self.common_get_content_type().to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + self.common_get_content_type().to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -141,6 +138,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsCaptureType::get_headers( self, req, connectors, )?) @@ -191,13 +189,10 @@ impl req: &types::RouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsSyncType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -270,8 +265,8 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsSyncType::get_request_body(self, req)?) .build(), )) @@ -336,13 +331,10 @@ impl types::PaymentsResponseData, >, { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -383,10 +375,10 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsAuthorizeType::get_request_body(self, req)?) .build(), )) @@ -443,13 +435,10 @@ impl req: &types::PaymentsCancelRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -487,8 +476,8 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsVoidType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsVoidType::get_request_body(self, req)?) .build(), )) @@ -541,13 +530,10 @@ impl services::ConnectorIntegration, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundExecuteType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundExecuteType::get_content_type(self).to_string(), + )]; let mut api_header = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_header); Ok(header) @@ -586,6 +572,7 @@ impl services::ConnectorIntegration CustomResult, errors::ConnectorError> { // This connector does not require an auth header, the authentication details are sent in the request body - Ok(vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]) + Ok(vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsSyncType::get_content_type(self).to_string(), + )]) } fn get_content_type(&self) -> &'static str { @@ -138,6 +135,7 @@ impl let request = services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) .body(types::PaymentsSyncType::get_request_body(self, req)?) .build(); @@ -190,13 +188,10 @@ impl _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { // This connector does not require an auth header, the authentication details are sent in the request body - Ok(vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]) + Ok(vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]) } fn get_content_type(&self) -> &'static str { @@ -240,10 +235,10 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsAuthorizeType::get_request_body(self, req)?) .build(), )) @@ -296,13 +291,10 @@ impl _req: &types::PaymentsCancelRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - Ok(vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]) + Ok(vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]) } fn get_content_type(&self) -> &'static str { @@ -338,8 +330,8 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsVoidType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsVoidType::get_request_body(self, req)?) .build(), )) @@ -392,13 +384,10 @@ impl services::ConnectorIntegration CustomResult, errors::ConnectorError> { // This connector does not require an auth header, the authentication details are sent in the request body - Ok(vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]) + Ok(vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]) } fn get_content_type(&self) -> &'static str { @@ -435,6 +424,7 @@ impl services::ConnectorIntegration CustomResult, errors::ConnectorError> { // This connector does not require an auth header, the authentication details are sent in the request body - Ok(vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]) + Ok(vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundSyncType::get_content_type(self).to_string(), + )]) } fn get_content_type(&self) -> &'static str { @@ -529,6 +516,7 @@ impl services::ConnectorIntegration CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - self.common_get_content_type().to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + self.common_get_content_type().to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -151,6 +148,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsCaptureType::get_headers( self, req, connectors, )?) @@ -208,13 +206,10 @@ impl req: &types::PaymentsSyncRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -245,8 +240,8 @@ impl services::RequestBuilder::new() .method(services::Method::Get) .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsSyncType::get_request_body(self, req)?) .build(), )) @@ -308,13 +303,10 @@ impl req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -353,10 +345,10 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsAuthorizeType::get_request_body(self, req)?) .build(), )) @@ -425,13 +417,10 @@ impl req: &types::PaymentsCancelRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsVoidType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsVoidType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -468,6 +457,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsVoidType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?) .body(types::PaymentsVoidType::get_request_body(self, req)?) .build(), @@ -526,13 +516,10 @@ impl services::ConnectorIntegration, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundExecuteType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundExecuteType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -574,6 +561,7 @@ impl services::ConnectorIntegration, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundSyncType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -668,6 +653,7 @@ impl services::ConnectorIntegration CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -126,6 +123,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsSessionType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSessionType::get_headers( self, req, connectors, )?) @@ -209,13 +207,10 @@ impl req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -289,6 +284,7 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) diff --git a/crates/router/src/connector/mollie.rs b/crates/router/src/connector/mollie.rs index 1c1e461a59..559888c97f 100644 --- a/crates/router/src/connector/mollie.rs +++ b/crates/router/src/connector/mollie.rs @@ -145,6 +145,7 @@ impl ConnectorIntegration CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - Self::common_get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + Self::common_get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -148,6 +145,7 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsCaptureType::get_headers( self, req, connectors, )?) @@ -210,13 +208,10 @@ impl req: &types::PaymentsSyncRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsSyncType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -250,6 +245,7 @@ impl services::RequestBuilder::new() .method(services::Method::Get) .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) .body(types::PaymentsSyncType::get_request_body(self, req)?) .build(), @@ -313,13 +309,10 @@ impl req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsAuthorizeType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsAuthorizeType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -362,10 +355,10 @@ impl .url(&types::PaymentsAuthorizeType::get_url( self, req, connectors, )?) + .attach_default_headers() .headers(types::PaymentsAuthorizeType::get_headers( self, req, connectors, )?) - .header(headers::X_ROUTER, "test") .body(types::PaymentsAuthorizeType::get_request_body(self, req)?) .build(), )) @@ -424,13 +417,10 @@ impl req: &types::PaymentsCancelRouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::PaymentsVoidType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::PaymentsVoidType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -472,6 +462,7 @@ impl let request = services::RequestBuilder::new() .method(services::Method::Post) .url(&types::PaymentsVoidType::get_url(self, req, connectors)?) + .attach_default_headers() .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?) .body(types::PaymentsVoidType::get_request_body(self, req)?) .build(); @@ -535,13 +526,10 @@ impl req: &types::RouterData, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - Verify::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + Verify::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -585,8 +573,8 @@ impl services::RequestBuilder::new() .method(services::Method::Post) .url(&Verify::get_url(self, req, connectors)?) + .attach_default_headers() .headers(Verify::get_headers(self, req, connectors)?) - .header(headers::X_ROUTER, "test") .body(Verify::get_request_body(self, req)?) .build(), )) @@ -656,13 +644,10 @@ impl services::ConnectorIntegration, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundExecuteType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundExecuteType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -697,6 +682,7 @@ impl services::ConnectorIntegration, _connectors: &settings::Connectors, ) -> CustomResult, errors::ConnectorError> { - let mut header = vec![ - ( - headers::CONTENT_TYPE.to_string(), - types::RefundSyncType::get_content_type(self).to_string(), - ), - (headers::X_ROUTER.to_string(), "test".to_string()), - ]; + let mut header = vec![( + headers::CONTENT_TYPE.to_string(), + types::RefundSyncType::get_content_type(self).to_string(), + )]; let mut api_key = self.get_auth_header(&req.connector_auth_type)?; header.append(&mut api_key); Ok(header) @@ -788,8 +771,8 @@ impl services::ConnectorIntegration( let mut url = locker.host.to_owned(); url.push_str("/card/deleteCard"); let mut request = services::Request::new(services::Method::Post, &url); - request.add_header(headers::X_ROUTER, "test"); + request.add_default_headers(); request.add_header(headers::CONTENT_TYPE, "application/x-www-form-urlencoded"); request.set_body(body); @@ -611,7 +611,7 @@ pub fn mk_crud_locker_request( let mut url = locker.basilisk_host.to_owned(); url.push_str(path); let mut request = services::Request::new(services::Method::Post, &url); - request.add_header(headers::X_ROUTER, "test"); + request.add_default_headers(); request.add_header(headers::CONTENT_TYPE, "application/json"); request.set_body(body.to_string()); Ok(request) diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs index 4ac48d0723..42941ee0ff 100644 --- a/crates/router/src/lib.rs +++ b/crates/router/src/lib.rs @@ -52,7 +52,6 @@ pub mod headers { pub const X_API_KEY: &str = "X-API-KEY"; pub const X_API_VERSION: &str = "X-ApiVersion"; pub const X_MERCHANT_ID: &str = "X-Merchant-Id"; - pub const X_ROUTER: &str = "X-router"; pub const X_LOGIN: &str = "X-Login"; pub const X_TRANS_KEY: &str = "X-Trans-Key"; pub const X_VERSION: &str = "X-Version"; diff --git a/crates/router/src/services/api/request.rs b/crates/router/src/services/api/request.rs index cc6ab747e6..90e994874f 100644 --- a/crates/router/src/services/api/request.rs +++ b/crates/router/src/services/api/request.rs @@ -30,6 +30,12 @@ pub enum ContentType { FormUrlEncoded, } +fn default_request_headers() -> [(String, String); 1] { + use http::header; + + [(header::VIA.to_string(), "HyperSwitch".into())] +} + #[derive(Debug, Serialize, Deserialize)] pub struct Request { pub url: String, @@ -58,6 +64,10 @@ impl Request { self.payload = Some(body.into()); } + pub fn add_default_headers(&mut self) { + self.headers.extend(default_request_headers()); + } + pub fn add_header(&mut self, header: &str, value: &str) { self.headers .insert((String::from(header), String::from(value))); @@ -109,6 +119,11 @@ impl RequestBuilder { self } + pub fn attach_default_headers(mut self) -> Self { + self.headers.extend(default_request_headers()); + self + } + pub fn header(mut self, header: &str, value: &str) -> Self { self.headers.insert((header.into(), value.into())); self