feat(request): add RequestBuilder method to attach default request headers (#826)

This commit is contained in:
Sanchith Hegde
2023-04-04 11:26:24 +05:30
committed by GitHub
parent 6d7b11a0f0
commit 6f61f83066
29 changed files with 272 additions and 225 deletions

View File

@ -97,13 +97,10 @@ impl
req: &types::PaymentsCaptureRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, String)>, 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<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>,
_connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, String)>, 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<Vec<(String, String)>, 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<api::Execute, types::RefundsData, types::Ref
req: &types::RefundsRouterData<api::Execute>,
_connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, String)>, 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<api::Execute, types::RefundsData, types::Ref
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,
)?)