mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
fix(routing): cache redaction on updation of mca (#9729)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -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 updation
|
||||
redact_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()?;
|
||||
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user