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

feat(router): add profile level auto retries config support (#6200)

Sai Harsha Vardhan56489771e403
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 769619d951..d7899e8b9a 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -440,14 +440,17 @@ where
)
.await?;
- #[cfg(feature = "retry")]
+ #[cfg(all(feature = "retry", feature = "v1"))]
let mut router_data = router_data;
- #[cfg(feature = "retry")]
+ #[cfg(all(feature = "retry", feature = "v1"))]
{
use crate::core::payments::retry::{self, GsmValidation};
- let config_bool =
- retry::config_should_call_gsm(&*state.store, merchant_account.get_id())
- .await;
+ let config_bool = retry::config_should_call_gsm(
+ &*state.store,
+ merchant_account.get_id(),
+ &business_profile,
+ )
+ .await;
if config_bool && router_data.should_call_gsm() {
router_data = retry::do_gsm_actions(
@@ -3762,8 +3765,12 @@ where
}
#[cfg(feature = "retry")]
- let should_do_retry =
- retry::config_should_call_gsm(&*state.store, merchant_account.get_id()).await;
+ let should_do_retry = retry::config_should_call_gsm(
+ &*state.store,
+ merchant_account.get_id(),
+ business_profile,
+ )
+ .await;
#[cfg(feature = "retry")]
if payment_data.get_payment_attempt().payment_method_type
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index b69c1ebf91..c3c4a6d01a 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -29,6 +29,7 @@ use crate::{
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
+#[cfg(feature = "v1")]
pub async fn do_gsm_actions<F, ApiRequest, FData, D>(
state: &app::SessionState,
req_state: ReqState,
@@ -114,7 +115,9 @@ where
match get_gsm_decision(gsm) {
api_models::gsm::GsmDecision::Retry => {
- retries = get_retries(state, retries, merchant_account.get_id()).await;
+ retries =
+ get_retries(state, retries, merchant_account.get_id(), business_profile)
+ .await;
if retries.is_none() || retries == Some(0) {
metrics::AUTO_RETRY_EXHAUSTED_COUNT.add(&metrics::CONTEXT, 1, &[]);
@@ -190,34 +193,43 @@ pub async fn is_step_up_enabled_for_merchant_connector(
.unwrap_or(false)
}
+#[cfg(feature = "v1")]
+pub async fn get_merchant_max_auto_retries_enabled(
+ db: &dyn StorageInterface,
+ merchant_id: &common_utils::id_type::MerchantId,
+) -> Option<i32> {
+ let key = merchant_id.get_max_auto_retries_enabled();
+
+ db.find_config_by_key(key.as_str())
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .and_then(|retries_config| {
+ retries_config
+ .config
+ .parse::<i32>()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Retries config parsing failed")
+ })
+ .map_err(|err| {
+ logger::error!(retries_error=?err);
+ None::<i32>
+ })
+ .ok()
+}
+
+#[cfg(feature = "v1")]
#[instrument(skip_all)]
pub async fn get_retries(
state: &app::SessionState,
retries: Option<i32>,
merchant_id: &common_utils::id_type::MerchantId,
+ profile: &domain::Profile,
) -> Option<i32> {
match retries {
Some(retries) => Some(retries),
- None => {
- let key = merchant_id.get_max_auto_retries_enabled();
-
- let db = &*state.store;
- db.find_config_by_key(key.as_str())
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .and_then(|retries_config| {
- retries_config
- .config
- .parse::<i32>()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Retries config parsing failed")
- })
- .map_err(|err| {
- logger::error!(retries_error=?err);
- None::<i32>
- })
- .ok()
- }
+ None => get_merchant_max_auto_retries_enabled(state.store.as_ref(), merchant_id)
+ .await
+ .or(profile.max_auto_retries_enabled.map(i32::from)),
}
}
@@ -649,7 +661,8 @@ pub fn make_new_payment_attempt(
todo!()
}
-pub async fn config_should_call_gsm(
+#[cfg(feature = "v1")]
+pub async fn get_merchant_config_for_gsm(
db: &dyn StorageInterface,
merchant_id: &common_utils::id_type::MerchantId,
) -> bool {
@@ -668,6 +681,17 @@ pub async fn config_should_call_gsm(
}
}
+#[cfg(feature = "v1")]
+pub async fn config_should_call_gsm(
+ db: &dyn StorageInterface,
+ merchant_id: &common_utils::id_type::MerchantId,
+ profile: &domain::Profile,
+) -> bool {
+ let merchant_config_gsm = get_merchant_config_for_gsm(db, merchant_id).await;
+ let profile_config_gsm = profile.is_auto_retries_enabled;
+ merchant_config_gsm || profile_config_gsm
+}
+
pub trait GsmValidation<F: Send + Clone + Sync, FData: Send + Sync, Resp> {
// TODO : move this function to appropriate place later.
fn should_call_gsm(&self) -> bool;