You are working on the hyperswitch repository (Rust payment processing system).…
- User
You are working on the hyperswitch repository (Rust payment processing system).
REPOSITORY SETUP:
- Repository: juspay/hyperswitch
- Working directory: ./repos/hyperswitch_pool_7 (already cloned)
- Base commit: 7943fb4bfb156e22d5329d45a580f90e02283604
- Task ID: juspay__hyperswitch-8394
- Version: v1.114.0
TASK DESCRIPTION: Bug: feat(revenue_recovery): Invoke attempt list instead of payment get in recovery webhooks flow
Previously we were using payment get to find whether attempt is present in db or not, but for the first invoice webhook there won't be any attempt present in db and recently we added a validation to use payment get only in case of attempt is present.
Also for stripe billing / stripe connector_transaction_id remains same instead charge id keeps changing , so we need to add support for this by checking if charge id is present we compare charge id if not we check for connector transaction id.
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
Previously we were using payment get to find whether attempt is present in db or not, but for the first invoice webhook there won't be any attempt present in db and recently we added a validation to use payment get only in case of attempt is present. This PR solves this issue by invoking payment get attempt list instead of payment get.
Also for stripe billing / stripe connector_transaction_id remains same instead charge id keeps changing , so we added a support for this by checking if charge id is present we compare charge id if not we check for connector transaction id.
Additional Changes
- This PR modifies the API contract
- This PR modifies the database schema
- This PR modifies application configuration/environment variables
Motivation and Context
Assistant
I'll work on this bug fix for the revenue recovery webhook flow. Let me first understand the current implementation by exploring the relevant files and code.
Assistant
Let me first explore the repository structure to understand where the revenue recovery and webhook code is located.
Assistant
(no content)
Assistant
Now let me look at the specific implementation files that handle the revenue recovery webhook flow and payment attempt logic:
Assistant
(no content)
Assistant
Let me examine the recovery incoming webhook handler:
Assistant
Now let me look at the payment attempt logic and how it currently checks for payment attempts:
Assistant
Let me check the psync flow since it seems relevant to the issue:
Assistant
Let me search for payment get operations in the payments core:
Assistant
Let me look at the payment operations to understand how payment get is implemented:
Assistant
Let me now search for how payment attempts are retrieved specifically for the recovery flow. Looking at the code from the revenue recovery flow, I can see that at lines 470-528 in recovery_incoming.rs, there's a
get_payment_attemptmethod that uses the PaymentGet operation to fetch the attempt. Let me also check for the connector transaction ID logic:Assistant
Now I need to examine how the connector transaction ID logic works. Let me look for the methods that deal with finding attempts by connector transaction ID:
Assistant
(no content)
Assistant
Let me search for the specific method in the payments file more specifically:
Assistant
(no content)
Assistant
Let me search more broadly:
Assistant
Let me check the structure of the PaymentsResponse to understand the connector transaction ID matching:
Assistant
Perfect! I can now see the key method
find_attempt_in_attempts_list_using_connector_transaction_idthat's used in the recovery flow. Now I need to understand how to find the appropriate payment attempt. Let me check the actual current implementation that needs to be changed.Looking at the code in
recovery_incoming.rslines 500-508, I can see that the current implementation only looks for the attempt in the list usingconnector_transaction_idbut according to the task description, we need to:- Change from using
payment gettopayment get attempt list(because for first invoice webhook there won't be any attempt in DB) - Support both charge ID and connector_transaction_id comparison for Stripe billing
Let me now update the code to reflect these changes:
- Change from using
Assistant
(no content)
Assistant
Now let me check the revenue recovery data structure to understand how it handles charge ID vs connector_transaction_id:
Assistant
(no content)
Assistant
(no content)
Assistant
Now I have a clearer picture of the situation. Let me now examine the code around lines 500-508 in recovery_incoming.rs more closely to understand how to make the changes properly:
Assistant
I don't have permission to make file changes yet. Let me check how the code is structured to better understand the changes needed.
Based on my analysis, I need to modify the logic in the recovery flow to:
- Not rely on PaymentGet when there might not be an attempt in the DB yet (first invoice webhook)
- Properly handle Stripe billing where connector_transaction_id stays the same but charge_id changes
Let me update my approach and look at a more specific method that would be better for handling this issue.
Assistant
Now I understand the complete flow. Looking at the issue description and the current code, I can see that:
- The current code uses
PaymentGetoperation (line 484) to retrieve payment attempts - For the first invoice webhook, there might not be any attempt in the DB yet
- The problem is that it tries to fetch payment attempt using
PaymentGetoperation even when no attempt exists in DB yet
The solution is to make the approach smarter by checking if there's an existing attempt before trying to fetch it via PaymentGet, and also support both charge ID and connector_transaction_id for Stripe billing.
However, I need to be careful about modifying this because I don't have permissions to make the file changes directly. But I can document what needs to be changed.
Let me summarize the changes needed:
- The current code uses
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.