Bug: [BUG] [CARD TESTING GUARD] Card Testing Guard Config null value fix for existing profiles



### Bug Description

For existing business profiles, the value of card_testing_guard_config appears null

### Expected Behavior

For existing business profiles, the value of card_testing_guard_config should not appear null

### Actual Behavior

For existing business profiles, the value of card_testing_guard_config appears null

### Steps To Reproduce

Retrieve an existing business_profile, and card_testing_guard_config will appear null.

### Context For The Bug

_No response_

### Environment

Integ, Sandbox, Production

### 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/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 94da0f0438b..ae3706a87d5 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -635,6 +635,25 @@ pub struct CardTestingGuardConfig {
 
 common_utils::impl_to_sql_from_sql_json!(CardTestingGuardConfig);
 
+impl Default for CardTestingGuardConfig {
+    fn default() -> Self {
+        Self {
+            is_card_ip_blocking_enabled: common_utils::consts::DEFAULT_CARD_IP_BLOCKING_STATUS,
+            card_ip_blocking_threshold: common_utils::consts::DEFAULT_CARD_IP_BLOCKING_THRESHOLD,
+            is_guest_user_card_blocking_enabled:
+                common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_STATUS,
+            guest_user_card_blocking_threshold:
+                common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_THRESHOLD,
+            is_customer_id_blocking_enabled:
+                common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_STATUS,
+            customer_id_blocking_threshold:
+                common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_THRESHOLD,
+            card_testing_guard_expiry:
+                common_utils::consts::DEFAULT_CARD_TESTING_GUARD_EXPIRY_IN_SECS,
+        }
+    }
+}
+
 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression)]
 #[diesel(sql_type = diesel::sql_types::Json)]
 pub struct WebhookDetails {
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 7bf25e689ab..b889414793d 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -3703,26 +3703,10 @@ impl ProfileCreateBridge for api::ProfileCreate {
             "fs",
         )));
 
