-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(router): fix retry_count and add validation for process_tracker #7614
base: main
Are you sure you want to change the base?
Conversation
Changed Files
|
…ttempt ID handling
@@ -811,9 +811,9 @@ where | |||
total_retry_count: revenue_recovery | |||
.as_ref() | |||
.map_or(1, |data| (data.total_retry_count + 1)), | |||
// Since this is an external system call, marking this payment_connector_transmission to ConnectorCallSucceeded. | |||
// Since this is an external system call, marking this payment_connector_transmission to ConnectorCallUnsucceeded. | |||
payment_connector_transmission: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed can you make this an Optional field and have ConnectorCallUnsucceeded
as the default value
@@ -266,7 +266,7 @@ impl ApiModelToDieselModelConvertor<ApiRevenueRecoveryMetadata> for PaymentReven | |||
fn convert_from(from: ApiRevenueRecoveryMetadata) -> Self { | |||
Self { | |||
total_retry_count: from.total_retry_count, | |||
payment_connector_transmission: from.payment_connector_transmission, | |||
payment_connector_transmission: Some(from.payment_connector_transmission.unwrap_or_default()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the unwrap_or_default
here
@@ -281,7 +281,7 @@ impl ApiModelToDieselModelConvertor<ApiRevenueRecoveryMetadata> for PaymentReven | |||
fn convert_back(self) -> ApiRevenueRecoveryMetadata { | |||
ApiRevenueRecoveryMetadata { | |||
total_retry_count: self.total_retry_count, | |||
payment_connector_transmission: self.payment_connector_transmission, | |||
payment_connector_transmission: Some(self.payment_connector_transmission.unwrap_or_default()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/api_models/src/payments.rs
Outdated
@@ -1586,6 +1586,21 @@ pub struct PaymentAttemptResponse { | |||
pub feature_metadata: Option<PaymentAttemptFeatureMetadata>, | |||
} | |||
|
|||
#[cfg(feature = "v2")] | |||
#[derive(Debug, serde::Serialize, Clone, ToSchema)] | |||
pub struct PaymentRecordResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct PaymentRecordResponse { | |
pub struct PaymentsAttemptRecordRequest { |
#[serde(rename = "snake_case")] | ||
pub enum PaymentConnectorTransmission { | ||
/// Failed to call the payment connector | ||
#[default] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this field as optional when we are already using this field as optional value ?
// Since its an Error from the connector we should set it as connectors's set status or Failure by default | ||
let attempt_status = attempt_status.unwrap_or(common_enums::AttemptStatus::Failure); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to make it failure ? If connector doesn't update the status let it be the previous status. This might update it Psync process tracker right ?
fn foreign_from(feature_metadata: &diesel_models::types::FeatureMetadata) -> Self { | ||
let revenue_recovery = feature_metadata | ||
.payment_revenue_recovery_metadata | ||
.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we pass this by reference ?
let revenue_recovery = feature_metadata | ||
.payment_revenue_recovery_metadata | ||
.clone() | ||
.map(|r| api_models::payments::PaymentRevenueRecoveryMetadata { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid single letter variable names.
.as_ref() | ||
.and_then(|metadata| metadata.get_retry_count()) | ||
}) | ||
.unwrap_or(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are supposed to get retry count at this point we better throw an error instead of setting the value to 0
if intent_retry_count <= mca_retry_threshold { | ||
router_env::logger::error!( | ||
"Payment retry count {} is less than threshold {}", | ||
intent_retry_count, | ||
mca_retry_threshold | ||
); | ||
return Ok(webhooks::WebhookResponseTracker::NoEffect); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have this logic inside ScheduleFailedPayment and also use when
instead of if
Option<( | ||
revenue_recovery::RecoveryPaymentAttempt, | ||
revenue_recovery::RecoveryPaymentIntent, | ||
)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having the return type as Option<(Attempt,Intent)> can we make this to <(Option, intent)> ?
@@ -326,7 +363,9 @@ impl RevenueRecoveryAttempt { | |||
attempt_status: attempt_res.status.to_owned(), | |||
feature_metadata: attempt_res.feature_metadata.to_owned(), | |||
}); | |||
Ok(payment_attempt) | |||
// If we have an attempt, combine it with payment_intent in a tuple. | |||
let combined = payment_attempt.map(|attempt| (attempt, (*payment_intent).clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use better variable names here ?
Type of Change
Description
This PR will fix the bug where the
retry_count
was stuck at 0 and will add validation for entry inprocess_tracker
only whenpayment_retry_count
exceeds thebilling_connector_retry_threshold
.Additional Changes
Motivation and Context
Earlier the retry_count was stuck at 0 and was not increasing, since updated payment intent was not being passing, which i have fixed in this PR
How did you test it?
tested it from stripe dashboard

Checklist
cargo +nightly fmt --all
cargo clippy