Skip to content

Commit

Permalink
refactor(router): add parameter connectors to get_request_body functi…
Browse files Browse the repository at this point in the history
…on (#2708)
  • Loading branch information
AkshayaFoiger authored Nov 8, 2023
1 parent 5642fef commit 7623ea9
Show file tree
Hide file tree
Showing 53 changed files with 920 additions and 259 deletions.
13 changes: 7 additions & 6 deletions connector-template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
}

fn get_request_body(&self, req: &types::PaymentsAuthorizeRouterData) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
fn get_request_body(&self, req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors,) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data =
{{project-name | downcase}}::{{project-name | downcase | pascal_case}}RouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -186,7 +186,7 @@ impl
.headers(types::PaymentsAuthorizeType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsAuthorizeType::get_request_body(self, req)?)
.body(types::PaymentsAuthorizeType::get_request_body(self, req, connectors)?)
.build(),
))
}
Expand Down Expand Up @@ -302,6 +302,7 @@ impl
fn get_request_body(
&self,
_req: &types::PaymentsCaptureRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
}
Expand All @@ -319,7 +320,7 @@ impl
.headers(types::PaymentsCaptureType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsCaptureType::get_request_body(self, req)?)
.body(types::PaymentsCaptureType::get_request_body(self, req, connectors)?)
.build(),
))
}
Expand Down Expand Up @@ -374,7 +375,7 @@ impl
Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
}

