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

perf(core): Introduce a new MCA domain type to reduce encryption service calls (#13223)

Anurag Thakurf7f28242e105
diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs
index f2fc0606f2..904ab92862 100644
--- a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs
+++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs
@@ -1017,6 +1017,249 @@ common_utils::create_list_wrapper!(
}
);
+/// A lightweight view of [`MerchantConnectorAccount`] containing only the
+/// columns that are NOT keymanager-encrypted. Fetching this type performs no
+/// decryption calls.
+///
+/// If you need `connector_account_details`, `connector_wallets_details`, or
+/// `additional_merchant_data`, fetch the full [`MerchantConnectorAccount`]
+/// via a single-row find instead.
+#[cfg(feature = "v1")]
+#[derive(Clone, Debug)]
+pub struct MerchantConnectorAccountWithoutEncrypted {
+ pub merchant_id: id_type::MerchantId,
+ pub connector_name: String,
+ pub test_mode: Option<bool>,
+ pub disabled: Option<bool>,
+ pub merchant_connector_id: id_type::MerchantConnectorAccountId,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_type: enums::ConnectorType,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub frm_configs: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_label: Option<String>,
+ pub business_country: Option<enums::CountryAlpha2>,
+ pub business_label: Option<String>,
+ pub business_sub_label: Option<String>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ pub profile_id: id_type::ProfileId,
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: enums::ConnectorStatus,
+ pub version: common_enums::ApiVersion,
+ pub connector_webhook_registration_details: Option<Value>,
+}
+
+#[cfg(feature = "v1")]
+impl TryFrom<storage::MerchantConnectorAccount> for MerchantConnectorAccountWithoutEncrypted {
+ type Error = error_stack::Report<ValidationError>;
+
+ fn try_from(other: storage::MerchantConnectorAccount) -> Result<Self, Self::Error> {
+ Ok(Self {
+ merchant_id: other.merchant_id,
+ connector_name: other.connector_name,
+ test_mode: other.test_mode,
+ disabled: other.disabled,
+ merchant_connector_id: other.merchant_connector_id,
+ payment_methods_enabled: other.payment_methods_enabled,
+ connector_type: other.connector_type,
+ metadata: other.metadata,
+ frm_configs: other.frm_config,
+ business_country: other.business_country,
+ business_label: other.business_label,
+ connector_label: other.connector_label,
+ business_sub_label: other.business_sub_label,
+ created_at: other.created_at,
+ modified_at: other.modified_at,
+ connector_webhook_details: other.connector_webhook_details,
+ profile_id: other
+ .profile_id
+ .ok_or(ValidationError::MissingRequiredField {
+ field_name: "profile_id".to_string(),
+ })?,
+ applepay_verified_domains: other.applepay_verified_domains,
+ pm_auth_config: other.pm_auth_config,
+ status: other.status,
+ version: other.version,
+ connector_webhook_registration_details: other.connector_webhook_registration_details,
+ })
+ }
+}
+
+#[cfg(feature = "v1")]
+impl MerchantConnectorAccountWithoutEncrypted {
+ pub fn get_id(&self) -> id_type::MerchantConnectorAccountId {
+ self.merchant_connector_id.clone()
+ }
+
+ pub fn get_connector_name_as_string(&self) -> String {
+ self.connector_name.clone()
+ }
+
+ pub fn get_metadata(&self) -> Option<pii::SecretSerdeValue> {
+ self.metadata.clone()
+ }
+}
+
+/// A lightweight view of [`MerchantConnectorAccount`] containing only the
+/// columns that are NOT keymanager-encrypted. Fetching this type performs no
+/// decryption calls.
+///
+/// If you need `connector_account_details`, `connector_wallets_details`, or
+/// `additional_merchant_data`, fetch the full [`MerchantConnectorAccount`]
+/// via a single-row find instead.
+#[cfg(feature = "v2")]
+#[derive(Clone, Debug)]
+pub struct MerchantConnectorAccountWithoutEncrypted {
+ pub id: id_type::MerchantConnectorAccountId,
+ pub merchant_id: id_type::MerchantId,
+ pub connector_name: common_enums::connector_enums::Connector,
+ pub disabled: Option<bool>,
+ pub payment_methods_enabled: Option<Vec<common_types::payment_methods::PaymentMethodsEnabled>>,
+ pub connector_type: enums::ConnectorType,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub frm_configs: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_label: Option<String>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ pub profile_id: id_type::ProfileId,
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: enums::ConnectorStatus,
+ pub version: common_enums::ApiVersion,
+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
+}
+
+#[cfg(feature = "v2")]
+impl TryFrom<storage::MerchantConnectorAccount> for MerchantConnectorAccountWithoutEncrypted {
+ type Error = error_stack::Report<ValidationError>;
+
+ fn try_from(other: storage::MerchantConnectorAccount) -> Result<Self, Self::Error> {
+ Ok(Self {
+ id: other.id,
+ merchant_id: other.merchant_id,
+ connector_name: other.connector_name,
+ disabled: other.disabled,
+ payment_methods_enabled: other.payment_methods_enabled,
+ connector_type: other.connector_type,
+ metadata: other.metadata,
+ frm_configs: other.frm_config,
+ connector_label: other.connector_label,
+ created_at: other.created_at,
+ modified_at: other.modified_at,
+ connector_webhook_details: other.connector_webhook_details,
+ profile_id: other.profile_id,
+ applepay_verified_domains: other.applepay_verified_domains,
+ pm_auth_config: other.pm_auth_config,
+ status: other.status,
+ version: other.version,
+ feature_metadata: other.feature_metadata.map(From::from),
+ })
+ }
+}
+
+#[cfg(feature = "v2")]
+impl MerchantConnectorAccountWithoutEncrypted {
+ pub fn get_id(&self) -> id_type::MerchantConnectorAccountId {
+ self.id.clone()
+ }
+
+ pub fn get_connector_name_as_string(&self) -> String {
+ self.connector_name.clone().to_string()
+ }
+
+ pub fn get_metadata(&self) -> Option<pii::SecretSerdeValue> {
+ self.metadata.clone()
+ }
+}
+
+common_utils::create_list_wrapper!(
+ MerchantConnectorAccountsWithoutEncrypted,
+ MerchantConnectorAccountWithoutEncrypted,
+ impl_functions: {
+ fn filter_and_map<'a, T>(
+ &'a self,
+ filter: impl Fn(&'a MerchantConnectorAccountWithoutEncrypted) -> bool,
+ func: impl Fn(&'a MerchantConnectorAccountWithoutEncrypted) -> T,
+ ) -> rustc_hash::FxHashSet<T>
+ where
+ T: std::hash::Hash + Eq,
+ {
+ self.0
+ .iter()
+ .filter(|mca| filter(mca))
+ .map(func)
+ .collect::<rustc_hash::FxHashSet<_>>()
+ }
+
+ pub fn filter_by_profile<'a, T>(
+ &'a self,
+ profile_id: &'a id_type::ProfileId,
+ func: impl Fn(&'a MerchantConnectorAccountWithoutEncrypted) -> T,
+ ) -> rustc_hash::FxHashSet<T>
+ where
+ T: std::hash::Hash + Eq,
+ {
+ self.filter_and_map(|mca| mca.profile_id == *profile_id, func)
+ }
+ #[cfg(feature = "v2")]
+ pub fn get_connector_and_supporting_payment_method_type_for_session_call(
+ &self,
+ ) -> Vec<(&MerchantConnectorAccountWithoutEncrypted, common_enums::PaymentMethodType, common_enums::PaymentMethod)> {
+ // This vector is created to work around lifetimes
+ let ref_vector = Vec::default();
+
+ let connector_and_supporting_payment_method_type = self.iter().flat_map(|connector_account| {
+ connector_account
+ .payment_methods_enabled.as_ref()
+ .unwrap_or(&Vec::default())
+ .iter()
+ .flat_map(|payment_method_types| payment_method_types.payment_method_subtypes.as_ref().unwrap_or(&ref_vector).iter().map(|payment_method_subtype| (payment_method_subtype, payment_method_types.payment_method_type)).collect::<Vec<_>>())
+ .filter(|(payment_method_types_enabled, _)| {
+ payment_method_types_enabled.payment_experience == Some(api_models::enums::PaymentExperience::InvokeSdkClient)
+ })
+ .map(|(payment_method_subtypes, payment_method_type)| {
+ (connector_account, payment_method_subtypes.payment_method_subtype, payment_method_type)
+ })
+ .collect::<Vec<_>>()
+ }).collect();
+ connector_and_supporting_payment_method_type
+ }
+ pub fn filter_based_on_profile_and_connector_type(
+ self,
+ profile_id: &id_type::ProfileId,
+ connector_type: common_enums::ConnectorType,
+ ) -> Self {
+ self.into_iter()
+ .filter(|mca| &mca.profile_id == profile_id && mca.connector_type == connector_type)
+ .collect()
+ }
+ pub fn is_merchant_connector_account_id_in_connector_mandate_details(
+ &self,
+ profile_id: Option<&id_type::ProfileId>,
+ connector_mandate_details: &CommonMandateReference,
+ ) -> bool {
+ let mca_ids = self
+ .iter()
+ .filter(|mca| {
+ mca.disabled.is_some_and(|disabled| !disabled)
+ && profile_id.is_some_and(|profile_id| *profile_id == mca.profile_id)
+ })
+ .map(|mca| mca.get_id())
+ .collect::<std::collections::HashSet<_>>();
+
+ connector_mandate_details
+ .payments
+ .as_ref()
+ .as_ref().is_some_and(|payments| {
+ payments.0.keys().any(|mca_id| mca_ids.contains(mca_id))
+ })
+ }
+ }
+);
+
#[cfg(feature = "v2")]
impl From<MerchantConnectorAccountFeatureMetadata>
for DieselMerchantConnectorAccountFeatureMetadata
@@ -1121,6 +1364,17 @@ where
key_store: &MerchantKeyStore,
) -> CustomResult<MerchantConnectorAccounts, Self::Error>;
+ /// Like [`Self::find_merchant_connector_account_by_merchant_id_and_disabled_list`],
+ /// but returns [`MerchantConnectorAccountsWithoutEncrypted`] — only the
+ /// non-keymanager-encrypted columns — and therefore performs no
+ /// decryption (no `key_store` needed, zero encryption-service calls).
+ /// Prefer this whenever the encrypted fields are not read.
+ async fn find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ &self,
+ merchant_id: &id_type::MerchantId,
+ get_disabled: bool,
+ ) -> CustomResult<MerchantConnectorAccountsWithoutEncrypted, Self::Error>;
+
#[cfg(all(feature = "olap", feature = "v2"))]
async fn list_connector_account_by_profile_id(
&self,
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index da0e8ef20c..e0e478d8c7 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1552,7 +1552,6 @@ struct PMAuthConfigValidation<'a> {
db: &'a dyn StorageInterface,
merchant_id: &'a id_type::MerchantId,
profile_id: &'a id_type::ProfileId,
- key_store: &'a domain::MerchantKeyStore,
}
impl PMAuthConfigValidation<'_> {
@@ -1567,10 +1566,9 @@ impl PMAuthConfigValidation<'_> {
let all_mcas = self
.db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
self.merchant_id,
true,
- self.key_store,
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
@@ -2025,7 +2023,6 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect
db: state.store.as_ref(),
merchant_id: platform.get_processor().get_account().get_id(),
profile_id: &mca.profile_id.clone(),
- key_store: platform.get_processor().get_key_store(),
};
pm_auth_config_validation.validate_pm_auth_config().await?;
@@ -2780,7 +2777,6 @@ pub async fn create_connector(
db: store,
merchant_id,
profile_id: business_profile.get_id(),
- key_store: processor.get_key_store(),
};
pm_auth_config_validation.validate_pm_auth_config().await?;
@@ -2892,10 +2888,9 @@ async fn validate_pm_auth(
let all_mcas = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
merchant_id,
true,
- platform.get_processor().get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
@@ -3015,10 +3010,9 @@ pub async fn list_payment_connectors(
let store = state.store.as_ref();
let merchant_connector_accounts = store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
processor.get_account().get_id(),
true,
- processor.get_key_store(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index f5f5c39aae..a9621978fd 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -3903,10 +3903,9 @@ pub async fn build_merchant_enabled_pms_context(
// --- Load all MCAs and filter by profile + connector type ---
let all_mcas = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
platform.get_processor().get_account().get_id(),
false,
- platform.get_processor().get_key_store(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
@@ -5683,10 +5682,9 @@ pub async fn list_customer_payment_method(
let merchant_connector_accounts = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
platform.get_processor().get_account().get_id(),
true,
- platform.get_processor().get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
@@ -6034,7 +6032,7 @@ pub async fn get_mca_status(
is_connector_agnostic_mit_enabled: bool,
connector_mandate_details: Option<CommonMandateReference>,
network_transaction_id: Option<&String>,
- merchant_connector_accounts: &domain::MerchantConnectorAccounts,
+ merchant_connector_accounts: &domain::MerchantConnectorAccountsWithoutEncrypted,
) -> errors::RouterResult<bool> {
let agnostic_mit = is_connector_agnostic_mit_enabled && network_transaction_id.is_some();
diff --git a/crates/router/src/core/payment_methods/client.rs b/crates/router/src/core/payment_methods/client.rs
index 6d3ab0c66c..e13a7c9c2d 100644
--- a/crates/router/src/core/payment_methods/client.rs
+++ b/crates/router/src/core/payment_methods/client.rs
@@ -200,10 +200,9 @@ impl CustomerPaymentMethodsFetcher for ModularCustomerPaymentMethodsFetcher {
// `get_mca_status` check performed in the legacy DB flow.
let merchant_connector_accounts = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
&merchant_id,
true,
- platform.get_processor().get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 788d9f75ef..0d610a830b 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -6953,10 +6953,9 @@ pub async fn get_apple_pay_retryable_connectors(
)? {
let merchant_connector_account_list = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
processor.get_account().get_id(),
false,
- processor.get_key_store(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
@@ -8935,24 +8934,23 @@ pub async fn validate_routing_id_with_profile_id(
#[cfg(feature = "v1")]
pub async fn validate_merchant_connector_ids_in_connector_mandate_details(
state: &SessionState,
- key_store: &domain::MerchantKeyStore,
+ _key_store: &domain::MerchantKeyStore,
connector_mandate_details: &api_models::payment_methods::CommonMandateReference,
merchant_id: &id_type::MerchantId,
card_network: Option<api_enums::CardNetwork>,
) -> CustomResult<(), errors::ApiErrorResponse> {
let db = &*state.store;
let merchant_connector_account_list = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
merchant_id,
true,
- key_store,
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
let merchant_connector_account_details_hash_map: std::collections::HashMap<
id_type::MerchantConnectorAccountId,
- domain::MerchantConnectorAccount,
+ domain::MerchantConnectorAccountWithoutEncrypted,
> = merchant_connector_account_list
.iter()
.map(|merchant_connector_account| {
@@ -9251,10 +9249,9 @@ pub async fn validate_allowed_payment_method_types_request(
if let Some(allowed_payment_method_types) = allowed_payment_method_types {
let db = &*state.store;
let all_connector_accounts = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
processor.get_account().get_id(),
false,
- processor.get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index 1af71dba99..0a3ea5ccf8 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -408,10 +408,9 @@ where
let db = &state.store;
let all_connector_accounts = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
processor.get_account().get_id(),
false,
- processor.get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/payments/operations/payment_session_intent.rs b/crates/router/src/core/payments/operations/payment_session_intent.rs
index 39ed19574a..0cd587cfad 100644
--- a/crates/router/src/core/payments/operations/payment_session_intent.rs
+++ b/crates/router/src/core/payments/operations/payment_session_intent.rs
@@ -276,10 +276,9 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsSessionRequest, payments::Payment
) -> CustomResult<api::ConnectorCallType, errors::ApiErrorResponse> {
let db = &state.store;
let all_connector_accounts = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
platform.get_processor().get_account().get_id(),
false,
- platform.get_processor().get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index 72d2736bff..858beab2bc 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -4091,14 +4091,13 @@ pub async fn get_active_mca_ids(
) -> RoutingResult<std::collections::HashSet<common_utils::id_type::MerchantConnectorAccountId>> {
let db_mcas = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
&key_store.merchant_id,
false,
- key_store,
)
.await
.unwrap_or_else(|_| {
- hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccounts::new(
+ hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccountsWithoutEncrypted::new(
vec![],
)
});
diff --git a/crates/router/src/core/payout_link.rs b/crates/router/src/core/payout_link.rs
index 3b549da4f8..168e6d6934 100644
--- a/crates/router/src/core/payout_link.rs
+++ b/crates/router/src/core/payout_link.rs
@@ -337,10 +337,9 @@ pub async fn filter_payout_methods(
let db = &*state.store;
//Fetch all merchant connector accounts
let all_mcas = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
platform.get_processor().get_account().get_id(),
false,
- platform.get_processor().get_key_store(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs
index a62a15d6d0..82eb82ffda 100644
--- a/crates/router/src/core/routing.rs
+++ b/crates/router/src/core/routing.rs
@@ -294,10 +294,9 @@ pub async fn create_routing_algorithm_under_profile(
core_utils::validate_profile_id_from_auth_layer(authentication_profile_id, &business_profile)?;
let all_mcas = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
processor_merchant_id,
true,
- processor.get_key_store(),
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs
index 42695041c4..d27cdfbdea 100644
--- a/crates/router/src/core/routing/helpers.rs
+++ b/crates/router/src/core/routing/helpers.rs
@@ -466,17 +466,16 @@ impl RoutingAlgorithmHelpers<'_> {
#[cfg(feature = "v1")]
pub async fn validate_connectors_in_routing_config(
state: &SessionState,
- key_store: &domain::MerchantKeyStore,
+ _key_store: &domain::MerchantKeyStore,
merchant_id: &id_type::MerchantId,
profile_id: &id_type::ProfileId,
routing_algorithm: &routing_types::StaticRoutingAlgorithm,
) -> RouterResult<()> {
let all_mcas = state
.store
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
merchant_id,
true,
- key_store,
)
.await
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
diff --git a/crates/router/src/core/superposition_sdk_config.rs b/crates/router/src/core/superposition_sdk_config.rs
index 7a13a64fc4..4d5d5601c7 100644
--- a/crates/router/src/core/superposition_sdk_config.rs
+++ b/crates/router/src/core/superposition_sdk_config.rs
@@ -153,10 +153,9 @@ pub async fn get_profile_superposition_sdk_config(
})?;
let all_mcas = db
- .find_merchant_connector_account_by_merchant_id_and_disabled_list(
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
platform.get_processor().get_account().get_id(),
false,
- platform.get_processor().get_key_store(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index df2fbe6a9e..ee6e444643 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -25,7 +25,9 @@ use error_stack::{report, ResultExt};
#[cfg(feature = "v2")]
use hyperswitch_domain_models::types::VaultRouterData;
use hyperswitch_domain_models::{
- merchant_connector_account::MerchantConnectorAccount,
+ merchant_connector_account::{
+ MerchantConnectorAccount, MerchantConnectorAccountWithoutEncrypted,
+ },
payment_address::PaymentAddress,
router_data::ErrorResponse,
router_data_v2::flow_common_types::VaultConnectorFlowData,
@@ -2568,6 +2570,12 @@ impl GetProfileId for MerchantConnectorAccount {
}
}
+impl GetProfileId for MerchantConnectorAccountWithoutEncrypted {
+ fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> {
+ Some(&self.profile_id)
+ }
+}
+
impl GetProfileId for storage::PaymentIntent {
#[cfg(feature = "v1")]
fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> {
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 7aa95465d9..8d5a63dfb1 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -1549,6 +1549,19 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.await
}
+ async fn find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ &self,
+ merchant_id: &id_type::MerchantId,
+ get_disabled: bool,
+ ) -> CustomResult<domain::MerchantConnectorAccountsWithoutEncrypted, errors::StorageError> {
+ self.diesel_store
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ merchant_id,
+ get_disabled,
+ )
+ .await
+ }
+
#[cfg(all(feature = "olap", feature = "v2"))]
async fn list_connector_account_by_profile_id(
&self,
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index d134ee16ec..dbfb8e4b60 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -996,6 +996,81 @@ impl ForeignTryFrom<domain::MerchantConnectorAccount>
}
}
+impl ForeignTryFrom<domain::MerchantConnectorAccountWithoutEncrypted>
+ for api_models::admin::MerchantConnectorListResponse
+{
+ type Error = error_stack::Report<errors::ApiErrorResponse>;
+ fn foreign_try_from(
+ item: domain::MerchantConnectorAccountWithoutEncrypted,
+ ) -> Result<Self, Self::Error> {
+ #[cfg(feature = "v1")]
+ let payment_methods_enabled = match item.payment_methods_enabled {
+ Some(secret_val) => {
+ let val = secret_val
+ .into_iter()
+ .map(|secret| secret.expose())
+ .collect();
+ serde_json::Value::Array(val)
+ .parse_value("PaymentMethods")
+ .change_context(errors::ApiErrorResponse::InternalServerError)?
+ }
+ None => None,
+ };
+
+ let frm_configs = match item.frm_configs {
+ Some(frm_value) => {
+ let configs_for_frm : Vec<api_models::admin::FrmConfigs> = frm_value
+ .iter()
+ .map(|config| { config
+ .peek()
+ .clone()
+ .parse_value("FrmConfigs")
+ .change_context(errors::ApiErrorResponse::InvalidDataFormat {
+ field_name: "frm_configs".to_string(),
+ expected_format: r#"[{ "gateway": "stripe", "payment_methods": [{ "payment_method": "card","payment_method_types": [{"payment_method_type": "credit","card_networks": ["Visa"],"flow": "pre","action": "cancel_txn"}]}]}]"#.to_string(),
+ })
+ })
+ .collect::<Result<Vec<_>, _>>()?;
+ Some(configs_for_frm)
+ }
+ None => None,
+ };
+ #[cfg(feature = "v1")]
+ let response = Self {
+ connector_type: item.connector_type,
+ connector_name: item.connector_name,
+ connector_label: item.connector_label,
+ merchant_connector_id: item.merchant_connector_id,
+ test_mode: item.test_mode,
+ disabled: item.disabled,
+ payment_methods_enabled,
+ business_country: item.business_country,
+ business_label: item.business_label,
+ business_sub_label: item.business_sub_label,
+ frm_configs,
+ profile_id: item.profile_id,
+ applepay_verified_domains: item.applepay_verified_domains,
+ pm_auth_config: item.pm_auth_config,
+ status: item.status,
+ };
+ #[cfg(feature = "v2")]
+ let response = Self {
+ id: item.id,
+ connector_type: item.connector_type,
+ connector_name: item.connector_name,
+ connector_label: item.connector_label,
+ disabled: item.disabled,
+ payment_methods_enabled: item.payment_methods_enabled,
+ frm_configs,
+ profile_id: item.profile_id,
+ applepay_verified_domains: item.applepay_verified_domains,
+ pm_auth_config: item.pm_auth_config,
+ status: item.status,
+ };
+ Ok(response)
+ }
+}
+
#[cfg(feature = "v1")]
impl ForeignTryFrom<domain::MerchantConnectorAccount>
for api_models::admin::MerchantConnectorResponse
diff --git a/crates/storage_impl/src/merchant_connector_account.rs b/crates/storage_impl/src/merchant_connector_account.rs
index 1598699927..41fe26ded2 100644
--- a/crates/storage_impl/src/merchant_connector_account.rs
+++ b/crates/storage_impl/src/merchant_connector_account.rs
@@ -138,6 +138,20 @@ impl<T: DatabaseStore> MerchantConnectorAccountInterface for kv_router_store::KV
.await
}
+ #[instrument(skip_all)]
+ async fn find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ &self,
+ merchant_id: &common_utils::id_type::MerchantId,
+ get_disabled: bool,
+ ) -> CustomResult<domain::MerchantConnectorAccountsWithoutEncrypted, Self::Error> {
+ self.router_store
+ .find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ merchant_id,
+ get_disabled,
+ )
+ .await
+ }
+
#[instrument(skip_all)]
#[cfg(all(feature = "olap", feature = "v2"))]
async fn list_connector_account_by_profile_id(
@@ -571,6 +585,32 @@ impl<T: DatabaseStore> MerchantConnectorAccountInterface for RouterStore<T> {
))
}
+ #[instrument(skip_all)]
+ async fn find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ &self,
+ merchant_id: &common_utils::id_type::MerchantId,
+ get_disabled: bool,
+ ) -> CustomResult<domain::MerchantConnectorAccountsWithoutEncrypted, Self::Error> {
+ let conn = pg_accounts_connection_read(self).await?;
+ let items = storage::MerchantConnectorAccount::find_by_merchant_id(
+ &conn,
+ merchant_id,
+ get_disabled,
+ )
+ .await
+ .map_err(|error| report!(Self::Error::from(error)))?;
+
+ let output = items
+ .into_iter()
+ .map(domain::MerchantConnectorAccountWithoutEncrypted::try_from)
+ .collect::<Result<Vec<_>, _>>()
+ .change_context(Self::Error::DecryptionError)?;
+
+ Ok(domain::MerchantConnectorAccountsWithoutEncrypted::new(
+ output,
+ ))
+ }
+
#[instrument(skip_all)]
#[cfg(all(feature = "olap", feature = "v2"))]
async fn list_connector_account_by_profile_id(
@@ -1352,6 +1392,37 @@ impl MerchantConnectorAccountInterface for MockDb {
Ok(domain::MerchantConnectorAccounts::new(output))
}
+ async fn find_merchant_connector_account_without_encrypted_by_merchant_id_and_disabled_list(
+ &self,
+ merchant_id: &common_utils::id_type::MerchantId,
+ get_disabled: bool,
+ ) -> CustomResult<domain::MerchantConnectorAccountsWithoutEncrypted, StorageError> {
+ let accounts = self
+ .merchant_connector_accounts
+ .lock()
+ .await
+ .iter()
+ .filter(|account: &&storage::MerchantConnectorAccount| {
+ if get_disabled {
+ account.merchant_id == *merchant_id
+ } else {
+ account.merchant_id == *merchant_id && account.disabled == Some(false)
+ }
+ })
+ .cloned()
+ .collect::<Vec<storage::MerchantConnectorAccount>>();
+
+ let output = accounts
+ .into_iter()
+ .map(domain::MerchantConnectorAccountWithoutEncrypted::try_from)
+ .collect::<Result<Vec<_>, _>>()
+ .change_context(StorageError::DecryptionError)?;
+
+ Ok(domain::MerchantConnectorAccountsWithoutEncrypted::new(
+ output,
+ ))
+ }
+
#[cfg(all(feature = "olap", feature = "v2"))]
async fn list_connector_account_by_profile_id(
&self,