Bug: [FEATURE] Add a Filter for Payment Methods Visibility only if It allows the requested capture Method



### Feature Description

There should be only those Payment Methods Visible in **Payments Method's list** that supports the applied **Capture type**.

For a concise **example** If Merchant has provided for manual capture then only the connectors that support manual capture should be shown in the list so in that case we shouldn't show connectors like `Mollie, Trustpay` etc as they don't support manual capture for payments.

### Possible Implementation

First of all the change must be required in the Development.toml file to mark up the connectors that don't implement the manual capture as by default every connector implements automatic capture.

Next we need to add filter to remove the connectors from the list if manual capture mode is selected

### Have you spent some time to check if this feature request has been raised before?

- [X] I checked and didn't find 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/config/development.toml b/config/development.toml
index 07a005ae9a2..7ba940bc582 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -177,9 +177,33 @@ ideal = { country = "NL", currency = "EUR" }
 
 [pm_filters.braintree]
 paypal = { currency = "AUD,BRL,CAD,CNY,CZK,DKK,EUR,HKD,HUF,ILS,JPY,MYR,MXN,TWD,NZD,NOK,PHP,PLN,GBP,RUB,SGD,SEK,CHF,THB,USD" }
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
 
 [pm_filters.klarna]
 klarna = { country = "AU,AT,BE,CA,CZ,DK,FI,FR,DE,GR,IE,IT,NL,NZ,NO,PL,PT,ES,SE,CH,GB,US", currency = "AUD,EUR,EUR,CAD,CZK,DKK,EUR,EUR,EUR,EUR,EUR,EUR,EUR,NZD,NOK,PLN,EUR,EUR,SEK,CHF,GBP,USD" }
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
+
+[pm_filters.zen]
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
+
+[pm_filters.aci]
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
+
+[pm_filters.mollie]
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
+
+[pm_filters.multisafepay]
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
+
+[pm_filters.trustpay]
+credit = { not_available_flows = {capture_method="manual"} }
+debit =  { not_available_flows = {capture_method="manual"} }
 
 [pm_filters.authorizedotnet]
 google_pay = { currency = "CHF,DKK,EUR,GBP,NOK,PLN,SEK,USD,AUD,NZD,CAD" }
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 4955f437aa6..84f00d91fe1 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -4,6 +4,7 @@ use std::{
     str::FromStr,
 };
 
+use api_models::enums;
 use common_utils::ext_traits::ConfigExt;
 use config::{Environment, File};
 #[cfg(feature = "kms")]
@@ -112,7 +113,7 @@ pub struct ConnectorFilters(pub HashMap<String, PaymentMethodFilters>);
 
 #[derive(Debug, Deserialize, Clone, Default)]
 #[serde(transparent)]
-pub struct PaymentMethodFilters(pub HashMap<PaymentMethodFilterKey, CurrencyCountryFilter>);
+pub struct PaymentMethodFilters(pub HashMap<PaymentMethodFilterKey, CurrencyCountryFlowFilter>);
 
 #[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
 #[serde(untagged)]
