Skip to content

Commit 9547759

Browse files
address comments
1 parent 3df307d commit 9547759

File tree

7 files changed

+108
-94
lines changed

7 files changed

+108
-94
lines changed

crates/router/src/core/payments.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ use self::{
6363
operations::{BoxedOperation, Operation, PaymentResponse},
6464
routing::{self as self_routing, SessionFlowRoutingInput},
6565
};
66-
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
67-
use super::routing::helpers::fetch_success_based_routing_configs;
6866
use super::{
6967
errors::StorageErrorExt, payment_methods::surcharge_decision_configs, routing::TransactionData,
7068
};
@@ -370,6 +368,8 @@ where
370368
&locale,
371369
#[cfg(all(feature = "dynamic_routing", feature = "v1"))]
372370
routable_connectors,
371+
#[cfg(all(feature = "dynamic_routing", feature = "v1"))]
372+
&business_profile,
373373
)
374374
.await?;
375375

@@ -503,6 +503,8 @@ where
503503
&locale,
504504
#[cfg(all(feature = "dynamic_routing", feature = "v1"))]
505505
routable_connectors,
506+
#[cfg(all(feature = "dynamic_routing", feature = "v1"))]
507+
&business_profile,
506508
)
507509
.await?;
508510

@@ -4508,13 +4510,6 @@ where
45084510
.change_context(errors::ApiErrorResponse::InternalServerError)
45094511
.attach_printable("failed eligibility analysis and fallback")?;
45104512

4511-
// Fetch and cache default config for success based routing
4512-
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
4513-
fetch_success_based_routing_configs(state, business_profile)
4514-
.await
4515-
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
4516-
.ok();
4517-
45184513
let connector_data = connectors
45194514
.into_iter()
45204515
.map(|conn| {

crates/router/src/core/payments/operations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ pub trait PostUpdateTracker<F, D, R: Send>: Send {
268268
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
269269
RoutableConnectorChoice,
270270
>,
271+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
271272
) -> RouterResult<D>
272273
where
273274
F: 'b + Send + Sync;

crates/router/src/core/payments/operations/payment_response.rs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
7979
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
8080
RoutableConnectorChoice,
8181
>,
82+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
8283
) -> RouterResult<PaymentData<F>>
8384
where
8485
F: 'b,
@@ -97,6 +98,8 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
9798
locale,
9899
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
99100
routable_connector,
101+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
102+
business_profile,
100103
))
101104
.await?;
102105

@@ -357,6 +360,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsIncrementalAu
357360
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] _routable_connector: Vec<
358361
RoutableConnectorChoice,
359362
>,
363+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
364+
_business_profile: &domain::Profile,
360365
) -> RouterResult<PaymentData<F>>
361366
where
362367
F: 'b + Send,
@@ -511,6 +516,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
511516
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
512517
RoutableConnectorChoice,
513518
>,
519+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
514520
) -> RouterResult<PaymentData<F>>
515521
where
516522
F: 'b + Send,
@@ -525,6 +531,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSyncData> for
525531
locale,
526532
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
527533
routable_connector,
534+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
535+
business_profile,
528536
))
529537
.await
530538
}
@@ -572,6 +580,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSessionData>
572580
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
573581
RoutableConnectorChoice,
574582
>,
583+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
575584
) -> RouterResult<PaymentData<F>>
576585
where
577586
F: 'b + Send,
@@ -586,6 +595,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsSessionData>
586595
locale,
587596
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
588597
routable_connector,
598+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
599+
business_profile,
589600
))
590601
.await?;
591602

@@ -614,6 +625,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SdkPaymentsSessionUpd
614625
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] _routable_connector: Vec<
615626
RoutableConnectorChoice,
616627
>,
628+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
629+
_business_profile: &domain::Profile,
617630
) -> RouterResult<PaymentData<F>>
618631
where
619632
F: 'b + Send,
@@ -687,6 +700,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCaptureData>
687700
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
688701
RoutableConnectorChoice,
689702
>,
703+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
690704
) -> RouterResult<PaymentData<F>>
691705
where
692706
F: 'b + Send,
@@ -701,6 +715,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCaptureData>
701715
locale,
702716
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
703717
routable_connector,
718+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
719+
business_profile,
704720
))
705721
.await?;
706722

@@ -723,6 +739,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCancelData> f
723739
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
724740
RoutableConnectorChoice,
725741
>,
742+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
726743
) -> RouterResult<PaymentData<F>>
727744
where
728745
F: 'b + Send,
@@ -737,6 +754,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsCancelData> f
737754
locale,
738755
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
739756
routable_connector,
757+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
758+
business_profile,
740759
))
741760
.await?;
742761

@@ -761,6 +780,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsApproveData>
761780
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
762781
RoutableConnectorChoice,
763782
>,
783+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
764784
) -> RouterResult<PaymentData<F>>
765785
where
766786
F: 'b + Send,
@@ -775,6 +795,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsApproveData>
775795
locale,
776796
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
777797
routable_connector,
798+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
799+
business_profile,
778800
))
779801
.await?;
780802

