Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dynamic_routing): perform db operations for dynamic_routing_stats table only when payments are in terminal state #6900

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
14 changes: 14 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,20 @@ pub enum IntentStatus {
}

impl IntentStatus {
/// Indicates whether the payment intent is in terminal state or not
pub fn is_in_terminal_state(self) -> bool {
prajjwalkumar17 marked this conversation as resolved.
Show resolved Hide resolved
match self {
Self::Succeeded | Self::Failed | Self::Cancelled | Self::PartiallyCaptured => true,
Self::Processing
| Self::RequiresCustomerAction
| Self::RequiresMerchantAction
| Self::RequiresPaymentMethod
| Self::RequiresConfirmation
| Self::RequiresCapture
| 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,9 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(

#[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();
Expand Down
Loading