Bug: [BUG] remove redundant DB calls when FRM feature is not enabled



### Bug Description

FRM is a payment feature which is integrated in HyperSwitch behind `frm` feature flag. There are some DB queries (which are generally not behind a feature flag) which are being executed even when `frm` feature is disabled.

### Expected Behavior

Underlying DB queries should be executed only when the feature which requires it is enabled. In this case, FRM DB queries should be executed only when `frm` is enabled

### Actual Behavior

FRM DB queries are being executed regardless of `frm` feature flag

### Steps To Reproduce

---

### Context For The Bug

_No response_

### Environment

Are you using hyperswitch hosted version? Yes/No
If yes, please provide the value of the `x-request-id` response header to help us debug your issue.

If not (or if building/running locally), please provide the following details:
1. Operating System or Linux distribution:
2. Rust version (output of `rustc --version`): ``
3. App version (output of `cargo r --features vergen -- --version`): ``


### 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/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index 38cf72a3e2f..9c5b632eff0 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -136,13 +136,17 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCaptureRequest>
         payment_intent.shipping_address_id = shipping_address.clone().map(|i| i.address_id);
         payment_intent.billing_address_id = billing_address.clone().map(|i| i.address_id);
 
-        let frm_response = db
-        .find_fraud_check_by_payment_id(payment_intent.payment_id.clone(), merchant_account.get_id().clone())
-        .await
-        .change_context(errors::ApiErrorResponse::PaymentNotFound)
-        .attach_printable_lazy(|| {
-            format!("Error while retrieving frm_response, merchant_id: {}, payment_id: {attempt_id}", merchant_account.get_id().get_string_repr())
-        });
+        let frm_response = if cfg!(feature = "frm") {
+            db.find_fraud_check_by_payment_id(payment_intent.payment_id.clone(), merchant_account.get_id().clone())
+                .await
+                .change_context(errors::ApiErrorResponse::PaymentNotFound)
+                .attach_printable_lazy(|| {
+                    format!("Error while retrieving frm_response, merchant_id: {}, payment_id: {attempt_id}", merchant_account.get_id().get_string_repr())
+                })
+                .ok()
+        } else {
+            None
+        };
 
         let payment_data = PaymentData {
             flow: PhantomData,
@@ -180,7 +184,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCaptureRequest>
             multiple_capture_data: None,
             redirect_response: None,
             surcharge_details: None,
-            frm_message: frm_response.ok(),
+            frm_message: frm_response,
             payment_link_data: None,
             incremental_authorization_details: None,
             authorizations: vec![],
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index 570337a5555..3d67dadd34d 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -117,13 +117,17 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, PaymentsCancelRequest> for P
         let currency = payment_attempt.currency.get_required_value("currency")?;
         let amount = payment_attempt.get_total_amount().into();
 
-        let frm_response = db
-        .find_fraud_check_by_payment_id(payment_intent.payment_id.clone(), merchant_account.get_id().clone())
-        .await
-        .change_context(errors::ApiErrorResponse::PaymentNotFound)
-        .attach_printable_lazy(|| {
-            format!("Error while retrieving frm_response, merchant_id: {:?}, payment_id: {attempt_id}", merchant_account.get_id())
-        });
+        let frm_response = if cfg!(feature = "frm") {
+            db.find_fraud_check_by_payment_id(payment_intent.payment_id.clone(), merchant_account.get_id().clone())
+                .await
+                .change_context(errors::ApiErrorResponse::PaymentNotFound)
+                .attach_printable_lazy(|| {
+                    format!("Error while retrieving frm_response, merchant_id: {:?}, payment_id: {attempt_id}", merchant_account.get_id())
+                })
+                .ok()
+        } else {
+            None
+        };
 
         let profile_id = payment_intent
             .profile_id
@@ -176,7 +180,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, PaymentsCancelRequest> for P
             multiple_capture_data: None,
             redirect_response: None,
             surcharge_details: None,
-            frm_message: frm_response.ok(),
+            frm_message: frm_response,
             payment_link_data: None,
             incremental_authorization_details: None,
             authorizations: vec![],
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index d7ca01e6661..0508d0549e8 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -348,13 +348,17 @@ async fn get_tracker_for_sync<
             format!("Error while retrieving dispute list for, merchant_id: {:?}, payment_id: {payment_id:?}", merchant_account.get_id())
         })?;
 
