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): add cache redaction for cgraph (#9629)

Prajjwal Kumar654ffe472fc2
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index cd0fc3dcad..0a2252be15 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -23,6 +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;
#[cfg(any(feature = "v1", feature = "v2"))]
use crate::types::transformers::ForeignFrom;
use crate::{
@@ -2577,6 +2578,9 @@ pub async fn create_connector(
},
)?;
+ // redact cgraph cache on new connector creation
+ redact_cgraph_cache(&state, merchant_id, business_profile.get_id()).await?;
+
#[cfg(feature = "v1")]
disputes::schedule_dispute_sync_task(&state, &business_profile, &mca).await?;
@@ -2887,6 +2891,9 @@ pub async fn update_connector(
)
})?;
+ // redact cgraph cache on connector updation
+ redact_cgraph_cache(&state, merchant_id, &profile_id).await?;
+
let response = updated_mca.foreign_try_into()?;
Ok(service_api::ApplicationResponse::Json(response))
@@ -2956,6 +2963,8 @@ pub async fn delete_connector(
.retrieve_and_delete_from_default_fallback_routing_algorithm_if_routable_connector_exists()
.await?;
+ // redact cgraph cache on connector deletion
+ redact_cgraph_cache(&state, &merchant_id, &mca.profile_id).await?;
let response = api::MerchantConnectorDeleteResponse {
merchant_id,
merchant_connector_id,
diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs
index 98b71748b3..27a83ea0b9 100644
--- a/crates/router/src/core/routing/helpers.rs
+++ b/crates/router/src/core/routing/helpers.rs
@@ -2731,3 +2731,33 @@ pub async fn delete_decision_engine_merchant(
Ok(())
}
+
+pub async fn redact_cgraph_cache(
+ state: &SessionState,
+ merchant_id: &id_type::MerchantId,
+ profile_id: &id_type::ProfileId,
+) -> RouterResult<()> {
+ let cgraph_payouts_key = format!(
+ "cgraph_po_{}_{}",
+ merchant_id.get_string_repr(),
+ profile_id.get_string_repr(),
+ );
+
+ let cgraph_payments_key = format!(
+ "cgraph_{}_{}",
+ merchant_id.get_string_repr(),
+ profile_id.get_string_repr(),
+ );
+
+ let config_payouts_key = cache::CacheKind::CGraph(cgraph_payouts_key.clone().into());
+ let config_payments_key = cache::CacheKind::CGraph(cgraph_payments_key.clone().into());
+ cache::redact_from_redis_and_publish(
+ state.store.get_cache_store().as_ref(),
+ [config_payouts_key, config_payments_key],
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to invalidate the cgraph cache")?;
+
+ Ok(())
+}
diff --git a/crates/router/src/core/subscription.rs b/crates/router/src/core/subscription.rs
index b5c760ad3e..6b98eabf8b 100644
--- a/crates/router/src/core/subscription.rs
+++ b/crates/router/src/core/subscription.rs
@@ -214,7 +214,7 @@ pub struct SubscriptionWithHandler<'a> {
profile: hyperswitch_domain_models::business_profile::Profile,
}
-impl<'a> SubscriptionWithHandler<'a> {
+impl SubscriptionWithHandler<'_> {
fn generate_response(
&self,
invoice: &diesel_models::invoice::Invoice,