Bug: [REFACTOR] raw_connector_response as secret



refactor raw_connector_response as secret
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 13cd8fa472f..f3d7d9b675c 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -5186,7 +5186,8 @@ pub struct PaymentsResponse {
     pub is_iframe_redirection_enabled: Option<bool>,
 
     /// Contains whole connector response
-    pub whole_connector_response: Option<String>,
+    #[schema(value_type = Option<String>)]
+    pub whole_connector_response: Option<Secret<String>>,
 }
 
 #[cfg(feature = "v2")]
@@ -5805,7 +5806,8 @@ pub struct PaymentsResponse {
     pub merchant_reference_id: Option<id_type::PaymentReferenceId>,
 
     /// Stringified connector raw response body. Only returned if `return_raw_connector_response` is true
-    pub raw_connector_response: Option<String>,
+    #[schema(value_type = Option<String>)]
+    pub raw_connector_response: Option<Secret<String>>,
 }
 
 #[cfg(feature = "v2")]
diff --git a/crates/common_types/src/domain.rs b/crates/common_types/src/domain.rs
index 6b5d1cf835d..e800cb9cb61 100644
--- a/crates/common_types/src/domain.rs
+++ b/crates/common_types/src/domain.rs
@@ -5,6 +5,8 @@ use std::collections::HashMap;
 use common_enums::enums;
 use common_utils::{impl_to_sql_from_sql_json, types::MinorUnit};
 use diesel::{sql_types::Jsonb, AsExpression, FromSqlRow};
+#[cfg(feature = "v2")]
+use masking::Secret;
 use serde::{Deserialize, Serialize};
 use utoipa::ToSchema;
 
@@ -104,10 +106,10 @@ pub struct MerchantConnectorAuthDetails {
     pub merchant_connector_creds: common_utils::pii::SecretSerdeValue,
 }
 
-/// Connector Response Data that are required to be populated in response
+/// Connector Response Data that are required to be populated in response, but not persisted in DB.
 #[cfg(feature = "v2")]
 #[derive(Clone, Debug)]
 pub struct ConnectorResponseData {
     /// Stringified connector raw response body
-    pub raw_connector_response: Option<String>,
+    pub raw_connector_response: Option<Secret<String>>,
 }
diff --git a/crates/hyperswitch_connectors/src/connectors/razorpay.rs b/crates/hyperswitch_connectors/src/connectors/razorpay.rs
index 33cdc326987..cdb636aab58 100644
--- a/crates/hyperswitch_connectors/src/connectors/razorpay.rs
+++ b/crates/hyperswitch_connectors/src/connectors/razorpay.rs
@@ -10,6 +10,7 @@ use common_utils::{
 };
 use error_stack::{report, Report, ResultExt};
 use hyperswitch_domain_models::{
+    payment_method_data::PaymentMethodData,
     router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
     router_flow_types::{
         access_token_auth::AccessTokenAuth,
@@ -315,10 +316,16 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
         _req: &PaymentsAuthorizeRouterData,
         connectors: &Connectors,
     ) -> CustomResult<String, errors::ConnectorError> {
-        Ok(format!(
-            "{}v1/payments/create/upi",
-            self.base_url(connectors)
-        ))
+        match _req.request.payment_method_data {
+            PaymentMethodData::Upi(_) => Ok(format!(
+                "{}v1/payments/create/upi",
+                self.base_url(connectors)
+            )),
+            _ => Err(errors::ConnectorError::NotImplemented(
+                "Payment method not implemented for Razorpay".to_string(),
+            )
+            .into()),
+        }
     }
 
     fn get_request_body(
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index a18f9e5dc6e..259f280d49b 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -104,7 +104,7 @@ pub struct RouterData<Flow, Request, Response> {
     pub psd2_sca_exemption_type: Option<common_enums::ScaExemptionType>,
 
     /// Contains stringified connector raw response body
-    pub raw_connector_response: Option<String>,
+    pub raw_connector_response: Option<Secret<String>>,
 
     /// Indicates whether the payment ID was provided by the merchant (true),
     /// or generated internally by Hyperswitch (false)
@@ -1260,7 +1260,6 @@ impl
                     resource_id,
                     redirection_data,
                     connector_metadata,
-                    connector_response_reference_id,
                     ..
                 } => {
                     let attempt_status = self.get_attempt_status_for_db_update(payment_data);
@@ -1289,9 +1288,7 @@ impl
                                             token_details.get_connector_token_request_reference_id()
                                         }),
                                 ),