@@ -797,6 +819,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRejectData> f
797819
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
798820
RoutableConnectorChoice,
799821
>,
822+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
800823
) -> RouterResult<PaymentData<F>>
801824
where
802825
F: 'b + Send,
@@ -811,6 +834,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsRejectData> f
811834
locale,
812835
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
813836
routable_connector,
837+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
838+
business_profile,
814839
))
815840
.await?;
816841

@@ -839,6 +864,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
839864
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
840865
RoutableConnectorChoice,
841866
>,
867+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
842868
) -> RouterResult<PaymentData<F>>
843869
where
844870
F: 'b + Send,
@@ -858,6 +884,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::SetupMandateRequestDa
858884
locale,
859885
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
860886
routable_connector,
887+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
888+
business_profile,
861889
))
862890
.await?;
863891

@@ -947,6 +975,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
947975
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connector: Vec<
948976
RoutableConnectorChoice,
949977
>,
978+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
950979
) -> RouterResult<PaymentData<F>>
951980
where
952981
F: 'b + Send,
@@ -961,6 +990,8 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::CompleteAuthorizeData
961990
locale,
962991
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
963992
routable_connector,
993+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
994+
business_profile,
964995
))
965996
.await
966997
}
@@ -1019,6 +1050,7 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
10191050
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] routable_connectors: Vec<
10201051
RoutableConnectorChoice,
10211052
>,
1053+
#[cfg(all(feature = "v1", feature = "dynamic_routing"))] business_profile: &domain::Profile,
10221054
) -> RouterResult<PaymentData<F>> {
10231055
// Update additional payment data with the payment method response that we received from connector
10241056

@@ -1677,11 +1709,25 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
16771709
)?;
16781710

16791711
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
1680-
push_metrics_for_success_based_routing(state, key_store, &payment_attempt, routable_connectors)
1681-
.await
1682-
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
1683-
.ok();
1684-
1712+
{
1713+
let state = state.clone();
1714+
let business_profile = business_profile.clone();
1715+
let payment_attempt = payment_attempt.clone();
1716+
tokio::spawn(
1717+
async move {
1718+
push_metrics_for_success_based_routing(
1719+
&state,
1720+
&payment_attempt,
1721+
routable_connectors,
1722+
&business_profile,
1723+
)
1724+
.await
1725+
.map_err(|e| logger::error!(dynamic_routing_metrics_error=?e))
1726+
.ok();
1727+
}
1728+
.in_current_span(),
1729+
);
1730+
}
16851731
payment_data.payment_intent = payment_intent;
16861732
payment_data.payment_attempt = payment_attempt;
16871733
router_data.payment_method_status.and_then(|status| {

crates/router/src/core/routing.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ use error_stack::ResultExt;
1010
use hyperswitch_domain_models::{mandates, payment_address};
1111
use router_env::metrics::add_attributes;
1212
use rustc_hash::FxHashSet;
13-
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
14-
use storage_impl::redis::cache::{self, CacheKind};
13+
#[cfg(feature = "v1")]
14+
use storage_impl::redis::cache;
1515

16-
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
17-
use self::helpers::refresh_success_based_routing_cache;
1816
#[cfg(feature = "payouts")]
1917
use super::payouts;
2018
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
@@ -1339,24 +1337,21 @@ pub async fn success_based_routing_update_configs(
13391337
.change_context(errors::ApiErrorResponse::InternalServerError)
13401338
.attach_printable("Unable to insert record in routing algorithm table")?;
13411339

1342-
// remove and refresh cache for success based routing configs
1343-
#[cfg(all(feature = "v1", feature = "dynamic_routing"))]
1344-
{
1345-
let cache_key = format!(
1346-
"{}_{}",
1347-
profile_id.get_string_repr().to_owned(),
1348-
algorithm_id.get_string_repr()
1349-
);
1350-
let cache_to_redact = vec![CacheKind::SuccessBasedDynamicRoutingCache(
1351-
cache_key.clone().into(),
1352-
)];
1353-
let _ = cache::publish_into_redact_channel(db.get_cache_store().as_ref(), cache_to_redact)
1354-
.await
1355-
.map_err(|e| {
1356-
logger::error!("unable to redact the success based routing config cache {e}")
1357-
});
1358-
refresh_success_based_routing_cache(&state, cache_key.as_str(), config_to_update).await;
1359-
}
1340+
// refresh cache for success based routing configs
1341+
let cache_key = format!(
1342+
"{}_{}",
1343+
profile_id.get_string_repr(),
1344+
algorithm_id.get_string_repr()
1345+
);
1346+
let cache_entries_to_redact = vec![cache::CacheKind::SuccessBasedDynamicRoutingCache(
1347+
cache_key.into(),
1348+
)];
1349+
let _ = cache::publish_into_redact_channel(
1350+
state.store.get_cache_store().as_ref(),
1351+
cache_entries_to_redact,
1352+
)
1353+
.await
1354+
.map_err(|e| logger::error!("unable to redact the success based routing config cache {e:?}"));
13601355

13611356
let new_record = record.foreign_into();
13621357

0 commit comments

Comments
 (0)