-    let frm_response = db
-        .find_fraud_check_by_payment_id(payment_id.to_owned(), merchant_account.get_id().clone())
-        .await
-        .change_context(errors::ApiErrorResponse::PaymentNotFound)
-        .attach_printable_lazy(|| {
-            format!("Error while retrieving frm_response, merchant_id: {:?}, payment_id: {payment_id:?}", merchant_account.get_id())
-        });
+    let frm_response = if cfg!(feature = "frm") {
+        db.find_fraud_check_by_payment_id(payment_id.to_owned(), merchant_account.get_id().clone())
+            .await
+            .change_context(errors::ApiErrorResponse::PaymentNotFound)
+            .attach_printable_lazy(|| {
+                format!("Error while retrieving frm_response, merchant_id: {:?}, payment_id: {payment_id:?}", merchant_account.get_id())
+            })
+            .ok()
+    } else {
+        None
+    };
 
     let contains_encoded_data = payment_attempt.encoded_data.is_some();
 
@@ -472,7 +476,7 @@ async fn get_tracker_for_sync<
         redirect_response: None,
         payment_link_data: None,
         surcharge_details: None,
-        frm_message: frm_response.ok(),
+        frm_message: frm_response,
         incremental_authorization_details: None,
         authorizations,
         authentication,

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

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

## Description
Described in #5888 

### 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
Ensures FRM DB queries are not executed if `frm` feature flag is not enabled. There are a couple of features disabled in HS production, and the DB migrations for such features have not been executed. This leads to unnecessary missing column logs in production - `ERROR: column fraud_check.last_step does not exist at character 443`

Moving such DB queries behind the feature flag ensures they are not executed in the flow.

## How did you test it?
<details>
    <summary>1. Create a txn</summary>

cURL

    curl --location 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_4cUeectovRvg0seB0AhDXZ04342m045JeKncgz5XfwkkhJujY4gy7TzfTS9uvdiP' \
    --data-raw '{
        "amount": 10000,
        "currency": "USD",
        "confirm": false,
        "capture_method": "automatic",
        "capture_on": "2022-09-10T10:11:12Z",
        "customer_id": "StripeCustomer",
        "email": "abcdef123@gmail.com",
        "name": "John Doe",
        "phone": "999999999",
        "phone_country_code": "+65",
        "description": "Its my first payment request",
        "authentication_type": "three_ds",
        "return_url": "https://duck.com",
        "setup_future_usage": "on_session",
        "customer_acceptance": {
            "acceptance_type": "offline",
            "accepted_at": "1963-05-03T04:07:52.723Z",
            "online": {
                "ip_address": "127.0.0.1",
                "user_agent": "amet irure esse"
            }
        },
        "billing": {
            "address": {
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "US"
            }
        },
        "browser_info": {
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
            "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "language": "nl-NL",
            "color_depth": 24,
            "screen_height": 723,
            "screen_width": 1536,
            "time_zone": 0,
            "java_enabled": true,
            "java_script_enabled": true,
            "ip_address": "127.0.0.1"
        },
        "shipping": {
            "address": {
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "US",
                "first_name": "John",
                "last_name": "Doe"
            }
        },
        "statement_descriptor_name": "joseph",
        "statement_descriptor_suffix": "JS",
        "metadata": {
            "udf1": "value1",
            "new_customer": "true",
            "login_date": "2019-09-10T10:11:12Z"
        }
    }'

