Bug: [BUG] payout operations are using payment connectors



### Bug Description

In case payment connectors were added prior to adding the same payout connector (Eg - onboarding `Adyen` as `payment_processor` and then onboarding `Adyen` as `payout_processor`), the payout transactions are routed via payment transactions (the first onboarding of the connector with the same name)

### Expected Behavior

Payout operations should make sure the payout txns are routed only through payout processors.

### Actual Behavior

Payout operations are routed through the first same processor that was onboarded (payments in this case)

### Steps for reproducing
1. Create a new merchant account
2. Create a payment processor (preferrably Adyen)
3. Create a payout processor for the same connector name (Adyen)
4. Make a payout transaction
5. Payout transaction should be routed through the payment connector

### Have you spent some time checking if this bug has been raised before?

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

### Have you read the Contributing Guidelines?

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

### Are you willing to submit a PR?

Yes, I am willing to submit a PR!
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 07b50d3a154..44a3983a96a 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -1106,7 +1106,7 @@ pub async fn create_recipient(
         // 1. Form router data
         let router_data = core_utils::construct_payout_router_data(
             state,
-            &connector_data.connector_name,
+            connector_data,
             merchant_account,
             key_store,
             payout_data,
@@ -1273,7 +1273,7 @@ pub async fn check_payout_eligibility(
     // 1. Form Router data
     let router_data = core_utils::construct_payout_router_data(
         state,
-        &connector_data.connector_name,
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
@@ -1453,7 +1453,7 @@ pub async fn create_payout(
     // 1. Form Router data
     let mut router_data = core_utils::construct_payout_router_data(
         state,
-        &connector_data.connector_name,
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
@@ -1645,7 +1645,7 @@ pub async fn create_payout_retrieve(
     // 1. Form Router data
     let mut router_data = core_utils::construct_payout_router_data(
         state,
-        &connector_data.connector_name,
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
@@ -1787,7 +1787,7 @@ pub async fn create_recipient_disburse_account(
     // 1. Form Router data
     let router_data = core_utils::construct_payout_router_data(
         state,
-        &connector_data.connector_name,
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
@@ -1872,7 +1872,7 @@ pub async fn cancel_payout(
     // 1. Form Router data
     let router_data = core_utils::construct_payout_router_data(
         state,
-        &connector_data.connector_name,
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
@@ -1977,7 +1977,7 @@ pub async fn fulfill_payout(
     // 1. Form Router data
     let mut router_data = core_utils::construct_payout_router_data(
         state,
-        &connector_data.connector_name,
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 7bc4505b973..d5af1f20afb 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -30,7 +30,7 @@ use crate::{
     db::StorageInterface,
     routes::SessionState,
     types::{
-        self, domain,
+        self, api, domain,
         storage::{self, enums},
         PollConfig,
     },
@@ -49,7 +49,7 @@ const IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_attempt_id_in_di
 #[instrument(skip_all)]
 pub async fn get_mca_for_payout<'a>(
     state: &'a SessionState,
-    connector_id: &str,
+    connector_data: &api::ConnectorData,
     merchant_account: &domain::MerchantAccount,
     key_store: &domain::MerchantKeyStore,
     payout_data: &PayoutData,
@@ -63,8 +63,8 @@ pub async fn get_mca_for_payout<'a>(
                 None,
                 key_store,
                 &payout_data.profile_id,
-                connector_id,
-                payout_data.payout_attempt.merchant_connector_id.as_ref(),
+                &connector_data.connector_name.to_string(),
+                connector_data.merchant_connector_id.as_ref(),
             )
             .await?;
             Ok(merchant_connector_account)
@@ -76,19 +76,20 @@ pub async fn get_mca_for_payout<'a>(
 #[instrument(skip_all)]
 pub async fn construct_payout_router_data<'a, F>(
     state: &'a SessionState,
-    connector_name: &api_models::enums::Connector,
+    connector_data: &api::ConnectorData,
     merchant_account: &domain::MerchantAccount,
     key_store: &domain::MerchantKeyStore,
     payout_data: &mut PayoutData,
 ) -> RouterResult<types::PayoutsRouterData<F>> {
     let merchant_connector_account = get_mca_for_payout(
         state,
-        &connector_name.to_string(),
+        connector_data,
         merchant_account,
         key_store,
         payout_data,
     )
     .await?;
+    let connector_name = connector_data.connector_name;
     payout_data.merchant_connector_account = Some(merchant_connector_account.clone());
     let connector_auth_type: types::ConnectorAuthType = merchant_connector_account
         .get_connector_account_details()
@@ -770,7 +771,7 @@ pub async fn construct_upload_file_router_data<'a>(
     payment_attempt: &storage::PaymentAttempt,
     merchant_account: &domain::MerchantAccount,
     key_store: &domain::MerchantKeyStore,
-    create_file_request: &types::api::CreateFileRequest,
+    create_file_request: &api::CreateFileRequest,
     connector_id: &str,
     file_key: String,
 ) -> RouterResult<types::UploadFileRouterData> {

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

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

## Description
Described in #5621 

### 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`
-->


## How did you test it?
<details>
    <summary>1. Create a merchant account</summary>
    curl --location 'https://sandbox.hyperswitch.io/accounts' \
        --header 'Content-Type: application/json' \
        --header 'Accept: application/json' \
        --header 'api-key: test_admin' \
        --data-raw '{
            "merchant_id": "merchant_1723634705",
            "locker_id": "m0010",
            "merchant_name": "NewAge Retailer",
            "merchant_details": {
                "primary_contact_person": "John Test",
                "primary_email": "JohnTest@test.com",
                "primary_phone": "sunt laborum",
                "secondary_contact_person": "John Test2",
                "secondary_email": "JohnTest2@test.com",
                "secondary_phone": "cillum do dolor id",
                "website": "https://www.example.com",
                "about_business": "Online Retail with a wide selection of organic products for North America",
                "address": {
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "city": "San Fransico",
                    "state": "California",
                    "zip": "94122",
                    "country": "US"
                }
            },
            "return_url": "https://google.com/success",
            "webhook_details": {
                "webhook_version": "1.0.1",
                "webhook_username": "ekart_retail",
                "webhook_password": "password_ekart@123",
                "payment_created_enabled": true,
                "payment_succeeded_enabled": true,
                "payment_failed_enabled": true
            },
            "sub_merchants_enabled": false,
            "metadata": {
                "city": "NY",
                "unit": "245"
            },
            "primary_business_details": [
                {
                    "country": "US",
                    "business": "food"
                }
            ]
        }'
</details>

<details>
    <summary>2. Create a payment connector</summary>
    curl --location 'https://sandbox.hyperswitch.io/account/merchant_1723447743/connectors' \
        --header 'Content-Type: application/json' \
        --header 'Accept: application/json' \
        --header 'x-feature: integ-custom' \
        --header 'api-key: test_admin' \
        --data '{
            "connector_type": "payment_processor",
            "connector_name": "adyen",
            "connector_label": "adyen_payments",
            "connector_account_details": {
                "auth_type": "SignatureKey",
                "api_key": "adyen_api_key",
                "key1": "adyen_key1",
                "api_secret": "adyen_api_secret"
            },
            "test_mode": true,
            "disabled": false,
            "metadata": {
                "city": "NY",
                "unit": "245",
                "endpoint_prefix": ""
            },
            "payment_methods_enabled": [
                {
                    "payment_method": "card",
                    "payment_method_types": [
                        {
                            "payment_method_type": "credit",
                            "minimum_amount": 1,
                            "maximum_amount": 68607706,
                            "recurring_enabled": true,
                            "installment_payment_enabled": true
                        },
                        {
                            "payment_method_type": "debit",
                            "minimum_amount": 1,
                            "maximum_amount": 68607706,
                            "recurring_enabled": true,
                            "installment_payment_enabled": true
                        }
                    ]
                },
                {
                    "payment_method": "bank_transfer",
                    "payment_method_types": [
                        {
                            "payment_method_type": "sepa",
                            "minimum_amount": 1,
                            "maximum_amount": 68607706,
                            "recurring_enabled": true,
                            "installment_payment_enabled": true
                        }
                    ]
                }
            ]
        }'
</details>

<details>
    <summary>3. Create a payout connector</summary>
    curl --location 'https://sandbox.hyperswitch.io/account/merchant_1723447743/connectors' \
        --header 'Content-Type: application/json' \
        --header 'Accept: application/json' \
        --header 'x-feature: integ-custom' \
        --header 'api-key: test_admin' \
        --data '{
            "connector_type": "payout_processor",
            "connector_name": "adyen",
            "connector_label": "adyen_payouts",
            "connector_account_details": {
                "auth_type": "SignatureKey",
                "api_key": "AQEphmfuXNWTK0Qc+iSEl3cshueYR55DGcESCNGoI7BTPLxjT7UBfl5QRzAQwV1bDb7kfNy1WIxIIkxgBw==-ziErjWyNKGE3hIz5kq+BUr2d82K2zdzE7Ums4FmpQxs=-#8zJ+$%]+;6:%q&X",
                "key1": "TestAccount280ECOM",
                "api_secret": "AQE6g3HYdt+JC0QL7H+krT1r87XJHatuAp5aWWtPiEyujXJqncR5Bch1VG8x3TFphs7fQO2UDw7kAnLvtRDBXVsNvuR83LVYjEgiTGAH-37o4c1326UtLekCWoFi9y/Do/RdojTYJHWjrz9PRZIM=-uxYPa9ju]2F3YVn)"
            },
            "test_mode": true,
            "disabled": false,
            "metadata": {
                "city": "NY",
                "unit": "245",
                "endpoint_prefix": ""
            },
            "payment_methods_enabled": [
                {
                    "payment_method": "card",
                    "payment_method_types": [
                        {
                            "payment_method_type": "credit",
                            "minimum_amount": 1,
                            "maximum_amount": 68607706,
                            "recurring_enabled": true,
                            "installment_payment_enabled": true
                        },
                        {
                            "payment_method_type": "debit",
                            "minimum_amount": 1,
                            "maximum_amount": 68607706,
                            "recurring_enabled": true,
                            "installment_payment_enabled": true
                        }
                    ]
                },
                {
                    "payment_method": "bank_transfer",
                    "payment_method_types": [
                        {
                            "payment_method_type": "sepa",
                            "minimum_amount": 1,
                            "maximum_amount": 68607706,
                            "recurring_enabled": true,
                            "installment_payment_enabled": true
                        }
                    ]
                }
            ]
        }'
</details>

<details>
    <summary>4. Create a payment txn</summary>
    curl --location 'https://sandbox.hyperswitch.io/payments' \
        --header 'Content-Type: application/json' \
        --header 'Accept: application/json' \
        --header 'api-key: snd_QwyXwKBhuv9cLgvQHoBSg7393kQIIb9UyhZZoDIZdG9LlOUDBgxGl8fQNApUw4i9' \
        --data '{
            "amount": 6540,
            "currency": "USD",
            "confirm": true,
            "capture_method": "automatic",
            "capture_on": "2022-09-10T10:11:12Z",
            "amount_to_capture": 6540,
            "description": "Its my first payment request",
            "authentication_type": "no_three_ds",
            "return_url": "https://google.com",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_data": {
                "card": {
                    "card_number": "4242424242424242",
                    "card_exp_month": "10",
                    "card_exp_year": "25",
                    "card_holder_name": "joseph Doe",
                    "card_cvc": "123"
                }
            },
            "billing": {
                "address": {
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "city": "San Fransico",
                    "state": "California",
                    "zip": "94122",
                    "country": "US",
                    "first_name": "joseph",
                    "last_name": "Doe"
                }
            },
            "browser_info": {
                "color_depth": 2,
                "java_enabled": false,
                "java_script_enabled": true,
                "language": "en",
                "screen_height": 100,
                "screen_width": 200,
                "time_zone": 530,
                "ip_address": "127.0.0.1",
                "accept_header": "-",
                "user_agent": "Mozilla"
            },
            "statement_descriptor_name": "joseph",
            "statement_descriptor_suffix": "JS",
            "metadata": {
                "udf1": "value1",
                "new_customer": "true",
                "login_date": "2019-09-10T10:11:12Z"
            },
            "business_label": "food",
            "business_country": "US"
        }'
</details>

<details>
    <summary>5. Create a payout txn</summary>
    curl --location 'https://sandbox.hyperswitch.io/payouts/create' \
        --header 'Content-Type: application/json' \
        --header 'api-key: snd_QwyXwKBhuv9cLgvQHoBSg7393kQIIb9UyhZZoDIZdG9LlOUDBgxGl8fQNApUw4i9' \
        --data-raw '{
            "amount": 100,
            "currency": "EUR",
            "profile_id": "pro_zPFmAstI3w3Ekf903ReS",
            "customer": {
                "id": "new_id",
                "email": "new_cust@example.com",
                "name": "John Doe",
                "phone": "999999999",
                "phone_country_code": "+65"
            },
            "connector": [
                "adyen"
            ],
            "description": "Its my first payout request",
            "payout_type": "card",
            "payout_method_data": {
                "card": {
                    "card_number": "4111111111111111",
                    "expiry_month": "3",
                    "expiry_year": "2030",
                    "card_holder_name": "John Doe"
                }
            },
            "billing": {
                "address": {
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "city": "San Fransico",
                    "state": "CA",
                    "zip": "94122",
                    "country": "US",
                    "first_name": "John",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+91"
                }
            },
            "entity_type": "Individual",
            "recurring": true,
            "metadata": {
                "ref": "123"
            },
            "confirm": true,
            "auto_fulfill": true
        }'
</details>

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

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
