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: Remove dynamo calls from HS code (#10530)

Sarthak Soni60102dd6cb54
diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rs
index 5aa30cc663..e33b860600 100644
--- a/crates/api_models/src/routing.rs
+++ b/crates/api_models/src/routing.rs
@@ -774,7 +774,6 @@ impl DynamicRoutingAlgorithmRef {
}
success_based_routing.enabled_feature
== DynamicRoutingFeatures::DynamicConnectorSelection
- || success_based_routing.enabled_feature == DynamicRoutingFeatures::Metrics
})
.unwrap_or_default()
}
@@ -792,7 +791,6 @@ impl DynamicRoutingAlgorithmRef {
}
elimination_routing.enabled_feature
== DynamicRoutingFeatures::DynamicConnectorSelection
- || elimination_routing.enabled_feature == DynamicRoutingFeatures::Metrics
})
.unwrap_or_default()
}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 77ec8d99e2..ba80da613f 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -10532,62 +10532,19 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to perform volume split on routing type")?;
- if routing_choice.routing_type.is_dynamic_routing() {
- if state.conf.open_router.dynamic_routing_enabled {
- routing::perform_dynamic_routing_with_open_router(
- state,
- connectors.clone(),
- business_profile,
- payment_attempt,
- payment_data,
- )
- .await
- .map_err(|e| logger::error!(open_routing_error=?e))
- .unwrap_or(connectors)
- } else {
- let dynamic_routing_config_params_interpolator =
- routing_helpers::DynamicRoutingConfigParamsInterpolator::new(
- payment_data.get_payment_attempt().payment_method,
- payment_data.get_payment_attempt().payment_method_type,
- payment_data.get_payment_attempt().authentication_type,
- payment_data.get_payment_attempt().currency,
- payment_data
- .get_billing_address()
- .and_then(|address| address.address)
- .and_then(|address| address.country),
- payment_data
- .get_payment_attempt()
- .payment_method_data
- .as_ref()
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card"))
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card_network"))
- .and_then(|network| network.as_str())
- .map(|network| network.to_string()),
- payment_data
- .get_payment_attempt()
- .payment_method_data
- .as_ref()
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card"))
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card_isin"))
- .and_then(|card_isin| card_isin.as_str())
- .map(|card_isin| card_isin.to_string()),
- );
-
- routing::perform_dynamic_routing_with_intelligent_router(
- state,
- connectors.clone(),
- business_profile,
- dynamic_routing_config_params_interpolator,
- payment_data,
- )
- .await
- .map_err(|e| logger::error!(dynamic_routing_error=?e))
- .unwrap_or(connectors)
- }
+ if routing_choice.routing_type.is_dynamic_routing()
+ && state.conf.open_router.dynamic_routing_enabled
+ {
+ routing::perform_dynamic_routing_with_open_router(
+ state,
+ connectors.clone(),
+ business_profile,
+ payment_attempt,
+ payment_data,
+ )
+ .await
+ .map_err(|e| logger::error!(open_routing_error=?e))
+ .unwrap_or(connectors)
} else {
connectors
}
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 3fb75da41d..38524ad26d 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1457,7 +1457,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
key_store: &domain::MerchantKeyStore,
storage_scheme: enums::MerchantStorageScheme,
locale: &Option<String>,
- #[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connectors: Vec<
+ #[cfg(all(feature = "v1", feature = "dynamic_routing"))] _routable_connectors: Vec<
RoutableConnectorChoice,
>,
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
@@ -2320,36 +2320,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
let state = state.clone();
let profile_id = business_profile.get_id().to_owned();
let payment_attempt = payment_attempt.clone();
- let dynamic_routing_config_params_interpolator =
- routing_helpers::DynamicRoutingConfigParamsInterpolator::new(
- payment_attempt.payment_method,
- payment_attempt.payment_method_type,
- payment_attempt.authentication_type,
- payment_attempt.currency,
- payment_data
- .address
- .get_payment_billing()
- .and_then(|address| address.clone().address)
- .and_then(|address| address.country),
- payment_attempt
- .payment_method_data
- .as_ref()
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card"))
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card_network"))
- .and_then(|network| network.as_str())
- .map(|network| network.to_string()),
- payment_attempt
- .payment_method_data
- .as_ref()
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card"))
- .and_then(|data| data.as_object())
- .and_then(|card| card.get("card_isin"))
- .and_then(|card_isin| card_isin.as_str())
- .map(|card_isin| card_isin.to_string()),
- );
+
tokio::spawn(
async move {
let should_route_to_open_router =
@@ -2370,47 +2341,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
.await
.map_err(|e| logger::error!(open_router_update_gateway_score_err=?e))
.ok();
- } else {
- routing_helpers::push_metrics_with_update_window_for_success_based_routing(
- &state,
- &payment_attempt,
- routable_connectors.clone(),
- &profile_id,
- dynamic_routing_algo_ref.clone(),
- dynamic_routing_config_params_interpolator.clone(),
- )
- .await
- .map_err(|e| logger::error!(success_based_routing_metrics_error=?e))
- .ok();
-
- if let Some(gsm_error_category) = gsm_error_category {
- if gsm_error_category.should_perform_elimination_routing() {
- logger::info!("Performing update window for elimination routing");
- routing_helpers::update_window_for_elimination_routing(
- &state,
- &payment_attempt,
- &profile_id,
- dynamic_routing_algo_ref.clone(),
- dynamic_routing_config_params_interpolator.clone(),
- gsm_error_category,
- )
- .await
- .map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
- .ok();
- };
- };
-
- routing_helpers::push_metrics_with_update_window_for_contract_based_routing(
- &state,
- &payment_attempt,
- routable_connectors,
- &profile_id,
- dynamic_routing_algo_ref,
- dynamic_routing_config_params_interpolator,
- )
- .await
- .map_err(|e| logger::error!(contract_based_routing_metrics_error=?e))
- .ok();
}
}
.in_current_span(),
diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs
index 35f9cdc754..fa04e142ac 100644
--- a/crates/router/src/core/routing.rs
+++ b/crates/router/src/core/routing.rs
@@ -1655,80 +1655,6 @@ pub async fn update_default_routing_config_for_profile(
))
}
-// Toggle the specific routing type as well as add the default configs in RoutingAlgorithm table
-// and update the same in business profile table.
-
-#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
-pub async fn toggle_specific_dynamic_routing(
- state: SessionState,
- platform: domain::Platform,
- feature_to_enable: routing::DynamicRoutingFeatures,
- profile_id: common_utils::id_type::ProfileId,
- dynamic_routing_type: routing::DynamicRoutingType,
-) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
- metrics::ROUTING_CREATE_REQUEST_RECEIVED.add(
- 1,
- router_env::metric_attributes!(
- ("profile_id", profile_id.clone()),
- ("algorithm_type", dynamic_routing_type.to_string())
- ),
- );
- let db = state.store.as_ref();
-
- let business_profile: domain::Profile = core_utils::validate_and_get_business_profile(
- db,
- platform.get_processor(),
- Some(&profile_id),
- )
- .await?
- .get_required_value("Profile")
- .change_context(errors::ApiErrorResponse::ProfileNotFound {
- id: profile_id.get_string_repr().to_owned(),
- })?;
-
- let dynamic_routing_algo_ref: routing_types::DynamicRoutingAlgorithmRef = business_profile
- .dynamic_routing_algorithm
- .clone()
- .map(|val| val.parse_value("DynamicRoutingAlgorithmRef"))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable(
- "unable to deserialize dynamic routing algorithm ref from business profile",
- )?
- .unwrap_or_default();
-
- match feature_to_enable {
- routing::DynamicRoutingFeatures::Metrics
- | routing::DynamicRoutingFeatures::DynamicConnectorSelection => {
- // occurs when algorithm is already present in the db
- // 1. If present with same feature then return response as already enabled
- // 2. Else update the feature and persist the same on db
- // 3. If not present in db then create a new default entry
- Box::pin(helpers::enable_dynamic_routing_algorithm(
- &state,
- platform.get_processor().get_key_store().clone(),
- business_profile,
- feature_to_enable,
- dynamic_routing_algo_ref,
- dynamic_routing_type,
- None,
- ))
- .await
- }
- routing::DynamicRoutingFeatures::None => {
- // disable specific dynamic routing for the requested profile
- helpers::disable_dynamic_routing_algorithm(
- &state,
- platform.get_processor().get_key_store().clone(),
- business_profile,
- dynamic_routing_algo_ref,
- dynamic_routing_type,
- )
- .await
- }
- }
-}
-
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
pub async fn create_specific_dynamic_routing(
state: SessionState,
@@ -1893,6 +1819,7 @@ pub async fn retrieve_dynamic_routing_volume_split(
Ok(service_api::ApplicationResponse::Json(resp))
}
+// check if this needs to stay
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
pub async fn success_based_routing_update_configs(
state: SessionState,
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 420bd58c6f..13bbfc3da2 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -2414,10 +2414,6 @@ impl Profile {
web::scope("/{profile_id}/dynamic_routing")
.service(
web::scope("/success_based")
- .service(
- web::resource("/toggle")
- .route(web::post().to(routing::toggle_success_based_routing)),
- )
.service(
web::resource("/create")
.route(web::post().to(routing::create_success_based_routing)),
@@ -2440,10 +2436,6 @@ impl Profile {
)
.service(
web::scope("/elimination")
- .service(
- web::resource("/toggle")
- .route(web::post().to(routing::toggle_elimination_routing)),
- )
.service(
web::resource("/create")
.route(web::post().to(routing::create_elimination_routing)),
diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs
index 5d82e8a1e7..ea7413c6de 100644
--- a/crates/router/src/routes/routing.rs
+++ b/crates/router/src/routes/routing.rs
@@ -1128,53 +1128,6 @@ pub async fn routing_update_default_config_for_profile(
.await
}
-#[cfg(all(feature = "olap", feature = "v1", feature = "dynamic_routing"))]
-#[instrument(skip_all)]
-pub async fn toggle_success_based_routing(
- state: web::Data<AppState>,
- req: HttpRequest,
- query: web::Query<api_models::routing::ToggleDynamicRoutingQuery>,
- path: web::Path<routing_types::ToggleDynamicRoutingPath>,
-) -> impl Responder {
- let flow = Flow::ToggleDynamicRouting;
- let wrapper = routing_types::ToggleDynamicRoutingWrapper {
- feature_to_enable: query.into_inner().enable,
- profile_id: path.into_inner().profile_id,
- };
- Box::pin(oss_api::server_wrap(
- flow,
- state,
- &req,
- wrapper.clone(),
- |state,
- auth: auth::AuthenticationData,
- wrapper: routing_types::ToggleDynamicRoutingWrapper,
- _| {
- let platform = auth.into();
- routing::toggle_specific_dynamic_routing(
- state,
- platform,
- wrapper.feature_to_enable,
- wrapper.profile_id,
- api_models::routing::DynamicRoutingType::SuccessRateBasedRouting,
- )
- },
- auth::auth_type(
- &auth::HeaderAuth(auth::ApiKeyAuth {
- is_connected_allowed: false,
- is_platform_allowed: false,
- }),
- &auth::JWTAuthProfileFromRoute {
- profile_id: wrapper.profile_id,
- required_permission: Permission::ProfileRoutingWrite,
- },
- req.headers(),
- ),
- api_locking::LockAction::NotApplicable,
- ))
- .await
-}
-
#[cfg(all(feature = "olap", feature = "v1", feature = "dynamic_routing"))]
#[instrument(skip_all)]
pub async fn create_success_based_routing(
@@ -1416,53 +1369,6 @@ pub async fn contract_based_routing_update_configs(
.await
}
-#[cfg(all(feature = "olap", feature = "v1", feature = "dynamic_routing"))]
-#[instrument(skip_all)]
-pub async fn toggle_elimination_routing(
- state: web::Data<AppState>,
- req: HttpRequest,
- query: web::Query<api_models::routing::ToggleDynamicRoutingQuery>,
- path: web::Path<routing_types::ToggleDynamicRoutingPath>,
-) -> impl Responder {
- let flow = Flow::ToggleDynamicRouting;
- let wrapper = routing_types::ToggleDynamicRoutingWrapper {
- feature_to_enable: query.into_inner().enable,
- profile_id: path.into_inner().profile_id,
- };
- Box::pin(oss_api::server_wrap(
- flow,
- state,
- &req,
- wrapper.clone(),
- |state,
- auth: auth::AuthenticationData,
- wrapper: routing_types::ToggleDynamicRoutingWrapper,
- _| {
- let platform = auth.into();
- routing::toggle_specific_dynamic_routing(
- state,
- platform,
- wrapper.feature_to_enable,
- wrapper.profile_id,
- api_models::routing::DynamicRoutingType::EliminationRouting,
- )
- },
- auth::auth_type(
- &auth::HeaderAuth(auth::ApiKeyAuth {
- is_connected_allowed: false,
- is_platform_allowed: false,
- }),
- &auth::JWTAuthProfileFromRoute {
- profile_id: wrapper.profile_id,
- required_permission: Permission::ProfileRoutingWrite,
- },
- req.headers(),
- ),
- api_locking::LockAction::NotApplicable,
- ))
- .await
-}
-
#[cfg(all(feature = "olap", feature = "v1", feature = "dynamic_routing"))]
#[instrument(skip_all)]
pub async fn create_elimination_routing(