Response

    {
        "payment_id": "pay_vOR4HKlsgkvHTnZf4PjC",
        "merchant_id": "postman_merchant_GHAction_9205c2f8-ea92-4ceb-8d6e-182cf16425be",
        "status": "requires_payment_method",
        "amount": 10000,
        "net_amount": 10000,
        "amount_capturable": 0,
        "amount_received": null,
        "connector": null,
        "client_secret": "pay_vOR4HKlsgkvHTnZf4PjC_secret_pIfEyYXxJwmoBKAZnPcD",
        "created": "2024-09-16T04:20:41.261Z",
        "currency": "USD",
        "customer_id": "StripeCustomer",
        "customer": {
            "id": "StripeCustomer",
            "name": "John Doe",
            "email": "abcdef123@gmail.com",
            "phone": "999999999",
            "phone_country_code": "+65"
        },
        "description": "Its my first payment request",
        "refunds": null,
        "disputes": null,
        "mandate_id": null,
        "mandate_data": null,
        "setup_future_usage": "on_session",
        "off_session": null,
        "capture_on": null,
        "capture_method": "automatic",
        "payment_method": null,
        "payment_method_data": 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": null,
            "email": null
        },
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "US",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": null,
                "last_name": null
            },
            "phone": null,
            "email": null
        },
        "order_details": null,
        "email": "abcdef123@gmail.com",
        "name": "John Doe",
        "phone": "999999999",
        "return_url": "https://duck.com/",
        "authentication_type": "three_ds",
        "statement_descriptor_name": "joseph",
        "statement_descriptor_suffix": "JS",
        "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": {
            "customer_id": "StripeCustomer",
            "created_at": 1726460441,
            "expires": 1726464041,
            "secret": "epk_51ac152969e5409fa03e13c462de5474"
        },
        "manual_retry_allowed": null,
        "connector_transaction_id": null,
        "frm_message": null,
        "metadata": {
            "udf1": "value1",
            "login_date": "2019-09-10T10:11:12Z",
            "new_customer": "true"
        },
        "connector_metadata": null,
        "feature_metadata": null,
        "reference_id": null,
        "payment_link": null,
        "profile_id": "pro_RSxpgp1DT0ak3TCybfa5",
        "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": false,
        "expires_on": "2024-09-16T04:35:41.261Z",
        "fingerprint": null,
        "browser_info": {
            "language": "nl-NL",
            "time_zone": 0,
            "ip_address": "127.0.0.1",
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
            "color_depth": 24,
            "java_enabled": true,
            "screen_width": 1536,
            "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "screen_height": 723,
            "java_script_enabled": true
        },
        "payment_method_id": null,
        "payment_method_status": null,
        "updated": "2024-09-16T04:20:41.283Z",
        "charges": null,
        "frm_metadata": null,
        "merchant_order_reference_id": null,
        "order_tax_amount": null
    }

</details>

<details>
    <summary>2. Confirm the txn</summary>

cURL

    curl --location 'http://localhost:8080/payments/pay_vOR4HKlsgkvHTnZf4PjC/confirm' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: pk_dev_8e7e083168464148bdc4aa4e18eb12ac' \
    --data-raw '{
        "client_secret": "pay_vOR4HKlsgkvHTnZf4PjC_secret_pIfEyYXxJwmoBKAZnPcD",
        "payment_method": "bank_debit",
        "payment_method_type": "ach",
        "payment_method_data": {
            "bank_debit": {
                "ach_bank_debit": {
                    "account_number": "40308669",
                    "routing_number": "121000358",
                    "sort_code": "560036",
                    "shopper_email": "example@gmail.com",
                    "card_holder_name": "joseph Doe",
                    "bank_name": "wells_fargo",
                    "bank_account_holder_name": "David Archer",
                    "billing_details": {
                        "houseNumberOrName": "50",
                        "street": "Test Street",
                        "city": "Amsterdam",
                        "stateOrProvince": "NY",
                        "postalCode": "12010",
                        "country": "US",
                        "name": "A. Klaassen",
                        "email": "example@gmail.com"
                    },
                    "reference": "daslvcgbaieh"
                }
            }
        },
        "browser_info": {
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
            "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "language": "nl-NL",
            "color_depth": 24,
            "screen_height": 723,
            "screen_width": 1536,
            "time_zone": 0,
            "java_enabled": true,
            "java_script_enabled": true,
            "ip_address": "127.0.0.1"
        }
    }'

