Skip to content

feat(gRPC): build gRPC client interface to initiate communication with recovery-decider service #8178

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

Merged
merged 150 commits into from
Aug 6, 2025

Conversation

AdityaKumaar21
Copy link
Contributor

@AdityaKumaar21 AdityaKumaar21 commented May 29, 2025

Type of Change

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

Description

I have implemented a gRPC client that facilitates communication with the recovery-decider gRPC service. The client should be capable of initializing and managing the connection to the service, sending requests, and handling responses in accordance with the defined service contract (protobuf definitions).

Additional Changes

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

Motivation and Context

How did you test it?

Decider gRPC server:-
Screenshot 2025-06-11 at 01 16 34

Decider gRPC client(HS):-
Screenshot 2025-06-05 at 02 05 20

Predictor gRPC server:-
Screenshot 2025-06-05 at 02 03 06

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

Summary by CodeRabbit

  • New Features

    • Introduced support for a gRPC client: Recovery Decider, enabling external retry decisioning.
    • Integrated dynamic scheduling for smart retry logic based on external gRPC service responses.
    • Added new protobuf definition for Recovery Decider.
  • Improvements

    • Enhanced revenue recovery payment flow with richer payment intent context and smarter retry scheduling.
    • Expanded logging and API flow tracking with new flow types.
  • Configuration

    • Added configuration options for new gRPC clients in the development environment.
  • Bug Fixes

    • Improved error handling and logging for gRPC client interactions.

Nishanth Challa and others added 30 commits April 2, 2025 14:06
@AdityaKumaar21 AdityaKumaar21 requested review from a team August 5, 2025 06:37
Comment on lines +239 to +243
logger::debug!(
payment_intent_id = ?payment_intent.get_id(),
attempt_id = ?payment_attempt.get_id(),
message = "payment_attempt.payment_method_data is None"
);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: You don't have to explicitly pass the message field.

Suggested change
logger::debug!(
payment_intent_id = ?payment_intent.get_id(),
attempt_id = ?payment_attempt.get_id(),
message = "payment_attempt.payment_method_data is None"
);
logger::debug!(
payment_intent_id = ?payment_intent.get_id(),
attempt_id = ?payment_attempt.get_id(),
"payment_attempt.payment_method_data is None"
);


let card_network_str = billing_connector_payment_method_details
.and_then(|details| match details {
BillingConnectorPaymentMethodDetails::Card(card_info) => card_info.card_network.clone(),
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can't we avoid the clone here? I think you should be able to, by deriving Copy on the common_enums::enums::CardNetwork enum.

BillingConnectorPaymentMethodDetails::Card(card_info) => card_info.card_issuer.clone(),
})?;

let card_funding_str = payment_intent
Copy link
Member

Choose a reason for hiding this comment

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

Card funding? Where are we obtaining this information from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically card type that we are fetching from payment intent's PaymentRevenueRecoveryMetadata-> payment_method_subtype

Copy link
Member

Choose a reason for hiding this comment

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

Why the "funding" in the variable name?

fn from(internal_request: InternalDeciderRequest) -> Self {
Self {
first_error_message: internal_request.first_error_message,
billing_state: internal_request.billing_state.peek().to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

@Aprabhat19 @srujanchikke Ideally you folks should consider using an equivalent of Secret on the gRPC server side as well, similar to how the connector-service folks are doing...

[billing_connectors_invoice_sync]
billing_connectors_which_requires_invoice_sync_call = "recurly" # List of billing connectors which has invoice sync api call

[revenue_recovery]
monitoring_threshold_in_seconds = 2592000 # 30*24*60*60 secs , threshold for monitoring the retry system
retry_algorithm_type = "cascading" # type of retry algorithm
monitoring_threshold_in_seconds = 60 # 30*24*60*60 secs , threshold for monitoring the retry system
Copy link
Member

Choose a reason for hiding this comment

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

The number and the comment don't match?

[billing_connectors_invoice_sync]
billing_connectors_which_requires_invoice_sync_call = "recurly" # List of billing connectors which has invoice sync api call

[revenue_recovery]
monitoring_threshold_in_seconds = 2592000 # 30*24*60*60 secs , threshold for monitoring the retry system
retry_algorithm_type = "cascading" # type of retry algorithm
monitoring_threshold_in_seconds = 60 # 30*24*60*60 secs , threshold for monitoring the retry system
Copy link
Member

Choose a reason for hiding this comment

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

The number (60) and the comment don't match?

);

logger::info!("Recovery Decider gRPC client successfully initialized");
// Some(Box::new(client) as Box<dyn RecoveryDeciderClientInterface>)
Copy link
Member

Choose a reason for hiding this comment

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

Remove commented code.

@@ -97,7 +99,7 @@ impl RevenueRecoveryPaymentsAttemptStatus {
payment_intent: &PaymentIntent,
process_tracker: storage::ProcessTracker,
revenue_recovery_payment_data: &storage::revenue_recovery::RevenueRecoveryPaymentData,
payment_attempt: payment_attempt::PaymentAttempt,
payment_attempt: PaymentAttempt,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can't we accept a reference here? Do you necessarily need an owned value?

process: &storage::ProcessTracker,
payment_attempt: payment_attempt::PaymentAttempt,
payment_attempt: PaymentAttempt,
Copy link
Member

Choose a reason for hiding this comment

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

Same here, can't we accept a reference?


#[derive(Debug, serde::Deserialize, Clone)]
pub struct RecoveryTimestamp {
pub initial_timestamp_in_hours: i64,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need an i64, can't we use something like u16 or u32? This is anyway a duration, we don't need these to be negative.

}
}
}
}

#[derive(Debug, serde::Deserialize, Clone, Default)]
pub struct RevenueRecoverySettings {
pub monitoring_threshold_in_seconds: i64,
Copy link
Member

Choose a reason for hiding this comment

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

Same here, we don't need an i64?

Copy link
Contributor

@hrithikesh026 hrithikesh026 left a comment

Choose a reason for hiding this comment

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

Core changes LGTM

@likhinbopanna likhinbopanna added this pull request to the merge queue Aug 6, 2025
Merged via the queue into main with commit 654c15e Aug 6, 2025
18 of 22 checks passed
@likhinbopanna likhinbopanna deleted the build-grpc-client-recovery branch August 6, 2025 13:44
pixincreate added a commit that referenced this pull request Aug 7, 2025
…ordea-sepa

* 'main' of github.com:juspay/hyperswitch:
  fix(router): [worldpayvantiv] dispute validations and statuses (#8862)
  chore(version): 2025.08.07.0
  feat(connector): [WORLDPAYVANTIV] Populate Network Decline Error Code & Message (#8856)
  feat(router): add support for partial authorization (#8833)
  feat(gRPC): build gRPC client interface to initiate communication with recovery-decider service (#8178)
  fix(connector): [CYBERSOURCE] fix response field for netcetera authentication response (#8850)
  chore(events): making events nanosecond level precision (#8759)
@hyperswitch-bot hyperswitch-bot bot removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE]: build gRPC Client Interface to initiate communication with recovery-trainer gRPC service
8 participants