-        let card_testing_guard_config = match self.card_testing_guard_config {
-            Some(card_testing_guard_config) => Some(CardTestingGuardConfig::foreign_from(
-                card_testing_guard_config,
-            )),
-            None => Some(CardTestingGuardConfig {
-                is_card_ip_blocking_enabled: common_utils::consts::DEFAULT_CARD_IP_BLOCKING_STATUS,
-                card_ip_blocking_threshold:
-                    common_utils::consts::DEFAULT_CARD_IP_BLOCKING_THRESHOLD,
-                is_guest_user_card_blocking_enabled:
-                    common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_STATUS,
-                guest_user_card_blocking_threshold:
-                    common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_THRESHOLD,
-                is_customer_id_blocking_enabled:
-                    common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_STATUS,
-                customer_id_blocking_threshold:
-                    common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_THRESHOLD,
-                card_testing_guard_expiry:
-                    common_utils::consts::DEFAULT_CARD_TESTING_GUARD_EXPIRY_IN_SECS,
-            }),
-        };
+        let card_testing_guard_config = self
+            .card_testing_guard_config
+            .map(CardTestingGuardConfig::foreign_from)
+            .or(Some(CardTestingGuardConfig::default()));
 
         Ok(domain::Profile::from(domain::ProfileSetter {
             profile_id,
@@ -3874,26 +3858,10 @@ impl ProfileCreateBridge for api::ProfileCreate {
             "fs",
         )));
 
-        let card_testing_guard_config = match self.card_testing_guard_config {
-            Some(card_testing_guard_config) => Some(CardTestingGuardConfig::foreign_from(
-                card_testing_guard_config,
-            )),
-            None => Some(CardTestingGuardConfig {
-                is_card_ip_blocking_enabled: common_utils::consts::DEFAULT_CARD_IP_BLOCKING_STATUS,
-                card_ip_blocking_threshold:
-                    common_utils::consts::DEFAULT_CARD_IP_BLOCKING_THRESHOLD,
-                is_guest_user_card_blocking_enabled:
-                    common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_STATUS,
-                guest_user_card_blocking_threshold:
-                    common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_THRESHOLD,
-                is_customer_id_blocking_enabled:
-                    common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_STATUS,
-                customer_id_blocking_threshold:
-                    common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_THRESHOLD,
-                card_testing_guard_expiry:
-                    common_utils::consts::DEFAULT_CARD_TESTING_GUARD_EXPIRY_IN_SECS,
-            }),
-        };
+        let card_testing_guard_config = self
+            .card_testing_guard_config
+            .map(CardTestingGuardConfig::foreign_from)
+            .or(Some(CardTestingGuardConfig::default()));
 
         Ok(domain::Profile::from(domain::ProfileSetter {
             id: profile_id,
diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs
index b72b47be16d..4bd6dfbe5dc 100644
--- a/crates/router/src/types/api/admin.rs
+++ b/crates/router/src/types/api/admin.rs
@@ -16,7 +16,7 @@ pub use api_models::{
     },
 };
 use common_utils::{ext_traits::ValueExt, types::keymanager as km_types};
-use diesel_models::organization::OrganizationBridge;
+use diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
 use error_stack::ResultExt;
 use hyperswitch_domain_models::merchant_key_store::MerchantKeyStore;
 use masking::{ExposeInterface, PeekInterface, Secret};
@@ -141,6 +141,10 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
         let masked_outgoing_webhook_custom_http_headers =
             outgoing_webhook_custom_http_headers.map(MaskedHeaders::from_headers);
 
+        let card_testing_guard_config = item
+            .card_testing_guard_config
+            .or(Some(CardTestingGuardConfig::default()));
+
         Ok(Self {
             merchant_id: item.merchant_id,
             profile_id,
@@ -186,9 +190,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
             always_request_extended_authorization: item.always_request_extended_authorization,
             is_click_to_pay_enabled: item.is_click_to_pay_enabled,
             authentication_product_ids: item.authentication_product_ids,
-            card_testing_guard_config: item
-                .card_testing_guard_config
-                .map(ForeignInto::foreign_into),
+            card_testing_guard_config: card_testing_guard_config.map(ForeignInto::foreign_into),
             is_clear_pan_retries_enabled: item.is_clear_pan_retries_enabled,
             force_3ds_challenge: item.force_3ds_challenge,
             is_debit_routing_enabled: Some(item.is_debit_routing_enabled),
@@ -224,6 +226,10 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
         let masked_outgoing_webhook_custom_http_headers =
             outgoing_webhook_custom_http_headers.map(MaskedHeaders::from_headers);
 
+        let card_testing_guard_config = item
+            .card_testing_guard_config
+            .or(Some(CardTestingGuardConfig::default()));
+
         Ok(Self {
             merchant_id: item.merchant_id,
             id,
@@ -264,9 +270,7 @@ impl ForeignTryFrom<domain::Profile> for ProfileResponse {
             is_network_tokenization_enabled: item.is_network_tokenization_enabled,
             is_click_to_pay_enabled: item.is_click_to_pay_enabled,
             authentication_product_ids: item.authentication_product_ids,
-            card_testing_guard_config: item
-                .card_testing_guard_config
-                .map(ForeignInto::foreign_into),
+            card_testing_guard_config: card_testing_guard_config.map(ForeignInto::foreign_into),
             is_clear_pan_retries_enabled: item.is_clear_pan_retries_enabled,
             is_debit_routing_enabled: Some(item.is_debit_routing_enabled),
             merchant_business_country: item.merchant_business_country,
@@ -335,25 +339,10 @@ pub async fn create_profile_from_merchant_account(
         "fs",
     )));
 
-    let card_testing_guard_config = match request.card_testing_guard_config {
-        Some(card_testing_guard_config) => Some(CardTestingGuardConfig::foreign_from(
-            card_testing_guard_config,
-        )),
-        None => Some(CardTestingGuardConfig {
-            is_card_ip_blocking_enabled: common_utils::consts::DEFAULT_CARD_IP_BLOCKING_STATUS,
-            card_ip_blocking_threshold: common_utils::consts::DEFAULT_CARD_IP_BLOCKING_THRESHOLD,
-            is_guest_user_card_blocking_enabled:
-                common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_STATUS,
-            guest_user_card_blocking_threshold:
-                common_utils::consts::DEFAULT_GUEST_USER_CARD_BLOCKING_THRESHOLD,
-            is_customer_id_blocking_enabled:
-                common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_STATUS,
-            customer_id_blocking_threshold:
-                common_utils::consts::DEFAULT_CUSTOMER_ID_BLOCKING_THRESHOLD,
-            card_testing_guard_expiry:
-                common_utils::consts::DEFAULT_CARD_TESTING_GUARD_EXPIRY_IN_SECS,
-        }),
-    };
+    let card_testing_guard_config = request
+        .card_testing_guard_config
+        .map(CardTestingGuardConfig::foreign_from)
+        .or(Some(CardTestingGuardConfig::default()));
 
     Ok(domain::Profile::from(domain::ProfileSetter {
         profile_id,

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

In our current implementation of `Card Testing Guard`, the `card_testing_guard_config` can be `NULL`
for existing profiles. That has been fixed in this PR to return the default values for `card_testing_guard_config` in case the underlying data is `NULL`

### 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).
-->

Issue Link: https://github.com/juspay/hyperswitch/issues/7598


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

**Postman Tests**

**Business Profile Retrieve**

-Request

```
curl --location 'http://localhost:8080/account/postman_merchant_GHAction_28c1525e-4f97-4f53-82a2-7ea63214a26a/business_profile/pro_N8dPPL3N4soUk236Rbq2' \
--header 'api-key: test_admin'
```

-Response

```
{
    "merchant_id": "postman_merchant_GHAction_28c1525e-4f97-4f53-82a2-7ea63214a26a",
    "profile_id": "pro_N8dPPL3N4soUk236Rbq2",
    "profile_name": "US_default",
    "return_url": "https://duck.com/success",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "M59W9wzwjThfjmSUuTqagO3k9SaN74rA8BFa4NMGBTRCgzwl7Y9gBNgAAKl0FqHe",
    "redirect_to_merchant_with_http_post": false,
    "webhook_details": {
        "webhook_version": "1.0.1",
        "webhook_username": "ekart_retail",
        "webhook_password": "password_ekart@123",
        "webhook_url": null,
        "payment_created_enabled": true,
        "payment_succeeded_enabled": true,
        "payment_failed_enabled": true
    },
    "metadata": null,
    "routing_algorithm": null,
    "intent_fulfillment_time": 900,
    "frm_routing_algorithm": null,
    "payout_routing_algorithm": null,
    "applepay_verified_domains": null,
    "session_expiry": 900,
    "payment_link_config": null,
    "authentication_connector_details": null,
    "use_billing_as_payment_method_billing": true,
    "extended_card_info_config": null,
    "collect_shipping_details_from_wallet_connector": false,
    "collect_billing_details_from_wallet_connector": false,
    "always_collect_shipping_details_from_wallet_connector": false,
    "always_collect_billing_details_from_wallet_connector": false,
    "is_connector_agnostic_mit_enabled": false,
    "payout_link_config": null,
    "outgoing_webhook_custom_http_headers": null,
    "tax_connector_id": null,
    "is_tax_connector_enabled": false,
    "is_network_tokenization_enabled": false,
    "is_auto_retries_enabled": false,
    "max_auto_retries_enabled": null,
    "always_request_extended_authorization": null,
    "is_click_to_pay_enabled": false,
    "authentication_product_ids": null,
    "card_testing_guard_config": {
        "card_ip_blocking_status": "disabled",
        "card_ip_blocking_threshold": 3,
        "guest_user_card_blocking_status": "disabled",
        "guest_user_card_blocking_threshold": 10,
        "customer_id_blocking_status": "disabled",
        "customer_id_blocking_threshold": 5,
        "card_testing_guard_expiry": 3600
    },
    "is_clear_pan_retries_enabled": false,
    "force_3ds_challenge": false
}
```

**Cypress Tests**

![image](https://github.com/user-attachments/assets/dc1560af-790c-4baf-8f57-1286c37a3431)


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