fn get_request_body(&self, req: &types::RefundsRouterData<api::Execute>) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
fn get_request_body(&self, req: &types::RefundsRouterData<api::Execute>, _connectors: &settings::Connectors,) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data =
{{project-name | downcase}}::{{project-name | downcase | pascal_case}}RouterData::try_from((
&self.get_currency_unit(),
Expand All @@ -394,7 +395,7 @@ impl
.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)?)
.body(types::RefundExecuteType::get_request_body(self, req, connectors)?)
.build();
Ok(Some(request))
}
Expand Down Expand Up @@ -442,7 +443,7 @@ impl
.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)?)
.body(types::RefundSyncType::get_request_body(self, req, connectors)?)
.build(),
))
}
Expand Down
19 changes: 15 additions & 4 deletions crates/router/src/connector/aci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ impl
.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)?)
.body(types::PaymentsSyncType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -280,6 +282,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsAuthorizeRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
// encode only for for urlencoded things.
let connector_router_data = aci::AciRouterData::try_from((
Expand Down Expand Up @@ -317,7 +320,9 @@ impl
.headers(types::PaymentsAuthorizeType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsAuthorizeType::get_request_body(self, req)?)
.body(types::PaymentsAuthorizeType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -386,6 +391,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsCancelRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = aci::AciCancelRequest::try_from(req)?;
let aci_req = types::RequestBody::log_and_get_request_body(
Expand All @@ -406,7 +412,9 @@ impl
.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)?)
.body(types::PaymentsVoidType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -479,6 +487,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
fn get_request_body(
&self,
req: &types::RefundsRouterData<api::Execute>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = aci::AciRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -508,7 +517,9 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
.headers(types::RefundExecuteType::get_headers(
self, req, connectors,
)?)
.body(types::RefundExecuteType::get_request_body(self, req)?)
.body(types::RefundExecuteType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down
57 changes: 45 additions & 12 deletions crates/router/src/connector/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl
fn get_request_body(
&self,
req: &types::SetupMandateRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let authorize_req = types::PaymentsAuthorizeRouterData::from((
req,
Expand Down Expand Up @@ -203,7 +204,9 @@ impl
.url(&types::SetupMandateType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::SetupMandateType::get_headers(self, req, connectors)?)
.body(types::SetupMandateType::get_request_body(self, req)?)
.body(types::SetupMandateType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -306,6 +309,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsCaptureRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -334,7 +338,9 @@ impl
.headers(types::PaymentsCaptureType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsCaptureType::get_request_body(self, req)?)
.body(types::PaymentsCaptureType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -398,6 +404,7 @@ impl
fn get_request_body(
&self,
req: &types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
// Adyen doesn't support PSync flow. We use PSync flow to fetch payment details,
// specifically the redirect URL that takes the user to their Payment page. In non-redirection flows,
Expand Down Expand Up @@ -482,15 +489,17 @@ impl
req: &types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>,
connectors: &settings::Connectors,
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
let request_body = self.get_request_body(req)?;
let request_body = self.get_request_body(req, connectors)?;
match request_body {
Some(_) => Ok(Some(
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)?)
.body(types::PaymentsSyncType::get_request_body(
self, req, connectors,
)?)
.build(),
)),
None => Ok(None),
Expand Down Expand Up @@ -632,6 +641,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsAuthorizeRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -664,7 +674,9 @@ impl
.headers(types::PaymentsAuthorizeType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsAuthorizeType::get_request_body(self, req)?)
.body(types::PaymentsAuthorizeType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -752,6 +764,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsBalanceRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenBalanceRequest::try_from(req)?;

Expand All @@ -776,7 +789,9 @@ impl
.headers(types::PaymentsBalanceType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsBalanceType::get_request_body(self, req)?)
.body(types::PaymentsBalanceType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -845,6 +860,7 @@ impl
fn get_request_body(
&self,
req: &types::PaymentsCancelRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenCancelRequest::try_from(req)?;

Expand All @@ -866,7 +882,9 @@ impl
.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)?)
.body(types::PaymentsVoidType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down Expand Up @@ -955,6 +973,7 @@ impl services::ConnectorIntegration<api::PoCancel, types::PayoutsData, types::Pa
fn get_request_body(
&self,
req: &types::PayoutsRouterData<api::PoCancel>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutCancelRequest::try_from(req)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
Expand All @@ -975,7 +994,9 @@ impl services::ConnectorIntegration<api::PoCancel, types::PayoutsData, types::Pa
.url(&types::PayoutCancelType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::PayoutCancelType::get_headers(self, req, connectors)?)
.body(types::PayoutCancelType::get_request_body(self, req)?)
.body(types::PayoutCancelType::get_request_body(
self, req, connectors,
)?)
.build();

Ok(Some(request))
Expand Down Expand Up @@ -1040,6 +1061,7 @@ impl services::ConnectorIntegration<api::PoCreate, types::PayoutsData, types::Pa
fn get_request_body(
&self,
req: &types::PayoutsRouterData<api::PoCreate>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
Expand All @@ -1066,7 +1088,9 @@ impl services::ConnectorIntegration<api::PoCreate, types::PayoutsData, types::Pa
.url(&types::PayoutCreateType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::PayoutCreateType::get_headers(self, req, connectors)?)
.body(types::PayoutCreateType::get_request_body(self, req)?)
.body(types::PayoutCreateType::get_request_body(
self, req, connectors,
)?)
.build();

Ok(Some(request))
Expand Down Expand Up @@ -1132,6 +1156,7 @@ impl
fn get_request_body(
&self,
req: &types::PayoutsRouterData<api::PoEligibility>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -1162,7 +1187,9 @@ impl
.headers(types::PayoutEligibilityType::get_headers(
self, req, connectors,
)?)
.body(types::PayoutEligibilityType::get_request_body(self, req)?)
.body(types::PayoutEligibilityType::get_request_body(
self, req, connectors,
)?)
.build();

Ok(Some(request))
Expand Down Expand Up @@ -1241,6 +1268,7 @@ impl services::ConnectorIntegration<api::PoFulfill, types::PayoutsData, types::P
fn get_request_body(
&self,
req: &types::PayoutsRouterData<api::PoFulfill>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -1269,7 +1297,9 @@ impl services::ConnectorIntegration<api::PoFulfill, types::PayoutsData, types::P
.headers(types::PayoutFulfillType::get_headers(
self, req, connectors,
)?)
.body(types::PayoutFulfillType::get_request_body(self, req)?)
.body(types::PayoutFulfillType::get_request_body(
self, req, connectors,
)?)
.build();

Ok(Some(request))
Expand Down Expand Up @@ -1339,6 +1369,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
fn get_request_body(
&self,
req: &types::RefundsRouterData<api::Execute>,
_connectors: &settings::Connectors,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
Expand Down Expand Up @@ -1369,7 +1400,9 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
.headers(types::RefundExecuteType::get_headers(
self, req, connectors,
)?)
.body(types::RefundExecuteType::get_request_body(self, req)?)
.body(types::RefundExecuteType::get_request_body(
self, req, connectors,
)?)
.build(),
))
}
Expand Down
Loading

0 comments on commit 7623ea9

Please sign in to comment.