-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(revenue_recovery): get recovery list and get recovery intent response missing values fix #10508
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2727,10 +2727,38 @@ pub async fn revenue_recovery_get_intent_core( | |||||
| 0 | ||||||
| }; | ||||||
|
|
||||||
| let payment_attempt = state | ||||||
| .store | ||||||
| .find_payment_attempts_by_payment_intent_id( | ||||||
| &payment_intent.id, | ||||||
| platform.get_processor().get_key_store(), | ||||||
| platform.get_processor().get_account().storage_scheme, | ||||||
| ) | ||||||
| .await | ||||||
| .ok() | ||||||
| .and_then(|attempts| { | ||||||
| payment_intent | ||||||
| .active_attempt_id | ||||||
| .as_ref() | ||||||
| .and_then(|active_attempt_id| { | ||||||
| attempts | ||||||
| .iter() | ||||||
| .find(|attempt| attempt.id == *active_attempt_id) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would active_attempt_id not be populated in intent?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when the payment enters revenue recovery from an external source and the attempts are marked as TriggeredBy::External so in this case active_attempt_id is set to None cause they're the external attempts and not managed by hyperswitch so active attempt is not tracked. When hyperswitch revenuer recovery creates a internal retry attempt ,in this case active attempt id is set to attempt id.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't list payment attempt from DB and filter it. Find a way to point query the appropriate attempt from DB. Like if active_attempt_id is present, fetch attempt using that id. |
||||||
| .cloned() | ||||||
| }) | ||||||
| .or_else(|| { | ||||||
| attempts | ||||||
| .iter() | ||||||
| .max_by_key(|attempt| attempt.created_at) | ||||||
| .cloned() | ||||||
| }) | ||||||
| }); | ||||||
|
|
||||||
| let response = transformers::generate_revenue_recovery_get_intent_response( | ||||||
| payment_data, | ||||||
| recovery_status, | ||||||
| card_attached, | ||||||
| payment_attempt.as_ref(), | ||||||
| ); | ||||||
|
|
||||||
| Ok(services::ApplicationResponse::Json(response)) | ||||||
|
|
@@ -8458,25 +8486,64 @@ pub async fn revenue_recovery_list_payments( | |||||
| let workflow_results = join_all(workflow_futures).await; | ||||||
| let billing_connector_results = join_all(billing_connector_futures).await; | ||||||
|
|
||||||
| let attempt_futures: Vec<_> = list | ||||||
| .iter() | ||||||
| .map(|(payment_intent, payment_attempt)| { | ||||||
| let platform_clone = platform.clone(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If an intent has an active attempt, its id should be populated in active_attempt_id of intent.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this change https://github.com/juspay/hyperswitch/pull/10508/files#r2584064017 we should not clone any object. instead use reference wherever possible |
||||||
|
|
||||||
| async move { | ||||||
| if payment_attempt.is_some() { | ||||||
| payment_attempt.clone() | ||||||
| } else { | ||||||
| db.find_payment_attempts_by_payment_intent_id( | ||||||
| &payment_intent.id.clone(), | ||||||
| platform_clone.get_processor().get_key_store(), | ||||||
| platform_clone.get_processor().get_account().storage_scheme, | ||||||
| ) | ||||||
| .await | ||||||
| .ok() | ||||||
| .and_then(|attempts| { | ||||||
| payment_intent | ||||||
| .active_attempt_id | ||||||
| .as_ref() | ||||||
| .and_then(|active_attempt_id| { | ||||||
| attempts | ||||||
| .iter() | ||||||
| .find(|attempt| attempt.id == *active_attempt_id) | ||||||
| .cloned() | ||||||
| }) | ||||||
| .or_else(|| { | ||||||
| attempts | ||||||
| .iter() | ||||||
| .max_by_key(|attempt| attempt.created_at) | ||||||
| .cloned() | ||||||
| }) | ||||||
|
Comment on lines
+8498
to
+8520
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't list payment attempt from DB and filter it. Find a way to point query the appropriate attempt from DB. Like if active_attempt_id is present, fetch attempt using that id. |
||||||
| }) | ||||||
| } | ||||||
| } | ||||||
| }) | ||||||
| .collect(); | ||||||
|
|
||||||
| let attempt_results = join_all(attempt_futures).await; | ||||||
|
|
||||||
| let data: Vec<api_models::payments::RecoveryPaymentsListResponseItem> = list | ||||||
| .into_iter() | ||||||
| .zip(workflow_results.into_iter()) | ||||||
| .zip(billing_connector_results.into_iter()) | ||||||
| .zip(attempt_results.into_iter()) | ||||||
| .map( | ||||||
| |( | ||||||
| ((payment_intent, payment_attempt), workflow_result), | ||||||
| billing_connector_account, | ||||||
| (((payment_intent, _), workflow_result), billing_connector_account), | ||||||
| payment_attempt, | ||||||
| )| { | ||||||
| let (calculate_workflow, execute_workflow) = | ||||||
| workflow_result.unwrap_or((None, None)); | ||||||
|
|
||||||
| // Get retry threshold from billing connector account | ||||||
| let max_retry_threshold = billing_connector_account | ||||||
| .as_ref() | ||||||
| .and_then(|mca| mca.get_retry_threshold()) | ||||||
| .unwrap_or(0); // Default fallback | ||||||
| .unwrap_or(0); | ||||||
|
|
||||||
| // Use custom mapping function | ||||||
| map_to_recovery_payment_item( | ||||||
| payment_intent, | ||||||
| payment_attempt, | ||||||
|
|
||||||
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.
generate openapi spec for the new introduced fields?
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 generate openapi spec