@@ -123,11 +124,17 @@ pub enum PaymentMethodFilterKey {
 
 #[derive(Debug, Deserialize, Clone, Default)]
 #[serde(default)]
-pub struct CurrencyCountryFilter {
+pub struct CurrencyCountryFlowFilter {
     #[serde(deserialize_with = "currency_set_deser")]
     pub currency: Option<HashSet<api_models::enums::Currency>>,
     #[serde(deserialize_with = "string_set_deser")]
     pub country: Option<HashSet<api_models::enums::CountryAlpha2>>,
+    pub not_available_flows: Option<NotAvailableFlows>,
+}
+#[derive(Debug, Deserialize, Copy, Clone, Default)]
+#[serde(default)]
+pub struct NotAvailableFlows {
+    pub capture_method: Option<enums::CaptureMethod>,
 }
 
 fn string_set_deser<'a, D>(
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 8dc6b0ed7b9..5074df7460e 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -17,7 +17,7 @@ use common_utils::{
 };
 use error_stack::{report, IntoReport, ResultExt};
 use router_env::{instrument, tracing};
-use storage_models::payment_method;
+use storage_models::{enums as storage_enums, payment_method};
 
 #[cfg(feature = "basilisk")]
 use crate::scheduler::metrics as scheduler_metrics;
@@ -1128,6 +1128,7 @@ async fn filter_payment_methods(
                         config,
                         &connector,
                         &payment_method_object.payment_method_type,
+                        payment_attempt,
                         &mut payment_method_object.card_networks,
                         &address.and_then(|inner| inner.country),
                         payment_attempt
@@ -1162,6 +1163,7 @@ fn filter_pm_based_on_config<'a>(
     config: &'a crate::configs::settings::ConnectorFilters,
     connector: &'a str,
     payment_method_type: &'a api_enums::PaymentMethodType,
+    payment_attempt: Option<&storage::PaymentAttempt>,
     card_network: &mut Option<Vec<api_enums::CardNetwork>>,
     country: &Option<api_enums::CountryAlpha2>,
     currency: Option<api_enums::Currency>,
@@ -1172,7 +1174,14 @@ fn filter_pm_based_on_config<'a>(
         .and_then(|inner| match payment_method_type {
             api_enums::PaymentMethodType::Credit | api_enums::PaymentMethodType::Debit => {
                 card_network_filter(country, currency, card_network, inner);
-                None
+
+                payment_attempt
+                    .and_then(|inner| inner.capture_method)
+                    .and_then(|capture_method| {
+                        (capture_method == storage_enums::CaptureMethod::Manual).then(|| {
+                            filter_pm_based_on_capture_method_used(inner, payment_method_type)
+                        })
+                    })
             }
             payment_method_type => inner
                 .0
@@ -1184,6 +1193,22 @@ fn filter_pm_based_on_config<'a>(
         .unwrap_or(true)
 }
 
+///Filters the payment method list on basis of Capture methods, checks whether the connector issues Manual payments using cards or not if not it won't be visible in payment methods list
+fn filter_pm_based_on_capture_method_used(
+    payment_method_filters: &settings::PaymentMethodFilters,
+    payment_method_type: &api_enums::PaymentMethodType,
+) -> bool {
+    payment_method_filters
+        .0
+        .get(&settings::PaymentMethodFilterKey::PaymentMethodType(
+            *payment_method_type,
+        ))
+        .and_then(|v| v.not_available_flows)
+        .and_then(|v| v.capture_method)
+        .map(|v| !matches!(v, api_enums::CaptureMethod::Manual))
+        .unwrap_or(true)
+}
+
 fn card_network_filter(
     country: &Option<api_enums::CountryAlpha2>,
     currency: Option<api_enums::Currency>,
@@ -1208,7 +1233,7 @@ fn card_network_filter(
 }
 
 fn global_country_currency_filter(
-    item: &settings::CurrencyCountryFilter,
+    item: &settings::CurrencyCountryFlowFilter,
     country: &Option<api_enums::CountryAlpha2>,
     currency: Option<api_enums::Currency>,
 ) -> bool {

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

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

## Description
We are adding a filter for the payment methods list that whenever the capture method on payment_intent is set to Manual it will evaluate whether that connector issues for the manual capture of payment or not. If not it won't be visible in payments method list


### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [x] 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\
As of now even if manual capture is not present for a connector, our route was showing the option from now it won't happen and only the methods allowed for manual capture will be visible to choose from

## How did you test it?
When we will make the payment create in manual mode we  will won't get the cards available as it don't supports manual capture

<img width="1728" alt="Screenshot 2023-04-26 at 18 26 15" src="https://user-images.githubusercontent.com/61520228/234581609-917e425a-fc8a-458e-a38a-fb94cbf8ed37.png">


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