Bug: feat(payments): support for card_network filter in payments list



- Support for card_network as filters in payments list
- Card network values in payments filter values
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 584f81992bd..4034b8cd58e 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -4361,6 +4361,8 @@ pub struct PaymentListFilterConstraints {
     /// The order in which payments list should be sorted
     #[serde(default)]
     pub order: Order,
+    /// The List of all the card networks to filter payments list
+    pub card_network: Option<Vec<enums::CardNetwork>>,
 }
 #[derive(Clone, Debug, serde::Serialize)]
 pub struct PaymentListFilters {
@@ -4390,6 +4392,8 @@ pub struct PaymentListFiltersV2 {
     pub payment_method: HashMap<enums::PaymentMethod, HashSet<enums::PaymentMethodType>>,
     /// The list of available authentication types
     pub authentication_type: Vec<enums::AuthenticationType>,
+    /// The list of available card networks
+    pub card_network: Vec<enums::CardNetwork>,
 }
 
 #[derive(Clone, Debug, serde::Serialize)]
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
index 562e5d205c0..be2b3547110 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
@@ -1294,6 +1294,7 @@ pub struct PaymentIntentListParams {
     pub ending_before_id: Option<id_type::PaymentId>,
     pub limit: Option<u32>,
     pub order: api_models::payments::Order,
+    pub card_network: Option<Vec<storage_enums::CardNetwork>>,
 }
 
 impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchConstraints {
@@ -1327,6 +1328,7 @@ impl From<api_models::payments::PaymentListConstraints> for PaymentIntentFetchCo
             ending_before_id: ending_before,
             limit: Some(std::cmp::min(limit, PAYMENTS_LIST_MAX_LIMIT_V1)),
             order: Default::default(),
+            card_network: None,
         }))
     }
 }
@@ -1351,6 +1353,7 @@ impl From<common_utils::types::TimeRange> for PaymentIntentFetchConstraints {
             ending_before_id: None,
             limit: None,
             order: Default::default(),
+            card_network: None,
         }))
     }
 }
@@ -1373,6 +1376,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentF
             authentication_type,
             merchant_connector_id,
             order,
+            card_network,
         } = value;
         if let Some(payment_intent_id) = payment_id {
             Self::Single { payment_intent_id }
@@ -1395,6 +1399,7 @@ impl From<api_models::payments::PaymentListFilterConstraints> for PaymentIntentF
                 ending_before_id: None,
                 limit: Some(std::cmp::min(limit, PAYMENTS_LIST_MAX_LIMIT_V2)),
                 order,
+                card_network,
             }))
         }
     }
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index d7899e8b9a9..859796310f0 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -3380,6 +3380,7 @@ pub async fn get_payment_filters(
             status: enums::IntentStatus::iter().collect(),
             payment_method: payment_method_types_map,
             authentication_type: enums::AuthenticationType::iter().collect(),
+            card_network: enums::CardNetwork::iter().collect(),
         },
     ))
 }
diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs
index 4c7232f6f3f..f5c3deeb18c 100644
--- a/crates/storage_impl/src/payments/payment_intent.rs
+++ b/crates/storage_impl/src/payments/payment_intent.rs
@@ -939,6 +939,9 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
                     None => query,
                 };
 
+                if let Some(card_network) = &params.card_network {
+                    query = query.filter(pa_dsl::card_network.eq_any(card_network.clone()));
+                }
                 query
             }
         };

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

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

## Description
<!-- Describe your changes in detail -->
- Support for card_network as filters in payments list 
- Card network values in payments filter values 


### Additional Changes

- [X] 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).
-->
Closes #5995 

## 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)?
-->
1. Payments filter list 
Request 
```
curl --location 'http://localhost:8080/payments/v2/filter' \
--header 'Authorization: Bearer JWT' \
--data ''
```

