Bug: [Refactor] Send an appropriate error if update_mandate is not supported



### Feature Description

Send an appropriate error if update_mandate is not  also add support for allowing the payment with payment_method
_type as None

### Possible Implementation

- Improvise theImplementation if its a Card
- Thorw an appropriate error

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

None
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 7b505e7c01c..b8b0fffe339 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -2136,12 +2136,33 @@ pub fn filter_pm_based_on_update_mandate_support_for_connector(
     payment_method_type: &api_enums::PaymentMethodType,
     connector: api_enums::Connector,
 ) -> bool {
-    supported_payment_methods_for_mandate
-        .0
-        .get(payment_method)
-        .and_then(|payment_method_type_hm| payment_method_type_hm.0.get(payment_method_type))
-        .map(|supported_connectors| supported_connectors.connector_list.contains(&connector))
-        .unwrap_or(false)
+    if payment_method == &api_enums::PaymentMethod::Card {
+        supported_payment_methods_for_mandate
+            .0
+            .get(payment_method)
+            .map(|payment_method_type_hm| {
+                let pm_credit = payment_method_type_hm
+                    .0
+                    .get(&api_enums::PaymentMethodType::Credit)
+                    .map(|conn| conn.connector_list.clone())
+                    .unwrap_or_default();
+                let pm_debit = payment_method_type_hm
+                    .0
+                    .get(&api_enums::PaymentMethodType::Debit)
+                    .map(|conn| conn.connector_list.clone())
+                    .unwrap_or_default();
+                &pm_credit | &pm_debit
+            })
+            .map(|supported_connectors| supported_connectors.contains(&connector))
+            .unwrap_or(false)
+    } else {
+        supported_payment_methods_for_mandate
+            .0
+            .get(payment_method)
+            .and_then(|payment_method_type_hm| payment_method_type_hm.0.get(payment_method_type))
+            .map(|supported_connectors| supported_connectors.connector_list.contains(&connector))
+            .unwrap_or(false)
+    }
 }
 
 fn filter_pm_based_on_supported_payments_for_mandate(
diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
index a81f97851d9..30918b2fe4e 100644
--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs
+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
@@ -1,3 +1,4 @@
+use api_models::enums::{PaymentMethod, PaymentMethodType};
 use async_trait::async_trait;
 use error_stack::{IntoReport, ResultExt};
 
@@ -275,17 +276,33 @@ impl types::SetupMandateRouterData {
         let payment_method_type = self.request.payment_method_type;
 
         let payment_method = self.request.payment_method_data.get_payment_method();
-        let supported_connectors_config =
-            payment_method
-                .zip(payment_method_type)
-                .map_or(false, |(pm, pmt)| {
+        let supported_connectors_config = payment_method.zip(payment_method_type).map_or_else(
+            || {
+                if payment_method == Some(PaymentMethod::Card) {
                     cards::filter_pm_based_on_update_mandate_support_for_connector(
                         supported_connectors_for_update_mandate,
-                        &pm,
-                        &pmt,
+                        &PaymentMethod::Card,
+                        &PaymentMethodType::Credit,
+                        connector.connector_name,
+                    ) && cards::filter_pm_based_on_update_mandate_support_for_connector(
+                        supported_connectors_for_update_mandate,
+                        &PaymentMethod::Card,
+                        &PaymentMethodType::Debit,
                         connector.connector_name,
                     )
-                });
+                } else {
+                    false
+                }
+            },
+            |(pm, pmt)| {
+                cards::filter_pm_based_on_update_mandate_support_for_connector(
+                    supported_connectors_for_update_mandate,
+                    &pm,
+                    &pmt,
+                    connector.connector_name,
+                )
+            },
+        );
         if supported_connectors_config {
             let connector_integration: services::BoxedConnectorIntegration<
                 '_,
@@ -378,9 +395,13 @@ impl types::SetupMandateRouterData {
                 Err(_) => Ok(resp),
             }
         } else {
-            Err(errors::ApiErrorResponse::InternalServerError)
-                .into_report()
-                .attach_printable("Update Mandate Flow not implemented for the connector ")?
+            Err(errors::ApiErrorResponse::PreconditionFailed {
+                message: format!(
+                    "Update Mandate flow not implemented for the connector {:?}",
+                    connector.connector_name
+                ),
+            })
+            .into_report()
         }
     }
 }
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 14d119768d0..c5232378615 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -256,9 +256,6 @@ bank_redirect.sofort = {connector_list = "stripe,adyen,globalpay"}
 card.credit ={connector_list ="cybersource"}
 card.debit = {connector_list ="cybersource"}
 
-[mandates.update_mandate_supported]
-connector_list = "cybersource"
-
 [analytics]
 source = "sqlx"
 
