Skip to content

Commit

Permalink
refactor(connector): [Adyen] Enhance currency Mapping with ConnectorC…
Browse files Browse the repository at this point in the history
…urrencyCommon Trait (#2209)
  • Loading branch information
srujanchikke authored Sep 21, 2023
1 parent 417f793 commit 3d18f20
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 175 deletions.
60 changes: 53 additions & 7 deletions crates/router/src/connector/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl ConnectorCommon for Adyen {
"adyen"
}

fn get_currency_unit(&self) -> api::CurrencyUnit {
api::CurrencyUnit::Minor
}

fn get_auth_header(
&self,
auth_type: &types::ConnectorAuthType,
Expand Down Expand Up @@ -169,7 +173,13 @@ impl
req,
types::PaymentsAuthorizeData::from(req),
));
let connector_req = adyen::AdyenPaymentRequest::try_from(&authorize_req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
authorize_req.request.currency,
authorize_req.request.amount,
&authorize_req,
))?;
let connector_req = adyen::AdyenPaymentRequest::try_from(&connector_router_data)?;

let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down Expand Up @@ -290,7 +300,13 @@ impl
&self,
req: &types::PaymentsCaptureRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenCaptureRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount_to_capture,
req,
))?;
let connector_req = adyen::AdyenCaptureRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenCaptureRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -608,7 +624,13 @@ impl
&self,
req: &types::PaymentsAuthorizeRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPaymentRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPaymentRequest::try_from(&connector_router_data)?;
let request_body = types::RequestBody::log_and_get_request_body(
&connector_req,
common_utils::ext_traits::Encode::<adyen::AdyenPaymentRequest<'_>>::encode_to_string_of_json,
Expand Down Expand Up @@ -1008,7 +1030,13 @@ impl services::ConnectorIntegration<api::PoCreate, types::PayoutsData, types::Pa
&self,
req: &types::PayoutsRouterData<api::PoCreate>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutCreateRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPayoutCreateRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenPayoutCreateRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -1094,7 +1122,13 @@ impl
&self,
req: &types::PayoutsRouterData<api::PoEligibility>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutEligibilityRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPayoutEligibilityRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenPayoutEligibilityRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -1197,7 +1231,13 @@ impl services::ConnectorIntegration<api::PoFulfill, types::PayoutsData, types::P
&self,
req: &types::PayoutsRouterData<api::PoFulfill>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutFulfillRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPayoutFulfillRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenPayoutFulfillRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -1289,7 +1329,13 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
&self,
req: &types::RefundsRouterData<api::Execute>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenRefundRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.refund_amount,
req,
))?;
let connector_req = adyen::AdyenRefundRequest::try_from(&connector_router_data)?;

let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down
Loading

0 comments on commit 3d18f20

Please sign in to comment.