-
-                            connector_response_reference_id: connector_response_reference_id
-                                .clone(),
+                            connector_response_reference_id: None,
                         },
                     ))
                 }
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 5319e823614..cf45d15a5a1 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -6549,7 +6549,7 @@ where
         Option<hyperswitch_domain_models::card_testing_guard_data::CardTestingGuardData>,
     pub vault_operation: Option<domain_payments::VaultOperation>,
     pub threeds_method_comp_ind: Option<api_models::payments::ThreeDsCompletionIndicator>,
-    pub whole_connector_response: Option<String>,
+    pub whole_connector_response: Option<Secret<String>>,
 }
 
 #[derive(Clone, serde::Serialize, Debug)]
@@ -9446,7 +9446,7 @@ pub trait OperationSessionGetters<F> {
     fn get_connector_customer_id(&self) -> Option<String>;
 
     #[cfg(feature = "v1")]
-    fn get_whole_connector_response(&self) -> Option<String>;
+    fn get_whole_connector_response(&self) -> Option<Secret<String>>;
 
     #[cfg(feature = "v1")]
     fn get_vault_operation(&self) -> Option<&domain_payments::VaultOperation>;
@@ -9673,7 +9673,7 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentData<F> {
         self.all_keys_required
     }
 
-    fn get_whole_connector_response(&self) -> Option<String> {
+    fn get_whole_connector_response(&self) -> Option<Secret<String>> {
         self.whole_connector_response.clone()
     }
 
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index f42efa0c1e4..21215ea7235 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -5,7 +5,7 @@ use error_stack::ResultExt;
 use hyperswitch_domain_models::errors::api_error_response::ApiErrorResponse;
 #[cfg(feature = "v2")]
 use hyperswitch_domain_models::payments::PaymentConfirmData;
-use masking::ExposeInterface;
+use masking::{ExposeInterface, Secret};
 use unified_connector_service_client::payments as payments_grpc;
 
 // use router_env::tracing::Instrument;
@@ -555,7 +555,9 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
 
         self.status = status;
         self.response = router_data_response;
-        self.raw_connector_response = payment_authorize_response.raw_connector_response;
+        self.raw_connector_response = payment_authorize_response
+            .raw_connector_response
+            .map(Secret::new);
 
         Ok(())
     }
diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs
index e27c9974406..84752f16520 100644
--- a/crates/router/src/core/payments/flows/psync_flow.rs
+++ b/crates/router/src/core/payments/flows/psync_flow.rs
@@ -2,6 +2,7 @@ use std::collections::HashMap;
 
 use async_trait::async_trait;
 use error_stack::ResultExt;
+use masking::Secret;
 use unified_connector_service_client::payments as payments_grpc;
 
 use super::{ConstructFlowSpecificData, Feature};
@@ -256,7 +257,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>
 
         self.status = status;
         self.response = router_data_response;
-        self.raw_connector_response = payment_get_response.raw_connector_response;
+        self.raw_connector_response = payment_get_response.raw_connector_response.map(Secret::new);
 
         Ok(())
     }
diff --git a/crates/router/src/core/payments/operations/payment_confirm_intent.rs b/crates/router/src/core/payments/operations/payment_confirm_intent.rs
index 5de3b754083..143d6f7d342 100644
--- a/crates/router/src/core/payments/operations/payment_confirm_intent.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm_intent.rs
@@ -597,6 +597,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentConfirmData<F>, PaymentsConfirmInt
             .connector_request_reference_id
             .clone();
 
+        // Updates payment_attempt for cases where authorize flow is not performed.
         let connector_response_reference_id = payment_data
             .payment_attempt
             .connector_response_reference_id
diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs
index fabfe3e38d2..9b6c091a577 100644
--- a/crates/router/src/services/api.rs
+++ b/crates/router/src/services/api.rs
@@ -45,7 +45,7 @@ pub use hyperswitch_interfaces::{
         BoxedConnectorIntegrationV2, ConnectorIntegrationAnyV2, ConnectorIntegrationV2,
     },
 };
-use masking::{Maskable, PeekInterface};
+use masking::{Maskable, PeekInterface, Secret};
 use router_env::{instrument, tracing, tracing_actix_web::RequestId, Tag};
 use serde::Serialize;
 use serde_json::json;
@@ -310,7 +310,8 @@ where
                                                         .trim_start_matches('\u{feff}')
                                                         .to_string();
                                                 }
-                                                data.raw_connector_response = Some(decoded);
+                                                data.raw_connector_response =
+                                                    Some(Secret::new(decoded));
                                             }
                                             Ok(data)
                                         }

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

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

## Description
<!-- Describe your changes in detail -->
This PR makes raw_connector_response as a Secret and it also addresses unresolved comments of https://github.com/juspay/hyperswitch/pull/8499