Response

    {
        "payment_id": "pay_vOR4HKlsgkvHTnZf4PjC",
        "merchant_id": "postman_merchant_GHAction_9205c2f8-ea92-4ceb-8d6e-182cf16425be",
        "status": "succeeded",
        "amount": 10000,
        "net_amount": 10000,
        "amount_capturable": 0,
        "amount_received": 10000,
        "connector": "adyen",
        "client_secret": "pay_vOR4HKlsgkvHTnZf4PjC_secret_pIfEyYXxJwmoBKAZnPcD",
        "created": "2024-09-16T04:20:41.261Z",
        "currency": "USD",
        "customer_id": "StripeCustomer",
        "customer": {
            "id": "StripeCustomer",
            "name": "John Doe",
            "email": "abcdef123@gmail.com",
            "phone": "999999999",
            "phone_country_code": "+65"
        },
        "description": "Its my first payment request",
        "refunds": null,
        "disputes": null,
        "mandate_id": null,
        "mandate_data": null,
        "setup_future_usage": "on_session",
        "off_session": null,
        "capture_on": null,
        "capture_method": "automatic",
        "payment_method": "bank_debit",
        "payment_method_data": {
            "bank_debit": {
                "ach": {
                    "account_number": "****8669",
                    "routing_number": "121***358",
                    "card_holder_name": "joseph Doe",
                    "bank_account_holder_name": "David Archer",
                    "bank_name": "wells_fargo",
                    "bank_type": null,
                    "bank_holder_type": 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": null,
            "email": null
        },
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "US",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": null,
                "last_name": null
            },
            "phone": null,
            "email": null
        },
        "order_details": null,
        "email": "abcdef123@gmail.com",
        "name": "John Doe",
        "phone": "999999999",
        "return_url": "https://duck.com/",
        "authentication_type": "three_ds",
        "statement_descriptor_name": "joseph",
        "statement_descriptor_suffix": "JS",
        "next_action": null,
        "cancellation_reason": null,
        "error_code": null,
        "error_message": null,
        "unified_code": null,
        "unified_message": null,
        "payment_experience": null,
        "payment_method_type": "ach",
        "connector_label": null,
        "business_country": null,
        "business_label": "default",
        "business_sub_label": null,
        "allowed_payment_method_types": null,
        "ephemeral_key": null,
        "manual_retry_allowed": false,
        "connector_transaction_id": "WMVPLJG2ZG47JFV5",
        "frm_message": null,
        "metadata": {
            "udf1": "value1",
            "login_date": "2019-09-10T10:11:12Z",
            "new_customer": "true"
        },
        "connector_metadata": null,
        "feature_metadata": null,
        "reference_id": "pay_vOR4HKlsgkvHTnZf4PjC_1",
        "payment_link": null,
        "profile_id": "pro_RSxpgp1DT0ak3TCybfa5",
        "surcharge_details": null,
        "attempt_count": 1,
        "merchant_decision": null,
        "merchant_connector_id": "mca_dQv2PlaakvcRdJ4XR04T",
        "incremental_authorization_allowed": null,
        "authorization_count": null,
        "incremental_authorizations": null,
        "external_authentication_details": null,
        "external_3ds_authentication_attempted": false,
        "expires_on": "2024-09-16T04:35:41.261Z",
        "fingerprint": null,
        "browser_info": {
            "language": "nl-NL",
            "time_zone": 0,
            "ip_address": "127.0.0.1",
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
            "color_depth": 24,
            "java_enabled": true,
            "screen_width": 1536,
            "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "screen_height": 723,
            "java_script_enabled": true
        },
        "payment_method_id": null,
        "payment_method_status": null,
        "updated": "2024-09-16T04:20:44.432Z",
        "charges": null,
        "frm_metadata": null,
        "merchant_order_reference_id": null,
        "order_tax_amount": null
    }

</details>

<details>
    <summary>3. Look at the logs to see if fraud_check queries are present (should be present when `frm` is enabled and absent when `frm` feature is disabled. </summary>
    
![image](https://github.com/user-attachments/assets/39849bd2-9f02-41a3-91b0-21d47c964965)

</details>



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