Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(core): make raw_connector_response as secret (#8565)

Aishwariyaa Anandfb33937c21dd
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 13cd8fa472..f3d7d9b675 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 6b5d1cf835..e800cb9cb6 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 33cdc32698..cdb636aab5 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 a18f9e5dc6..259f280d49 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 5319e82361..cf45d15a5a 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 f42efa0c1e..21215ea723 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 e27c997440..84752f1652 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 5de3b75408..143d6f7d34 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 fabfe3e38d..9b6c091a57 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)
}