Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector): [Authorizedotnet] Enhance currency Mapping with ConnectorCurrencyCommon Trait #2570

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions crates/router/src/connector/authorizedotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl ConnectorCommon for Authorizedotnet {
"authorizedotnet"
}

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

fn common_get_content_type(&self) -> &'static str {
"application/json"
}
Expand Down Expand Up @@ -142,7 +146,14 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
&self,
req: &types::PaymentsCaptureRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = authorizedotnet::CancelOrCaptureTransactionRequest::try_from(req)?;
let connector_router_data = authorizedotnet::AuthorizedotnetRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.payment_amount,
Azanul marked this conversation as resolved.
Show resolved Hide resolved
req,
))?;
let connector_req =
authorizedotnet::CancelOrCaptureTransactionRequest::try_from(&connector_router_data)?;

let authorizedotnet_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down Expand Up @@ -315,7 +326,14 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
&self,
req: &types::PaymentsAuthorizeRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = authorizedotnet::CreateTransactionRequest::try_from(req)?;
let connector_router_data = authorizedotnet::AuthorizedotnetRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
req,
))?;
let connector_req =
authorizedotnet::CreateTransactionRequest::try_from(&connector_router_data)?;

let authorizedotnet_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down Expand Up @@ -407,7 +425,14 @@ impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsR
&self,
req: &types::PaymentsCancelRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = authorizedotnet::CancelOrCaptureTransactionRequest::try_from(req)?;
let connector_router_data = authorizedotnet::AuthorizedotnetRouterData::try_from((
&self.get_currency_unit(),
req.request.currency.unwrap(),
Azanul marked this conversation as resolved.
Show resolved Hide resolved
req.request.amount.unwrap(),
req,
))?;
let connector_req =
authorizedotnet::CancelOrCaptureTransactionRequest::try_from(&connector_router_data)?;

let authorizedotnet_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down Expand Up @@ -496,7 +521,13 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
&self,
req: &types::RefundsRouterData<api::Execute>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = authorizedotnet::CreateRefundRequest::try_from(req)?;
let connector_router_data = authorizedotnet::AuthorizedotnetRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.refund_amount,
req,
))?;
let connector_req = authorizedotnet::CreateRefundRequest::try_from(&connector_router_data)?;

let authorizedotnet_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down Expand Up @@ -583,7 +614,15 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
&self,
req: &types::RefundsRouterData<api::RSync>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = authorizedotnet::AuthorizedotnetCreateSyncRequest::try_from(req)?;
let connector_router_data = authorizedotnet::AuthorizedotnetRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.refund_amount,
req,
))?;
let connector_req =
authorizedotnet::AuthorizedotnetCreateSyncRequest::try_from(&connector_router_data)?;

let sync_request = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<authorizedotnet::AuthorizedotnetCreateSyncRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -670,7 +709,15 @@ impl
&self,
req: &types::PaymentsCompleteAuthorizeRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = authorizedotnet::PaypalConfirmRequest::try_from(req)?;
let connector_router_data = authorizedotnet::AuthorizedotnetRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
req,
))?;
let connector_req =
authorizedotnet::PaypalConfirmRequest::try_from(&connector_router_data)?;

let authorizedotnet_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<authorizedotnet::PaypalConfirmRequest>::encode_to_string_of_json,
Expand Down
Loading