Bug: [FEATURE]: [Authorizedotnet] Currency Unit Conversion



### :memo: Feature Description

- Each currency can be described in terms of base or minor units. 
- For instance, when dealing with USD currency, the Cent is considered as the minor unit, while the Dollar is considered the base unit. 
- In Hyperswitch, the amount value is expected to be always provided in minor units. 
- For example: In USD, If the amount is 1 in base unit (Dollar), then it will be equivalent to 100 in minor units (Cent)
- Some of the connectors integrated require the amount to be converted to a desirable unit before being passed to them. 
- We have functions `to_currency_base_unit` and `to_currency_lower_unit` in place to convert the minor unit amount to its decimal equivalent and vice versa. These conversions are handled explicitly based on the connector.


### :hammer: Possible Implementation

- ConnectorCommon trait have been implemented for the connector. 
- This trait contains `get_currency_unit` method. This method needs to be implemented. 
- It will define what type of conversion needs to be done during `connector_router_data` creation. Concurrently handle the creation of `connector_router_data` to be passed for the connector request body creation.
- You can check this PR for further reference https://github.com/juspay/hyperswitch/pull/2196

:bookmark: Note: All the changes needed should be contained within `hyperswitch/crates/router/src/connector/`

### :package: Have you spent some time checking if this feature request has been raised before?

- [X] I checked and didn't find a similar issue

### :package: Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### :sparkles: Are you willing to submit a PR?

diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs
index 99e87ca1edf..7ff2098344e 100644
--- a/crates/router/src/connector/authorizedotnet.rs
+++ b/crates/router/src/connector/authorizedotnet.rs
@@ -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"
     }
