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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(routing): cache redaction on updation of mca (#9729)
Prajjwal Kumarb52aafa8873f
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 30f7094348..9652bfdd52 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -23,7 +23,7 @@ use masking::{ExposeInterface, PeekInterface, Secret};use pm_auth::types as pm_auth_types;use uuid::Uuid;-use super::routing::helpers::{redact_cgraph_cache, update_default_fallback_on_mca_update};+use super::routing::helpers::redact_cgraph_cache;#[cfg(any(feature = "v1", feature = "v2"))]use crate::types::transformers::ForeignFrom;use crate::{@@ -2873,7 +2873,7 @@ pub async fn update_connector(let updated_mca = db.update_merchant_connector_account(key_manager_state,- mca,+ mca.clone(),payment_connector.into(),&key_store,)@@ -2894,8 +2894,33 @@ pub async fn update_connector(// redact cgraph cache on connector updationredact_cgraph_cache(&state, merchant_id, &profile_id).await?;- // update default fallback config- update_default_fallback_on_mca_update(&state, merchant_id, &profile_id, &updated_mca).await?;+ // redact routing cache on connector updation+ #[cfg(feature = "v1")]+ let merchant_config = MerchantDefaultConfigUpdate {+ routable_connector: &Some(+ common_enums::RoutableConnectors::from_str(&mca.connector_name).map_err(|_| {+ errors::ApiErrorResponse::InvalidDataValue {+ field_name: "connector_name",+ }+ })?,+ ),+ merchant_connector_id: &mca.get_id(),+ store: db,+ merchant_id,+ profile_id: &mca.profile_id,+ transaction_type: &mca.connector_type.into(),+ };++ #[cfg(feature = "v1")]+ if req.disabled.unwrap_or(false) {+ merchant_config+ .retrieve_and_delete_from_default_fallback_routing_algorithm_if_routable_connector_exists()+ .await?;+ } else {+ merchant_config+ .retrieve_and_update_default_fallback_routing_algorithm_if_routable_connector_exists()+ .await?;+ }let response = updated_mca.foreign_try_into()?;diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rsindex 03e24ca2bf..e5671e2edb 100644--- a/crates/router/src/core/routing/helpers.rs+++ b/crates/router/src/core/routing/helpers.rs@@ -2,9 +2,11 @@//!//! Functions that are used to perform the retrieval of merchant's//! routing dict, configs, defaults+use std::fmt::Debug;+#[cfg(all(feature = "dynamic_routing", feature = "v1"))]+use std::str::FromStr;#[cfg(all(feature = "dynamic_routing", feature = "v1"))]use std::sync::Arc;-use std::{fmt::Debug, str::FromStr};#[cfg(feature = "v1")]use api_models::open_router;@@ -2788,50 +2790,3 @@ pub async fn redact_routing_cache(Ok(())}--pub async fn update_default_fallback_on_mca_update(- state: &SessionState,- merchant_id: &id_type::MerchantId,- profile_id: &id_type::ProfileId,- updated_mca: &hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccount,-) -> RouterResult<()> {- let db = state.store.as_ref();- let merchant_id_str = merchant_id.get_string_repr();- let profile_id_str = profile_id.get_string_repr();- let txn_type = &storage::enums::TransactionType::from(updated_mca.connector_type);-- let mut connectors = get_merchant_default_config(db, merchant_id_str, txn_type).await?;-- let choice = routing_types::RoutableConnectorChoice {- choice_kind: routing_types::RoutableChoiceKind::FullStruct,- connector: api_models::enums::RoutableConnectors::from_str(- &updated_mca.connector_name.to_string(),- )- .change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)- .attach_printable(format!(- "Unable to parse RoutableConnectors from connector: {}",- updated_mca.connector_name- ))?,- merchant_connector_id: Some(updated_mca.get_id().clone()),- };-- if updated_mca.disabled.unwrap_or(false)- || updated_mca.status == api_models::enums::ConnectorStatus::Inactive- {- // remove if disabled- connectors.retain(|c| c.merchant_connector_id != Some(updated_mca.get_id().clone()));- } else {- // ensure it is present if enabled- if !connectors.contains(&choice) {- connectors.push(choice);- }- }-- // update merchant config- update_merchant_default_config(db, merchant_id_str, connectors.clone(), txn_type).await?;-- // update profile config- update_merchant_default_config(db, profile_id_str, connectors, txn_type).await?;-- Ok(())-}