From e8b28d1d64f8c91996bbdfe83bd1c3d708372e6e Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 19 Dec 2024 20:16:49 +0530 Subject: [PATCH 1/5] refactor(dynamic_routing): perform db operations only when payments are in terminal state --- crates/common_enums/src/enums.rs | 15 +++++++++++++++ .../core/payments/operations/payment_response.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 5aac1a07457b..4387926a8923 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1305,6 +1305,21 @@ pub enum IntentStatus { impl IntentStatus { /// Indicates whether the syncing with the connector should be allowed or not + pub fn is_in_terminal_state(self) -> bool { + match self { + Self::Succeeded + | Self::Failed + | Self::PartiallyCaptured => true, + Self::Cancelled + | Self::Processing + | Self::RequiresCustomerAction + | Self::RequiresMerchantAction + | Self::RequiresPaymentMethod + | Self::RequiresConfirmation + | Self::RequiresCapture + | Self::PartiallyCapturedAndCapturable => false, + } + } pub fn should_force_sync_with_connector(self) -> bool { match self { // Confirm has not happened yet diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 01a4e0860918..3a98b5ce3f6a 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1969,7 +1969,7 @@ async fn payment_response_update_tracker( #[cfg(all(feature = "v1", feature = "dynamic_routing"))] { - if business_profile.dynamic_routing_algorithm.is_some() { + if payment_intent.status.is_in_terminal_state() && business_profile.dynamic_routing_algorithm.is_some() { let state = state.clone(); let business_profile = business_profile.clone(); let payment_attempt = payment_attempt.clone(); From d530c11316146273eb7149515e964ef3b5971bd9 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:49:11 +0000 Subject: [PATCH 2/5] chore: run formatter --- crates/common_enums/src/enums.rs | 4 +--- .../router/src/core/payments/operations/payment_response.rs | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 4387926a8923..6884ccee3e93 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1307,9 +1307,7 @@ impl IntentStatus { /// Indicates whether the syncing with the connector should be allowed or not pub fn is_in_terminal_state(self) -> bool { match self { - Self::Succeeded - | Self::Failed - | Self::PartiallyCaptured => true, + Self::Succeeded | Self::Failed | Self::PartiallyCaptured => true, Self::Cancelled | Self::Processing | Self::RequiresCustomerAction diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 3a98b5ce3f6a..cbf8e22589ef 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1969,7 +1969,9 @@ async fn payment_response_update_tracker( #[cfg(all(feature = "v1", feature = "dynamic_routing"))] { - if payment_intent.status.is_in_terminal_state() && business_profile.dynamic_routing_algorithm.is_some() { + if payment_intent.status.is_in_terminal_state() + && business_profile.dynamic_routing_algorithm.is_some() + { let state = state.clone(); let business_profile = business_profile.clone(); let payment_attempt = payment_attempt.clone(); From a408d7fe87e9a41a9f6869a77cff5a27db670efe Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Mon, 23 Dec 2024 18:45:17 +0530 Subject: [PATCH 3/5] address comments --- crates/common_enums/src/enums.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 6884ccee3e93..787f49af816b 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1304,12 +1304,13 @@ pub enum IntentStatus { } impl IntentStatus { - /// Indicates whether the syncing with the connector should be allowed or not pub fn is_in_terminal_state(self) -> bool { match self { - Self::Succeeded | Self::Failed | Self::PartiallyCaptured => true, - Self::Cancelled - | Self::Processing + Self::Succeeded | + Self::Failed | + Self::Cancelled | + Self::PartiallyCaptured => true, + Self::Processing | Self::RequiresCustomerAction | Self::RequiresMerchantAction | Self::RequiresPaymentMethod From fa9df1b30123714f10626ad687f9c46b57a59323 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:19:49 +0000 Subject: [PATCH 4/5] chore: run formatter --- crates/common_enums/src/enums.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 787f49af816b..30169ba854e8 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1306,10 +1306,7 @@ pub enum IntentStatus { impl IntentStatus { pub fn is_in_terminal_state(self) -> bool { match self { - Self::Succeeded | - Self::Failed | - Self::Cancelled | - Self::PartiallyCaptured => true, + Self::Succeeded | Self::Failed | Self::Cancelled | Self::PartiallyCaptured => true, Self::Processing | Self::RequiresCustomerAction | Self::RequiresMerchantAction From 74075323a9b37d578b857c28ca7f1e7828ee7e05 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Mon, 23 Dec 2024 19:01:34 +0530 Subject: [PATCH 5/5] address comments --- crates/common_enums/src/enums.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 787f49af816b..e77e725468f3 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1304,6 +1304,7 @@ pub enum IntentStatus { } impl IntentStatus { + /// Indicates whether the payment intent is in terminal state or not pub fn is_in_terminal_state(self) -> bool { match self { Self::Succeeded | @@ -1319,6 +1320,8 @@ impl IntentStatus { | Self::PartiallyCapturedAndCapturable => false, } } + + /// Indicates whether the syncing with the connector should be allowed or not pub fn should_force_sync_with_connector(self) -> bool { match self { // Confirm has not happened yet