@@ -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.amount_to_capture,
+            req,
+        ))?;
+        let connector_req =
+            authorizedotnet::CancelOrCaptureTransactionRequest::try_from(&connector_router_data)?;
 
         let authorizedotnet_req = types::RequestBody::log_and_get_request_body(
             &connector_req,
@@ -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,
@@ -496,7 +514,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,
@@ -583,7 +607,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,
@@ -670,7 +702,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,
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index 1b7480f78e4..cd7e070b16f 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -31,6 +31,38 @@ pub enum TransactionType {
     #[serde(rename = "authCaptureContinueTransaction")]
     ContinueCapture,
 }
+
+#[derive(Debug, Serialize)]
+pub struct AuthorizedotnetRouterData<T> {
+    pub amount: f64,
+    pub router_data: T,
+}
+
+impl<T>
+    TryFrom<(
+        &types::api::CurrencyUnit,
+        types::storage::enums::Currency,
+        i64,
+        T,
+    )> for AuthorizedotnetRouterData<T>
+{
+    type Error = error_stack::Report<errors::ConnectorError>;
+    fn try_from(
+        (currency_unit, currency, amount, item): (
+            &types::api::CurrencyUnit,
+            types::storage::enums::Currency,
+            i64,
+            T,
+        ),
+    ) -> Result<Self, Self::Error> {
+        let amount = utils::get_amount_as_f64(currency_unit, amount, currency)?;
+        Ok(Self {
+            amount,
+            router_data: item,
+        })
+    }
+}
+
 #[derive(Debug, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct AuthorizedotnetAuthType {
@@ -99,7 +131,7 @@ pub enum WalletMethod {
 }
 
 fn get_pm_and_subsequent_auth_detail(
-    item: &types::PaymentsAuthorizeRouterData,
+    item: &AuthorizedotnetRouterData<&types::PaymentsAuthorizeRouterData>,
 ) -> Result<
     (
         PaymentDetails,
@@ -109,6 +141,7 @@ fn get_pm_and_subsequent_auth_detail(
     error_stack::Report<errors::ConnectorError>,
 > {
     match item
+        .router_data
         .request
         .mandate_id
         .to_owned()
@@ -124,7 +157,7 @@ fn get_pm_and_subsequent_auth_detail(
                 original_network_trans_id,
                 reason: Reason::Resubmission,
             });
-            match item.request.payment_method_data {
+            match item.router_data.request.payment_method_data {
                 api::PaymentMethodData::Card(ref ccard) => {
                     let payment_details = PaymentDetails::CreditCard(CreditCardDetails {
                         card_number: (*ccard.card_number).clone(),
@@ -134,12 +167,12 @@ fn get_pm_and_subsequent_auth_detail(
                     Ok((payment_details, processing_options, subseuent_auth_info))
                 }
                 _ => Err(errors::ConnectorError::NotSupported {
-                    message: format!("{:?}", item.request.payment_method_data),
+                    message: format!("{:?}", item.router_data.request.payment_method_data),
                     connector: "AuthorizeDotNet",
                 })?,
             }
         }
-        _ => match item.request.payment_method_data {
+        _ => match item.router_data.request.payment_method_data {
             api::PaymentMethodData::Card(ref ccard) => {
                 Ok((
                     PaymentDetails::CreditCard(CreditCardDetails {
@@ -155,12 +188,15 @@ fn get_pm_and_subsequent_auth_detail(
                 ))
             }
             api::PaymentMethodData::Wallet(ref wallet_data) => Ok((
-                get_wallet_data(wallet_data, &item.request.complete_authorize_url)?,
+                get_wallet_data(
+                    wallet_data,
+                    &item.router_data.request.complete_authorize_url,
+                )?,
                 None,
                 None,
             )),
             _ => Err(errors::ConnectorError::NotSupported {
-                message: format!("{:?}", item.request.payment_method_data),
+                message: format!("{:?}", item.router_data.request.payment_method_data),
                 connector: "AuthorizeDotNet",
             })?,
         },
@@ -263,26 +299,34 @@ impl From<enums::CaptureMethod> for AuthorizationType {
     }
 }
 
-impl TryFrom<&types::PaymentsAuthorizeRouterData> for CreateTransactionRequest {
+impl TryFrom<&AuthorizedotnetRouterData<&types::PaymentsAuthorizeRouterData>>
+    for CreateTransactionRequest
+{
     type Error = error_stack::Report<errors::ConnectorError>;
-    fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
+    fn try_from(
+        item: &AuthorizedotnetRouterData<&types::PaymentsAuthorizeRouterData>,
+    ) -> Result<Self, Self::Error> {
         let (payment_details, processing_options, subsequent_auth_information) =
             get_pm_and_subsequent_auth_detail(item)?;
         let authorization_indicator_type =
-            item.request.capture_method.map(|c| AuthorizationIndicator {
-                authorization_indicator: c.into(),
-            });
+            item.router_data
+                .request
+                .capture_method
+                .map(|c| AuthorizationIndicator {
+                    authorization_indicator: c.into(),
+                });
         let transaction_request = TransactionRequest {
-            transaction_type: TransactionType::from(item.request.capture_method),
-            amount: utils::to_currency_base_unit_asf64(item.request.amount, item.request.currency)?,
+            transaction_type: TransactionType::from(item.router_data.request.capture_method),
+            amount: item.amount,
             payment: payment_details,
-            currency_code: item.request.currency.to_string(),
+            currency_code: item.router_data.request.currency.to_string(),
             processing_options,
             subsequent_auth_information,
             authorization_indicator_type,
         };
 
-        let merchant_authentication = AuthorizedotnetAuthType::try_from(&item.connector_auth_type)?;
+        let merchant_authentication =
+            AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;
 
         Ok(Self {
             create_transaction_request: AuthorizedotnetPaymentsRequest {
@@ -313,19 +357,25 @@ impl TryFrom<&types::PaymentsCancelRouterData> for CancelOrCaptureTransactionReq
     }
 }
 
-impl TryFrom<&types::PaymentsCaptureRouterData> for CancelOrCaptureTransactionRequest {
+impl TryFrom<&AuthorizedotnetRouterData<&types::PaymentsCaptureRouterData>>
+    for CancelOrCaptureTransactionRequest
+{
     type Error = error_stack::Report<errors::ConnectorError>;
-    fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
+    fn try_from(
+        item: &AuthorizedotnetRouterData<&types::PaymentsCaptureRouterData>,
+    ) -> Result<Self, Self::Error> {
         let transaction_request = TransactionVoidOrCaptureRequest {
-            amount: Some(utils::to_currency_base_unit_asf64(
-                item.request.amount_to_capture,
-                item.request.currency,
-            )?),
+            amount: Some(item.amount),
             transaction_type: TransactionType::Capture,
-            ref_trans_id: item.request.connector_transaction_id.to_string(),
+            ref_trans_id: item
+                .router_data
+                .request
+                .connector_transaction_id
+                .to_string(),
         };
 
-        let merchant_authentication = AuthorizedotnetAuthType::try_from(&item.connector_auth_type)?;
+        let merchant_authentication =
+            AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;
 
         Ok(Self {
             create_transaction_request: AuthorizedotnetPaymentCancelOrCaptureRequest {
@@ -648,10 +698,13 @@ pub struct CreateRefundRequest {
     create_transaction_request: AuthorizedotnetRefundRequest,
 }
 
-impl<F> TryFrom<&types::RefundsRouterData<F>> for CreateRefundRequest {
+impl<F> TryFrom<&AuthorizedotnetRouterData<&types::RefundsRouterData<F>>> for CreateRefundRequest {
     type Error = error_stack::Report<errors::ConnectorError>;
-    fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
+    fn try_from(
+        item: &AuthorizedotnetRouterData<&types::RefundsRouterData<F>>,
+    ) -> Result<Self, Self::Error> {
         let payment_details = item
+            .router_data
             .request
             .connector_metadata
             .as_ref()
@@ -661,21 +714,19 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for CreateRefundRequest {
             })?
             .clone();
 
-        let merchant_authentication = AuthorizedotnetAuthType::try_from(&item.connector_auth_type)?;
+        let merchant_authentication =
+            AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;
 
         let transaction_request = RefundTransactionRequest {
             transaction_type: TransactionType::Refund,
-            amount: utils::to_currency_base_unit_asf64(
-                item.request.refund_amount,
-                item.request.currency,
-            )?,
+            amount: item.amount,
             payment: payment_details
                 .parse_value("PaymentDetails")
                 .change_context(errors::ConnectorError::MissingRequiredField {
                     field_name: "payment_details",
                 })?,
-            currency_code: item.request.currency.to_string(),
-            reference_transaction_id: item.request.connector_transaction_id.clone(),
+            currency_code: item.router_data.request.currency.to_string(),
+            reference_transaction_id: item.router_data.request.connector_transaction_id.clone(),
         };
 
         Ok(Self {
@@ -750,12 +801,17 @@ pub struct AuthorizedotnetCreateSyncRequest {
     get_transaction_details_request: TransactionDetails,
 }
 
-impl<F> TryFrom<&types::RefundsRouterData<F>> for AuthorizedotnetCreateSyncRequest {
+impl<F> TryFrom<&AuthorizedotnetRouterData<&types::RefundsRouterData<F>>>
+    for AuthorizedotnetCreateSyncRequest
+{
     type Error = error_stack::Report<errors::ConnectorError>;
 
-    fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
-        let transaction_id = item.request.get_connector_refund_id()?;
-        let merchant_authentication = AuthorizedotnetAuthType::try_from(&item.connector_auth_type)?;
+    fn try_from(
+        item: &AuthorizedotnetRouterData<&types::RefundsRouterData<F>>,
+    ) -> Result<Self, Self::Error> {
+        let transaction_id = item.router_data.request.get_connector_refund_id()?;
+        let merchant_authentication =
+            AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;
 
         let payload = Self {
             get_transaction_details_request: TransactionDetails {
@@ -1131,10 +1187,15 @@ pub struct PaypalQueryParams {
     payer_id: String,
 }
 
-impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for PaypalConfirmRequest {
+impl TryFrom<&AuthorizedotnetRouterData<&types::PaymentsCompleteAuthorizeRouterData>>
+    for PaypalConfirmRequest
+{
     type Error = error_stack::Report<errors::ConnectorError>;
-    fn try_from(item: &types::PaymentsCompleteAuthorizeRouterData) -> Result<Self, Self::Error> {
+    fn try_from(
+        item: &AuthorizedotnetRouterData<&types::PaymentsCompleteAuthorizeRouterData>,
+    ) -> Result<Self, Self::Error> {
         let params = item
+            .router_data
             .request
             .redirect_response
             .as_ref()
@@ -1146,7 +1207,7 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for PaypalConfirmReque
                 .change_context(errors::ConnectorError::ResponseDeserializationFailed)?
                 .payer_id,
         );
-        let transaction_type = match item.request.capture_method {
+        let transaction_type = match item.router_data.request.capture_method {
             Some(enums::CaptureMethod::Manual) => TransactionType::ContinueAuthorization,
             _ => TransactionType::ContinueCapture,
         };
@@ -1155,10 +1216,11 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for PaypalConfirmReque
             payment: PaypalPaymentConfirm {
                 pay_pal: Paypal { payer_id },
             },
-            ref_trans_id: item.request.connector_transaction_id.clone(),
+            ref_trans_id: item.router_data.request.connector_transaction_id.clone(),
         };
 
-        let merchant_authentication = AuthorizedotnetAuthType::try_from(&item.connector_auth_type)?;
+        let merchant_authentication =
+            AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;
 
         Ok(Self {
             create_transaction_request: PaypalConfirmTransactionRequest {

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [ ] New feature
- [ ] Enhancement
- [X] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
<!-- Describe your changes in detail -->


### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
Fixes #2218 


## Checklist
<!-- Put an `x` in the boxes that apply -->

- [X] I formatted the code `cargo +nightly fmt --all`
- [ ] I addressed lints thrown by `cargo clippy`
- [X] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
