From 1f848659f135542fdfa967b3b48ad6cdf69fda2c Mon Sep 17 00:00:00 2001 From: Shanks Date: Thu, 14 Dec 2023 16:51:34 +0530 Subject: [PATCH] fix(router): add routing cache invalidation on payment connector update (#3132) --- crates/euclid_wasm/Cargo.toml | 2 +- crates/router/src/core/admin.rs | 77 ++++--------------- .../src/types/domain/merchant_account.rs | 5 ++ 3 files changed, 23 insertions(+), 61 deletions(-) diff --git a/crates/euclid_wasm/Cargo.toml b/crates/euclid_wasm/Cargo.toml index 51288a9d0f..f17cdec875 100644 --- a/crates/euclid_wasm/Cargo.toml +++ b/crates/euclid_wasm/Cargo.toml @@ -10,7 +10,7 @@ rust-version.workspace = true crate-type = ["cdylib"] [features] -default = ["connector_choice_bcompat"] +default = ["connector_choice_bcompat", "connector_choice_mca_id"] release = ["connector_choice_bcompat", "connector_choice_mca_id"] connector_choice_bcompat = ["api_models/connector_choice_bcompat"] connector_choice_mca_id = ["api_models/connector_choice_mca_id", "euclid/connector_choice_mca_id", "kgraph_utils/connector_choice_mca_id"] diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index f6aaf22480..84a2f442de 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -776,14 +776,13 @@ pub async fn create_payment_connector( let pm_auth_connector = api_enums::convert_pm_auth_connector(req.connector_name.to_string().as_str()); - let is_unroutable_connector = if pm_auth_connector.is_some() { + if pm_auth_connector.is_some() { if req.connector_type != api_enums::ConnectorType::PaymentMethodAuth { return Err(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid connector type given".to_string(), }) .into_report(); } - true } else { let routable_connector_option = req .connector_name @@ -794,7 +793,6 @@ pub async fn create_payment_connector( message: "Invalid connector name given".to_string(), })?; routable_connector = Some(routable_connector_option); - false }; // If connector label is not passed in the request, generate one @@ -863,31 +861,13 @@ pub async fn create_payment_connector( // The purpose of this merchant account update is just to update the // merchant account `modified_at` field for KGraph cache invalidation - let merchant_account_update = storage::MerchantAccountUpdate::Update { - merchant_name: None, - merchant_details: None, - return_url: None, - webhook_details: None, - sub_merchants_enabled: None, - parent_merchant_id: None, - enable_payment_response_hash: None, - locker_id: None, - payment_response_hash_key: None, - primary_business_details: None, - metadata: None, - publishable_key: None, - redirect_to_merchant_with_http_post: None, - routing_algorithm: None, - intent_fulfillment_time: None, - frm_routing_algorithm: None, - payout_routing_algorithm: None, - default_profile: None, - payment_link_config: None, - }; - state .store - .update_specific_fields_in_merchant(merchant_id, merchant_account_update, &key_store) + .update_specific_fields_in_merchant( + merchant_id, + storage::MerchantAccountUpdate::ModifiedAtUpdate, + &key_store, + ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("error updating the merchant account when creating payment connector")?; @@ -1018,40 +998,6 @@ pub async fn create_payment_connector( ], ); - if !is_unroutable_connector { - if let Some(routable_connector_val) = routable_connector { - let choice = routing_types::RoutableConnectorChoice { - #[cfg(feature = "backwards_compatibility")] - choice_kind: routing_types::RoutableChoiceKind::FullStruct, - connector: routable_connector_val, - #[cfg(feature = "connector_choice_mca_id")] - merchant_connector_id: Some(mca.merchant_connector_id.clone()), - #[cfg(not(feature = "connector_choice_mca_id"))] - sub_label: req.business_sub_label.clone(), - }; - - if !default_routing_config.contains(&choice) { - default_routing_config.push(choice.clone()); - routing_helpers::update_merchant_default_config( - &*state.clone().store, - merchant_id, - default_routing_config, - ) - .await?; - } - - if !default_routing_config_for_profile.contains(&choice) { - default_routing_config_for_profile.push(choice); - routing_helpers::update_merchant_default_config( - &*state.store, - &profile_id, - default_routing_config_for_profile, - ) - .await?; - } - } - }; - let mca_response = mca.try_into()?; Ok(service_api::ApplicationResponse::Json(mca_response)) } @@ -1240,6 +1186,17 @@ pub async fn update_payment_connector( } } + // The purpose of this merchant account update is just to update the + // merchant account `modified_at` field for KGraph cache invalidation + db.update_specific_fields_in_merchant( + merchant_id, + storage::MerchantAccountUpdate::ModifiedAtUpdate, + &key_store, + ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("error updating the merchant account when updating payment connector")?; + let payment_connector = storage::MerchantConnectorAccountUpdate::Update { merchant_id: None, connector_type: Some(req.connector_type), diff --git a/crates/router/src/types/domain/merchant_account.rs b/crates/router/src/types/domain/merchant_account.rs index cbcd70aaef..3832ffb3da 100644 --- a/crates/router/src/types/domain/merchant_account.rs +++ b/crates/router/src/types/domain/merchant_account.rs @@ -79,6 +79,7 @@ pub enum MerchantAccountUpdate { recon_status: diesel_models::enums::ReconStatus, }, UnsetDefaultProfile, + ModifiedAtUpdate, } impl From for MerchantAccountUpdateInternal { @@ -140,6 +141,10 @@ impl From for MerchantAccountUpdateInternal { default_profile: Some(None), ..Default::default() }, + MerchantAccountUpdate::ModifiedAtUpdate => Self { + modified_at: Some(date_time::now()), + ..Default::default() + }, } } }