fix(router): add routing cache invalidation on payment connector update (#3132)

This commit is contained in:
Shanks
2023-12-14 16:51:34 +05:30
committed by GitHub
parent 70b86b71e4
commit 1f848659f1
3 changed files with 23 additions and 61 deletions

View File

@ -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"]

View File

@ -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),

View File

@ -79,6 +79,7 @@ pub enum MerchantAccountUpdate {
recon_status: diesel_models::enums::ReconStatus,
},
UnsetDefaultProfile,
ModifiedAtUpdate,
}
impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
@ -140,6 +141,10 @@ impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {
default_profile: Some(None),
..Default::default()
},
MerchantAccountUpdate::ModifiedAtUpdate => Self {
modified_at: Some(date_time::now()),
..Default::default()
},
}
}
}