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

fix(router): fix retry_count and add validation for process_tracker #7614

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

AdityaKumaar21
Copy link
Contributor

@AdityaKumaar21 AdityaKumaar21 commented Mar 25, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This PR will fix the bug where the retry_count was stuck at 0 and will add validation for entry in process_tracker only when payment_retry_count exceeds the billing_connector_retry_threshold.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

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
Screenshot 2025-03-25 at 19 18 08

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@AdityaKumaar21 AdityaKumaar21 requested review from a team as code owners March 25, 2025 06:33
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 25, 2025
@AdityaKumaar21 AdityaKumaar21 added the C-bug Category: Bug label Mar 25, 2025
@AdityaKumaar21 AdityaKumaar21 self-assigned this Mar 25, 2025
@AdityaKumaar21 AdityaKumaar21 added C-feature Category: Feature request or enhancement enhancement New feature or request and removed M-api-contract-changes Metadata: This PR involves API contract changes C-feature Category: Feature request or enhancement labels Mar 25, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 25, 2025
@@ -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:
Copy link
Contributor

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

@juspay juspay deleted a comment from Aprabhat19 Mar 26, 2025
@@ -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()),
Copy link
Contributor

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()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -1586,6 +1586,21 @@ pub struct PaymentAttemptResponse {
pub feature_metadata: Option<PaymentAttemptFeatureMetadata>,
}

#[cfg(feature = "v2")]
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
pub struct PaymentRecordResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct PaymentRecordResponse {
pub struct PaymentsAttemptRecordRequest {

#[serde(rename = "snake_case")]
pub enum PaymentConnectorTransmission {
/// Failed to call the payment connector
#[default]
Copy link
Contributor

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 ?

Comment on lines +628 to +629
// 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);
Copy link
Contributor

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()
Copy link
Contributor

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 {
Copy link
Contributor

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);
Copy link
Contributor

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

Comment on lines 154 to 162
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);
}

Copy link
Contributor

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

Comment on lines +316 to +319
Option<(
revenue_recovery::RecoveryPaymentAttempt,
revenue_recovery::RecoveryPaymentIntent,
)>,
Copy link
Contributor

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()));
Copy link
Contributor

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Bug enhancement New feature or request M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants