Bug: [FEATURE]: [Dlocal] 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/dlocal.rs b/crates/router/src/connector/dlocal.rs
index 90be2399ba0..b706d694a3d 100644
--- a/crates/router/src/connector/dlocal.rs
+++ b/crates/router/src/connector/dlocal.rs
@@ -109,6 +109,10 @@ impl ConnectorCommon for Dlocal {
         "dlocal"
     }
 
+    fn get_currency_unit(&self) -> api::CurrencyUnit {
+        api::CurrencyUnit::Minor
+    }
+
     fn common_get_content_type(&self) -> &'static str {
         "application/json"
     }
@@ -207,7 +211,13 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
         &self,
         req: &types::PaymentsAuthorizeRouterData,
     ) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
-        let connector_request = dlocal::DlocalPaymentsRequest::try_from(req)?;
+        let connector_router_data = dlocal::DlocalRouterData::try_from((
+            &self.get_currency_unit(),
+            req.request.currency,
+            req.request.amount,
+            req,
+        ))?;
+        let connector_request = dlocal::DlocalPaymentsRequest::try_from(&connector_router_data)?;
         let dlocal_payments_request = types::RequestBody::log_and_get_request_body(
             &connector_request,
             utils::Encode::<dlocal::DlocalPaymentsRequest>::encode_to_string_of_json,
@@ -508,10 +518,16 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
         &self,
         req: &types::RefundsRouterData<api::Execute>,
     ) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
-        let connector_request = dlocal::RefundRequest::try_from(req)?;
+        let connector_router_data = dlocal::DlocalRouterData::try_from((
+            &self.get_currency_unit(),
+            req.request.currency,
+            req.request.refund_amount,
+            req,
+        ))?;
+        let connector_request = dlocal::DlocalRefundRequest::try_from(&connector_router_data)?;
         let dlocal_refund_request = types::RequestBody::log_and_get_request_body(
             &connector_request,
-            utils::Encode::<dlocal::RefundRequest>::encode_to_string_of_json,
+            utils::Encode::<dlocal::DlocalRefundRequest>::encode_to_string_of_json,
         )
         .change_context(errors::ConnectorError::RequestEncodingFailed)?;
         Ok(Some(dlocal_refund_request))
diff --git a/crates/router/src/connector/dlocal/transformers.rs b/crates/router/src/connector/dlocal/transformers.rs
index 8558836372e..87562fa3344 100644
--- a/crates/router/src/connector/dlocal/transformers.rs
+++ b/crates/router/src/connector/dlocal/transformers.rs
@@ -51,6 +51,37 @@ pub enum PaymentMethodFlow {
     ReDirect,
 }
 
+#[derive(Debug, Serialize)]
+pub struct DlocalRouterData<T> {
+    pub amount: i64,
+    pub router_data: T,
+}
+
+impl<T>
+    TryFrom<(
+        &types::api::CurrencyUnit,
+        types::storage::enums::Currency,
+        i64,
+        T,
+    )> for DlocalRouterData<T>
+{
+    type Error = error_stack::Report<errors::ConnectorError>;
+
+    fn try_from(
+        (_currency_unit, _currency, amount, router_data): (
+            &types::api::CurrencyUnit,
+            types::storage::enums::Currency,
+            i64,
+            T,
+        ),
+    ) -> Result<Self, Self::Error> {
+        Ok(Self {
+            amount,
+            router_data,
+        })
+    }
+}
+
 #[derive(Default, Debug, Serialize, Eq, PartialEq)]
 pub struct DlocalPaymentsRequest {
     pub amount: i64,
@@ -66,22 +97,24 @@ pub struct DlocalPaymentsRequest {
     pub description: Option<String>,
 }
 
-impl TryFrom<&types::PaymentsAuthorizeRouterData> for DlocalPaymentsRequest {
+impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalPaymentsRequest {
     type Error = error_stack::Report<errors::ConnectorError>;
-    fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
-        let email = item.request.email.clone();
-        let address = item.get_billing_address()?;
+    fn try_from(
+        item: &DlocalRouterData<&types::PaymentsAuthorizeRouterData>,
+    ) -> Result<Self, Self::Error> {
+        let email = item.router_data.request.email.clone();
+        let address = item.router_data.get_billing_address()?;
         let country = address.get_country()?;
         let name = get_payer_name(address);
-        match item.request.payment_method_data {
+        match item.router_data.request.payment_method_data {
             api::PaymentMethodData::Card(ref ccard) => {
                 let should_capture = matches!(
-                    item.request.capture_method,
+                    item.router_data.request.capture_method,
                     Some(enums::CaptureMethod::Automatic)
                 );
                 let payment_request = Self {
-                    amount: item.request.amount,
-                    currency: item.request.currency,
+                    amount: item.amount,
+                    currency: item.router_data.request.currency,
                     payment_method_id: PaymentMethodId::Card,
                     payment_method_flow: PaymentMethodFlow::Direct,
                     country: country.to_string(),
@@ -99,22 +132,28 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for DlocalPaymentsRequest {
                         expiration_year: ccard.card_exp_year.clone(),
                         capture: should_capture.to_string(),
                         installments_id: item
+                            .router_data
                             .request
                             .mandate_id
                             .as_ref()
                             .map(|ids| ids.mandate_id.clone()),
                         // [#595[FEATURE] Pass Mandate history information in payment flows/request]
-                        installments: item.request.mandate_id.clone().map(|_| "1".to_string()),
+                        installments: item
+                            .router_data
+                            .request
+                            .mandate_id
+                            .clone()
+                            .map(|_| "1".to_string()),
                     }),
-                    order_id: item.payment_id.clone(),
-                    three_dsecure: match item.auth_type {
+                    order_id: item.router_data.payment_id.clone(),
+                    three_dsecure: match item.router_data.auth_type {
                         diesel_models::enums::AuthenticationType::ThreeDs => {
                             Some(ThreeDSecureReqData { force: true })
                         }
                         diesel_models::enums::AuthenticationType::NoThreeDs => None,
                     },
-                    callback_url: Some(item.request.get_router_return_url()?),
-                    description: item.description.clone(),
+                    callback_url: Some(item.router_data.request.get_router_return_url()?),
+                    description: item.router_data.description.clone(),
                 };
                 Ok(payment_request)
             }
@@ -399,22 +438,24 @@ impl<F, T>
 
 // REFUND :
 #[derive(Default, Debug, Serialize)]
-pub struct RefundRequest {
+pub struct DlocalRefundRequest {
     pub amount: String,
     pub payment_id: String,
     pub currency: enums::Currency,
     pub id: String,
 }
 
-impl<F> TryFrom<&types::RefundsRouterData<F>> for RefundRequest {
+impl<F> TryFrom<&DlocalRouterData<&types::RefundsRouterData<F>>> for DlocalRefundRequest {
     type Error = error_stack::Report<errors::ConnectorError>;
-    fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
-        let amount_to_refund = item.request.refund_amount.to_string();
+    fn try_from(
+        item: &DlocalRouterData<&types::RefundsRouterData<F>>,
+    ) -> Result<Self, Self::Error> {
+        let amount_to_refund = item.router_data.request.refund_amount.to_string();
         Ok(Self {
             amount: amount_to_refund,
-            payment_id: item.request.connector_transaction_id.clone(),
-            currency: item.request.currency,
-            id: item.request.refund_id.clone(),
+            payment_id: item.router_data.request.connector_transaction_id.clone(),
+            currency: item.router_data.request.currency,
+            id: item.router_data.request.refund_id.clone(),
         })
     }
 }

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

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

## Description
- Addressing Issue: #2223 
- Modified two files in `hyperswitch/crates/router/src/connector/`
  - `dlocal.rs`
    - Implement `get_currency_unit` function
    - Modify `ConnectorIntegration` implementations for `Dlocal`
  - `dlocal/transformers.rs`
    - Implement `DlocalRouterData<T>` structure and functionality
    - Modify implementation for `DlocalPaymentsRequest`

### 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).
-->


## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->


## 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`
- [ ] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
