Bug: [Refactor] Use recurring enabled flag to decide which payment method supports MIT



### Feature Description

 Use recurring enabled flag to decide which payment method supports MIT

### Possible Implementation

 Use recurring enabled flag to decide which payment method supports MIT

### Have you spent some time checking if this feature request 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/diesel_models/src/query/merchant_connector_account.rs b/crates/diesel_models/src/query/merchant_connector_account.rs
index bd24d12ec22..cc73bd7a532 100644
--- a/crates/diesel_models/src/query/merchant_connector_account.rs
+++ b/crates/diesel_models/src/query/merchant_connector_account.rs
@@ -124,7 +124,9 @@ impl MerchantConnectorAccount {
         if get_disabled {
             generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
                 conn,
-                dsl::merchant_id.eq(merchant_id.to_owned()),
+                dsl::merchant_id
+                    .eq(merchant_id.to_owned())
+                    .and(dsl::disabled.eq(true)),
                 None,
                 None,
                 Some(dsl::created_at.asc()),
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 657ad625045..28121ecc801 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -3525,7 +3525,22 @@ pub async fn list_customer_payment_method(
         )
         .await
         .attach_printable("unable to decrypt payment method billing address details")?;
-
+        let connector_mandate_details = pm
+            .connector_mandate_details
+            .clone()
+            .map(|val| {
+                val.parse_value::<storage::PaymentsMandateReference>("PaymentsMandateReference")
+            })
+            .transpose()
+            .change_context(errors::ApiErrorResponse::InternalServerError)
+            .attach_printable("Failed to deserialize to Payment Mandate Reference ")?;
+        let mca_enabled = get_mca_status(
+            state,
+            &key_store,
+            &merchant_account.merchant_id,
+            connector_mandate_details,
+        )
+        .await?;
         // Need validation for enabled payment method ,querying MCA
         let pma = api::CustomerPaymentMethod {
             payment_token: parent_payment_method_token.to_owned(),
@@ -3537,7 +3552,7 @@ pub async fn list_customer_payment_method(
             card: payment_method_retrieval_context.card_details,
             metadata: pm.metadata,
             payment_method_issuer_code: pm.payment_method_issuer_code,
-            recurring_enabled: false,
+            recurring_enabled: mca_enabled,
             installment_payment_enabled: false,
             payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
             created: Some(pm.created_at),
@@ -3667,7 +3682,38 @@ pub async fn list_customer_payment_method(
 
     Ok(services::ApplicationResponse::Json(response))
 }
+pub async fn get_mca_status(
+    state: &routes::AppState,
+    key_store: &domain::MerchantKeyStore,
+    merchant_id: &str,
+    connector_mandate_details: Option<storage::PaymentsMandateReference>,
+) -> errors::RouterResult<bool> {
+    if let Some(connector_mandate_details) = connector_mandate_details {
+        let mcas = state
+            .store
+            .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+                merchant_id,
+                true,
+                key_store,
+            )
+            .await
+            .change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+                id: merchant_id.to_string(),
+            })?;
+        let mut mca_ids = HashSet::new();
 
+        for mca in mcas {
+            mca_ids.insert(mca.merchant_connector_id);
+        }
+
+        for mca_id in connector_mandate_details.keys() {
+            if !mca_ids.contains(mca_id) {
+                return Ok(true);
+            }
+        }
+    }
+    Ok(false)
+}
 pub async fn decrypt_generic_data<T>(
     data: Option<Encryption>,
     key: &[u8],

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

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

## Description
use recurring enabled flag in the lIst Customer Payment Method to decide which payment method supports MIT.


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

- Create a MA and a MCA with 2 connectors , cybersource and stripe
- Create a mandate payment with one card , lets say using stripe
- create a mandate payment with some pm, let's say wallet with the connector cybersource
- list the payment methods for the customer, the card which has mandate enabled will have the recurring field as true else false
> So in the below case have not disabled any mca and then you do a list the recurring enabled field will come as true
```
Response
{
    "customer_payment_methods": [
        {
            "payment_token": "token_HeBYwsQiiuwKosGloeAF",
            "payment_method_id": "pm_N1PKc4pShnNg3zCCKFrY",
            "customer_id": "CustomerX",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "4242",
                "expiry_month": "11",
                "expiry_year": "2040",
                "card_token": null,
                "card_holder_name": "AKA",
                "card_fingerprint": null,
                "nick_name": "HELO",
                "card_network": null,
                "card_isin": "424242",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-05-23T07:11:00.434Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-23T07:11:00.434Z",
            "default_payment_method_set": false,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+91"
                },
                "email": null
            }
        },
        {
            "payment_token": "token_lMFXXJEri6mOFZOc0q1Y",
            "payment_method_id": "pm_rHGmYfEiZU2tMjFV3Gka",
            "customer_id": "CustomerX",
            "payment_method": "wallet",
            "payment_method_type": "google_pay",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": null,
            "metadata": null,
            "created": "2024-05-22T19:01:56.041Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-22T19:01:56.041Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "AE",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "Dubai",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+97"
                },
                "email": null
            }
        }
    ],
    "is_guest_customer": null
}
```
> Now if you disable cybersource then the list pm will show the recurring enabled field for wallets as false
<img width="1680" alt="Screenshot 2024-05-23 at 12 46 15 PM" src="https://github.com/juspay/hyperswitch/assets/55580080/11902155-dff0-4cf9-a4a0-7413810ea013">

```
Response
{
    "customer_payment_methods": [
        {
            "payment_token": "token_P93Wev0NlWNzCqr0nHzz",
            "payment_method_id": "pm_N1PKc4pShnNg3zCCKFrY",
            "customer_id": "CustomerX",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "4242",
                "expiry_month": "11",
                "expiry_year": "2040",
                "card_token": null,
                "card_holder_name": "AKA",
                "card_fingerprint": null,
                "nick_name": "HELO",
                "card_network": null,
                "card_isin": "424242",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-05-23T07:11:00.434Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-23T07:11:00.434Z",
            "default_payment_method_set": false,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+91"
                },
                "email": null
            }
        },
        {
            "payment_token": "token_MaQ7pdm33YgwUHQtOSFe",
            "payment_method_id": "pm_rHGmYfEiZU2tMjFV3Gka",
            "customer_id": "CustomerX",
            "payment_method": "wallet",
            "payment_method_type": "google_pay",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": null,
            "metadata": null,
            "created": "2024-05-22T19:01:56.041Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-22T19:01:56.041Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "AE",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "Dubai",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+97"
                },
                "email": null
            }
        }
    ],
    "is_guest_customer": null
}
```
> Make a on_session payment with some other card, lets say `4111`, the recurring enabled will be false as there was no mandate setup with the connector
```
Create
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_7bjDyp3n0wrRt2q8JiftvA6eggv0vWNQNNSFL7YgtDg0q4JTQIPvvRJf9WF6FR9H' \
--data-raw ' {"amount": 7000,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
     "customer_id": "CustomerX",
    "email": "something@gmail.com",
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "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"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "metadata": {
        "order_details": {
            "product_name": "Apple iphone 15",
            "quantity": 1
        }
    },
    
    
   "setup_future_usage": "on_session"

    
}'
```
```
Confirm
curl --location 'http://localhost:8080/payments/pay_Ig6fQkfaXJfMYNWFYRp2/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_7bjDyp3n0wrRt2q8JiftvA6eggv0vWNQNNSFL7YgtDg0q4JTQIPvvRJf9WF6FR9H' \
--data '{
    "confirm": true,

          "payment_method": "card",
    "payment_method_type": "credit",



    "payment_method_data": {
        "card": {
                
              "card_number": "4111111111111111",
            
            
            "card_exp_month": "12",
            "card_exp_year": "2043",
            "card_holder_name": "Cy1",
            "card_cvc": "123"
        }
    },
    
        
             "routing": {
        "type": "single",
        "data": {"connector":"cybersource","merchant_connector_id":"mca_JfI8xFhxTnL5q2bFhpUW"}
      },
      "customer_acceptance": {
            "acceptance_type": "offline",
            "accepted_at": "1963-05-03T04:07:52.723Z",
            "online": {
                "ip_address": "in sit",
                "user_agent": "amet irure esse"
            }}

}'
```
```
Response
{
    "customer_payment_methods": [
        {
            "payment_token": "token_bz048kmTQUOIn9ZVXt6P",
            "payment_method_id": "pm_SkeqCzMYhN4ztURPxxw9",
            "customer_id": "CustomerX",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "1111",
                "expiry_month": "12",
                "expiry_year": "2043",
                "card_token": null,
                "card_holder_name": "Cy1",
                "card_fingerprint": null,
                "nick_name": null,
                "card_network": null,
                "card_isin": "411111",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-05-23T07:19:38.071Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-23T07:19:38.071Z",
            "default_payment_method_set": false,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+91"
                },
                "email": null
            }
        },
        {
            "payment_token": "token_XwND8wiXdMykgcfZQprc",
            "payment_method_id": "pm_N1PKc4pShnNg3zCCKFrY",
            "customer_id": "CustomerX",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "4242",
                "expiry_month": "11",
                "expiry_year": "2040",
                "card_token": null,
                "card_holder_name": "AKA",
                "card_fingerprint": null,
                "nick_name": "HELO",
                "card_network": null,
                "card_isin": "424242",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-05-23T07:11:00.434Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-23T07:11:00.434Z",
            "default_payment_method_set": false,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+91"
                },
                "email": null
            }
        },
        {
            "payment_token": "token_RDoIFRCyyWgRcaB2JPGa",
            "payment_method_id": "pm_rHGmYfEiZU2tMjFV3Gka",
            "customer_id": "CustomerX",
            "payment_method": "wallet",
            "payment_method_type": "google_pay",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": null,
            "metadata": null,
            "created": "2024-05-22T19:01:56.041Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-05-22T19:01:56.041Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "AE",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "Dubai",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+97"
                },
                "email": null
            }
        }
    ],
    "is_guest_customer": null
}
```

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

- [ ] 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