Response
```
{
    "connector": {
        "connector_name": [
            {
                "connector_label": "connector_label",
                "merchant_connector_id": "connector_id"
            }
        ]
    },
    "currency": [Array of currency values],
    "status": [Array of status],
    "payment_method": { [Array of payment methods]},
    "authentication_type": [Array of authentication types],
    "card_network": [
        "Visa",
        "Mastercard",
        "AmericanExpress",
        "JCB",
        "DinersClub",
        "Discover",
        "CartesBancaires",
        "UnionPay",
        "Interac",
        "RuPay",
        "Maestro"
    ]
}
```

2. Payments list with filter 
Request 
```
curl --location 'http://localhost:8080/payments/list' \
--header 'authorization: Bearer JWT "
--data '{"offset":0,"limit":50,"start_time":"2024-08-23T18:30:00Z","card_network":["Visa"]}'
```
Response 
```
{
    "count": 2,
    "total_count": 2,
    "data": [
        {
            "payment_id": "pay_TTYRZZpn4GZgyZkvfpLz",
            "merchant_id": "merchant_1726749985",
            "status": "succeeded",
            "amount": 10000,
            "net_amount": 10000,
            "amount_capturable": 0,
            "amount_received": null,
            "connector": "stripe_test",
            "client_secret": "pay_TTYRZZpn4GZgyZkvfpLz_secret_BNl87WI1lhH3h92QwwRi",
            "created": "2024-09-23T06:52:14.730Z",
            "currency": "USD",
            "customer_id": "hyperswitch_sdk_demo_id",
            "customer": {
                "id": "hyperswitch_sdk_demo_id",
                "name": "John Doe",
                "email": "guest@example.com",
                "phone": "999999999",
                "phone_country_code": "+65"
            },
            "description": "Default value",
            "refunds": null,
            "disputes": null,
            "mandate_id": null,
            "mandate_data": null,
            "setup_future_usage": null,
            "off_session": null,
            "capture_on": null,
            "capture_method": "automatic",
            "payment_method": "card",
            "payment_method_data": {
                "card": {
                    "last4": null,
                    "card_type": null,
                    "card_network": "Visa",
                    "card_issuer": "",
                    "card_issuing_country": null,
                    "card_isin": null,
                    "card_extended_bin": null,
                    "card_exp_month": null,
                    "card_exp_year": null,
                    "card_holder_name": null,
                    "payment_checks": null,
                    "authentication_data": null
                },
                "billing": null
            },
            "payment_token": null,
            "shipping": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "John",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "1234567890",
                    "country_code": "+1"
                },
                "email": null
            },
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "John",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "1234567890",
                    "country_code": "+1"
                },
                "email": "billing_email@gmail.com"
            },
            "order_details": null,
            "email": null,
            "name": null,
            "phone": null,
            "return_url": null,
            "authentication_type": "no_three_ds",
            "statement_descriptor_name": null,
            "statement_descriptor_suffix": null,
            "next_action": null,
            "cancellation_reason": null,
            "error_code": null,
            "error_message": null,
            "unified_code": null,
            "unified_message": null,
            "payment_experience": null,
            "payment_method_type": null,
            "connector_label": null,
            "business_country": null,
            "business_label": "default",
            "business_sub_label": null,
            "allowed_payment_method_types": null,
            "ephemeral_key": null,
            "manual_retry_allowed": null,
            "connector_transaction_id": "pay_2dJSM6oUYFoKtxtD45jm",
            "frm_message": null,
            "metadata": {
                "order_details": {
                    "amount": 10000,
                    "quantity": 1,
                    "product_name": "Apple iphone 15"
                }
            },
            "connector_metadata": null,
            "feature_metadata": null,
            "reference_id": null,
            "payment_link": null,
            "profile_id": "pro_ClRdOxbia1VPXGEvFHe3",
            "surcharge_details": null,
            "attempt_count": 1,
            "merchant_decision": null,
            "merchant_connector_id": "mca_fBms1u3jKBroyqKUax5S",
            "incremental_authorization_allowed": null,
            "authorization_count": null,
            "incremental_authorizations": null,
            "external_authentication_details": null,
            "external_3ds_authentication_attempted": null,
            "expires_on": null,
            "fingerprint": null,
            "browser_info": null,
            "payment_method_id": null,
            "payment_method_status": null,
            "updated": null,
            "charges": null,
            "frm_metadata": null,
            "merchant_order_reference_id": null,
            "order_tax_amount": null
        },
        {
            "payment_id": "pay_8rF6jCw4J0W4e2eV7WqC",
            "merchant_id": "merchant_1726749985",
            "status": "requires_payment_method",
            "amount": 10000,
            "net_amount": 10000,
            "amount_capturable": 10000,
            "amount_received": null,
            "connector": null,
            "client_secret": "pay_8rF6jCw4J0W4e2eV7WqC_secret_LuwsymB20YhQ1MaujKgK",
            "created": "2024-09-23T06:50:09.337Z",
            "currency": "USD",
            "customer_id": "hyperswitch_sdk_demo_id",
            "customer": {
                "id": "hyperswitch_sdk_demo_id",
                "name": "John Doe",
                "email": "guest@example.com",
                "phone": "999999999",
                "phone_country_code": "+65"
            },
            "description": "Default value",
            "refunds": null,
            "disputes": null,
            "mandate_id": null,
            "mandate_data": null,
            "setup_future_usage": null,
            "off_session": null,
            "capture_on": null,
            "capture_method": "automatic",
            "payment_method": null,
            "payment_method_data": {
                "card": {
                    "last4": null,
                    "card_type": null,
                    "card_network": "Visa",
                    "card_issuer": "",
                    "card_issuing_country": null,
                    "card_isin": null,
                    "card_extended_bin": null,
                    "card_exp_month": null,
                    "card_exp_year": null,
                    "card_holder_name": null,
                    "payment_checks": null,
                    "authentication_data": null
                },
                "billing": null
            },
            "payment_token": null,
            "shipping": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "John",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "1234567890",
                    "country_code": "+1"
                },
                "email": null
            },
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "John",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "1234567890",
                    "country_code": "+1"
                },
                "email": "billing_email@gmail.com"
            },
            "order_details": null,
            "email": null,
            "name": null,
            "phone": null,
            "return_url": null,
            "authentication_type": "no_three_ds",
            "statement_descriptor_name": null,
            "statement_descriptor_suffix": null,
            "next_action": null,
            "cancellation_reason": null,
            "error_code": null,
            "error_message": null,
            "unified_code": null,
            "unified_message": null,
            "payment_experience": null,
            "payment_method_type": null,
            "connector_label": null,
            "business_country": null,
            "business_label": "default",
            "business_sub_label": null,
            "allowed_payment_method_types": null,
            "ephemeral_key": null,
            "manual_retry_allowed": null,
            "connector_transaction_id": null,
            "frm_message": null,
            "metadata": {
                "order_details": {
                    "amount": 10000,
                    "quantity": 1,
                    "product_name": "Apple iphone 15"
                }
            },
            "connector_metadata": null,
            "feature_metadata": null,
            "reference_id": null,
            "payment_link": null,
            "profile_id": "pro_ClRdOxbia1VPXGEvFHe3",
            "surcharge_details": null,
            "attempt_count": 1,
            "merchant_decision": null,
            "merchant_connector_id": null,
            "incremental_authorization_allowed": null,
            "authorization_count": null,
            "incremental_authorizations": null,
            "external_authentication_details": null,
            "external_3ds_authentication_attempted": null,
            "expires_on": null,
            "fingerprint": null,
            "browser_info": null,
            "payment_method_id": null,
            "payment_method_status": null,
            "updated": null,
            "charges": null,
            "frm_metadata": null,
            "merchant_order_reference_id": null,
            "order_tax_amount": null
        }
    ]
}

```
## 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`
- [ ] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