### 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?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
Payments - Create
```
curl --location 'http://localhost:8080/v2/payments' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_2Epn3j4dw4PTTcAeiYCq' \
--header 'Authorization: api-key=dev_rVjIA9bnmFxbtjq0nZeACzzLz9mqAMLNNRBG26wWmCMnkUb3kAs2MaPXR0Nlxzkx' \
--data-raw '{
  "amount_details": {
    "currency": "USD",
    "order_amount": 6540
  },
  "payment_method_data": {
    "card": {
      "card_cvc": "123",
      "card_exp_month": "10",
      "card_exp_year": "25",
      "card_holder_name": "joseph Doe",
      "card_number": "4242424242424242"
    },
    "billing": {
            "address": {
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "IN",
                "first_name": "Swangi",
                "last_name": "Kumari"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            },
            "email": "swangi.kumari@juspay.in"
        }
  },
  "payment_method_subtype": "credit",
  "payment_method_type": "card",
  "return_raw_connector_response": true
}'
```
Response
```
{
    "id": "12345_pay_0197ede6d02c77d1a499530bf675e725",
    "status": "succeeded",
    "amount": {
        "order_amount": 6540,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 6540,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": 6540
    },
    "customer_id": null,
    "connector": "stripe",
    "created": "2025-07-09T06:36:56.236Z",
    "payment_method_data": {
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "IN",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": "Swangi",
                "last_name": "Kumari"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            },
            "email": "swangi.kumari@juspay.in"
        }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "connector_transaction_id": "pi_3RirciD5R7gDAGff0JSMZ9vN",
    "connector_reference_id": "pi_3RirciD5R7gDAGff0JSMZ9vN",
    "merchant_connector_id": "mca_afJBIsuaoPHhNuVG2CCo",
    "browser_info": null,
    "error": null,
    "shipping": null,
    "billing": null,
    "attempts": null,
    "connector_token_details": {
        "token": "pm_1RirciD5R7gDAGff9P1tYKQk",
        "connector_token_request_reference_id": "cRhwNEwZyiEAeSeCCv"
    },
    "payment_method_id": null,
    "next_action": null,
    "return_url": "https://google.com/success",
    "authentication_type": null,
    "authentication_type_applied": "no_three_ds",
    "is_iframe_redirection_enabled": null,
    "merchant_reference_id": null,
    "raw_connector_response": "{\n  \"id\": \"pi_3RirciD5R7gDAGff0JSMZ9vN\",\n  \"object\": \"payment_intent\",\n  \"amount\": 6540,\n  \"amount_capturable\": 0,\n  \"amount_details\": {\n    \"tip\": {}\n  },\n  \"amount_received\": 6540,\n  \"application\": null,\n  \"application_fee_amount\": null,\n  \"automatic_payment_methods\": null,\n  \"canceled_at\": null,\n  \"cancellation_reason\": null,\n  \"capture_method\": \"automatic\",\n  \"client_secret\": \"pi_3RirciD5R7gDAGff0JSMZ9vN_secret_UW4tYLvjQrDi7NHt8Scv7Bade\",\n  \"confirmation_method\": \"automatic\",\n  \"created\": 1752043016,\n  \"currency\": \"usd\",\n  \"customer\": null,\n  \"description\": null,\n  \"invoice\": null,\n  \"last_payment_error\": null,\n  \"latest_charge\": {\n    \"id\": \"ch_3RirciD5R7gDAGff0T483Brp\",\n    \"object\": \"charge\",\n    \"amount\": 6540,\n    \"amount_captured\": 6540,\n    \"amount_refunded\": 0,\n    \"amount_updates\": [],\n    \"application\": null,\n    \"application_fee\": null,\n    \"application_fee_amount\": null,\n    \"balance_transaction\": \"txn_3RirciD5R7gDAGff0YvvPlkn\",\n    \"billing_details\": {\n      \"address\": {\n        \"city\": \"San Fransico\",\n        \"country\": \"IN\",\n        \"line1\": \"1467\",\n        \"line2\": \"Harrison Street\",\n        \"postal_code\": \"94122\",\n        \"state\": \"California\"\n      },\n      \"email\": \"swangi.kumari@juspay.in\",\n      \"name\": \"Swangi Kumari\",\n      \"phone\": \"8056594427\",\n      \"tax_id\": null\n    },\n    \"calculated_statement_descriptor\": \"D2CSTORE0\",\n    \"captured\": true,\n    \"created\": 1752043017,\n    \"currency\": \"usd\",\n    \"customer\": null,\n    \"description\": null,\n    \"destination\": null,\n    \"dispute\": null,\n    \"disputed\": false,\n    \"failure_balance_transaction\": null,\n    \"failure_code\": null,\n    \"failure_message\": null,\n    \"fraud_details\": {},\n    \"invoice\": null,\n    \"livemode\": false,\n    \"metadata\": {\n      \"order_id\": \"12345_att_0197ede6d0497bc3b00553f0bd9bf01c\"\n    },\n    \"on_behalf_of\": null,\n    \"order\": null,\n    \"outcome\": {\n      \"advice_code\": null,\n      \"network_advice_code\": null,\n      \"network_decline_code\": null,\n      \"network_status\": \"approved_by_network\",\n      \"reason\": null,\n      \"risk_level\": \"normal\",\n      \"risk_score\": 4,\n      \"rule\": \"allow_if_in_allowlist\",\n      \"seller_message\": \"Payment complete.\",\n      \"type\": \"authorized\"\n    },\n    \"paid\": true,\n    \"payment_intent\": \"pi_3RirciD5R7gDAGff0JSMZ9vN\",\n    \"payment_method\": \"pm_1RirciD5R7gDAGff9P1tYKQk\",\n    \"payment_method_details\": {\n      \"card\": {\n        \"amount_authorized\": 6540,\n        \"authorization_code\": \"667270\",\n        \"brand\": \"visa\",\n        \"checks\": {\n          \"address_line1_check\": \"pass\",\n          \"address_postal_code_check\": \"pass\",\n          \"cvc_check\": \"pass\"\n        },\n        \"country\": \"US\",\n        \"exp_month\": 10,\n        \"exp_year\": 2025,\n        \"extended_authorization\": {\n          \"status\": \"disabled\"\n        },\n        \"fingerprint\": \"h7L3P7Ht9VtwZ6yb\",\n        \"funding\": \"credit\",\n        \"incremental_authorization\": {\n          \"status\": \"unavailable\"\n        },\n        \"installments\": null,\n        \"last4\": \"4242\",\n        \"mandate\": null,\n        \"multicapture\": {\n          \"status\": \"unavailable\"\n        },\n        \"network\": \"visa\",\n        \"network_token\": {\n          \"used\": false\n        },\n        \"network_transaction_id\": \"104557651805572\",\n        \"overcapture\": {\n          \"maximum_amount_capturable\": 6540,\n          \"status\": \"unavailable\"\n        },\n        \"regulated_status\": \"unregulated\",\n        \"three_d_secure\": null,\n        \"wallet\": null\n      },\n      \"type\": \"card\"\n    },\n    \"radar_options\": {},\n    \"receipt_email\": null,\n    \"receipt_number\": null,\n    \"receipt_url\": \"https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xTTdmVGFENVI3Z0RBR2ZmKImcuMMGMgZ0E_VSu6k6LBYDbs4wzaE7cYX2DHDMygwy6f_E0Q1SGSjyRrHheoBChPHBQVxXj4zo7kwE\",\n    \"refunded\": false,\n    \"review\": null,\n    \"shipping\": null,\n    \"source\": null,\n    \"source_transfer\": null,\n    \"statement_descriptor\": null,\n    \"statement_descriptor_suffix\": null,\n    \"status\": \"succeeded\",\n    \"transfer_data\": null,\n    \"transfer_group\": null\n  },\n  \"livemode\": false,\n  \"metadata\": {\n    \"order_id\": \"12345_att_0197ede6d0497bc3b00553f0bd9bf01c\"\n  },\n  \"next_action\": null,\n  \"on_behalf_of\": null,\n  \"payment_method\": \"pm_1RirciD5R7gDAGff9P1tYKQk\",\n  \"payment_method_configuration_details\": null,\n  \"payment_method_options\": {\n    \"card\": {\n      \"installments\": null,\n      \"mandate_options\": null,\n      \"network\": null,\n      \"request_three_d_secure\": \"automatic\"\n    }\n  },\n  \"payment_method_types\": [\n    \"card\"\n  ],\n  \"processing\": null,\n  \"receipt_email\": null,\n  \"review\": null,\n  \"setup_future_usage\": \"on_session\",\n  \"shipping\": null,\n  \"source\": null,\n  \"statement_descriptor\": null,\n  \"statement_descriptor_suffix\": null,\n  \"status\": \"succeeded\",\n  \"transfer_data\": null,\n  \"transfer_group\": null\n}"
}
```
The raw_connector_response was a JSON in logs, now it is a Secret
![image](https://github.com/user-attachments/assets/ce19a048-0bca-43e6-b293-7940b0cedd4f)


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