diff --git a/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario16-Bank debit-ach/Payments - Create/request.json b/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario16-Bank debit-ach/Payments - Create/request.json
index bc160467bf8..21c079e0ad0 100644
--- a/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario16-Bank debit-ach/Payments - Create/request.json	
+++ b/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario16-Bank debit-ach/Payments - Create/request.json	
@@ -31,7 +31,7 @@
       "description": "Its my first payment request",
       "authentication_type": "three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario17-Bank debit-Bacs/Payments - Create/request.json b/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario17-Bank debit-Bacs/Payments - Create/request.json
index 9340a493524..1ec9a829a48 100644
--- a/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario17-Bank debit-Bacs/Payments - Create/request.json	
+++ b/postman/collection-dir/adyen_uk/Flow Testcases/Happy Cases/Scenario17-Bank debit-Bacs/Payments - Create/request.json	
@@ -31,7 +31,7 @@
       "description": "Its my first payment request",
       "authentication_type": "no_three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario6-Create Wallet - Paypal/Payments - Create/request.json b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario6-Create Wallet - Paypal/Payments - Create/request.json
index f0066e67bbc..824bfb49230 100644
--- a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario6-Create Wallet - Paypal/Payments - Create/request.json	
+++ b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario6-Create Wallet - Paypal/Payments - Create/request.json	
@@ -32,7 +32,7 @@
       "description": "Its my first payment request",
       "authentication_type": "three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario7-Create Wallet - Paypal with confrm false/Payments - Create/request.json b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario7-Create Wallet - Paypal with confrm false/Payments - Create/request.json
index 792e7c399fc..9778d0ee32b 100644
--- a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario7-Create Wallet - Paypal with confrm false/Payments - Create/request.json	
+++ b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario7-Create Wallet - Paypal with confrm false/Payments - Create/request.json	
@@ -32,7 +32,7 @@
       "description": "Its my first payment request",
       "authentication_type": "three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario1-Create payment with confirm true/Payments - Create/request.json b/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario1-Create payment with confirm true/Payments - Create/request.json
index 0bf606d869e..7afc6d61c49 100644
--- a/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario1-Create payment with confirm true/Payments - Create/request.json	
+++ b/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario1-Create payment with confirm true/Payments - Create/request.json	
@@ -31,7 +31,7 @@
       "description": "Its my first payment request",
       "authentication_type": "no_three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario3-Create payment without PMD/Payments - Create/request.json b/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario3-Create payment without PMD/Payments - Create/request.json
index c2d7c7bf9c0..a6aef6ecb71 100644
--- a/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario3-Create payment without PMD/Payments - Create/request.json	
+++ b/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario3-Create payment without PMD/Payments - Create/request.json	
@@ -31,7 +31,7 @@
       "description": "Its my first payment request",
       "authentication_type": "no_three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario5-Create 3DS payment with confrm false/Payments - Create/request.json b/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario5-Create 3DS payment with confrm false/Payments - Create/request.json
index caa19cc5c67..01fa4013653 100644
--- a/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario5-Create 3DS payment with confrm false/Payments - Create/request.json	
+++ b/postman/collection-dir/zen/Flow Testcases/Happy Cases/Scenario5-Create 3DS payment with confrm false/Payments - Create/request.json	
@@ -31,7 +31,7 @@
       "description": "Its my first payment request",
       "authentication_type": "no_three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",
diff --git a/postman/collection-dir/zen/Flow Testcases/Variation Cases/Scenario2-Confirming the payment without PMD/Payments - Create/request.json b/postman/collection-dir/zen/Flow Testcases/Variation Cases/Scenario2-Confirming the payment without PMD/Payments - Create/request.json
index c2d7c7bf9c0..a6aef6ecb71 100644
--- a/postman/collection-dir/zen/Flow Testcases/Variation Cases/Scenario2-Confirming the payment without PMD/Payments - Create/request.json	
+++ b/postman/collection-dir/zen/Flow Testcases/Variation Cases/Scenario2-Confirming the payment without PMD/Payments - Create/request.json	
@@ -31,7 +31,7 @@
       "description": "Its my first payment request",
       "authentication_type": "no_three_ds",
       "return_url": "https://duck.com",
-      "setup_future_usage": "off_session",
+      "setup_future_usage": "on_session",
       "billing": {
         "address": {
           "line1": "1467",

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

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

## Description
Send an appropriate error if update_mandate is not also add support for allowing the payment with payment_method
_type as None and also fix the failing postman collection


### 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 an MCA with Cybersource
> Make a UpdateMandatePayment with `payment_method_type` as null
>Payment would succeed

![Screenshot 2024-02-08 at 4 48 42 PM](https://github.com/juspay/hyperswitch/assets/55580080/d362b690-1610-4e9a-a30e-c3a27e60f9b5)


- Create a MA and an MCA with Cybersource
- >Make a Payment , would throw a 4xx


## 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
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
