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_4 (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 help you implement the bug fix for the revenue recovery webhook flow. Let me first understand the current implementation by examining the relevant files.
Assistant
Let me search for files related to revenue recovery and webhook handling to understand the current implementation:
Assistant
Now let me search for webhook handling related to stripe billing:
Assistant
Let me search more broadly for webhook handling code:
Assistant
Let me look at the key webhook recovery file and the stripe billing connector:
Assistant
Now let me check the stripe billing connector to understand how it handles connector transaction IDs:
Assistant
Let me look at the transformers file for the stripe billing connector to understand the structure better:
Assistant
Now I need to look at how the payment attempts are checked to understand the current implementation and where we need to make changes. Let me also search for recent changes to the payment get validation:
Assistant
Let me look at how payment attempts are retrieved in the revenue recovery flow, particularly focusing on the specific code around the payment get:
Assistant
Let me now look for the exact place where the payment get validation happens. Let me check the payment attempt retrieval logic more closely:
Assistant
Let me examine the
find_attempt_in_attempts_list_using_connector_transaction_idfunction in the payments API models to understand it better:Assistant
Let me search for the specific function:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me look at the actual implementation of
find_attempt_in_attempts_list_using_connector_transaction_idin the payments module:Assistant
Let me try a more targeted search to understand how payment attempts are found by connector transaction ID:
Assistant
Based on my analysis, I now understand the issue and what needs to be changed. Let me summarize what I've found and then implement the fix.
Looking at the revenue recovery webhook flow in
recovery_incoming.rs, I see the core problem:- The current code in
get_payment_attempt()function (lines 456-529) usespayments::payments_core::<PSync, ...>withPaymentGetoperation to fetch payment attempts. - This approach fails for the first invoice webhook because there's no attempt in the database yet.
- The task description indicates we need to use "payment get attempt list" instead of "payment get"
- For Stripe billing, we also need to support comparing charge ID when available instead of connector transaction ID
Let me now update the code to fix both issues:
- The current code in
Assistant
I need to first check if I can read this file to make sure I understand the structure correctly, and then I'll make a plan for the change. Let me also update the todo list to reflect the actual work I'm going to do.
Assistant
Let me check what the revenue recovery data structure looks like to see if there's a charge_id field:
Assistant
I see that the
RevenueRecoveryAttemptDatadoesn't have acharge_idfield currently. Let me check what's in the stripe billing transformers to see where charge_id might come from:Assistant
Now I understand the issue better. Looking at the code and the task requirements, I need to make two key changes:
- Replace the payment get operation with a payment attempt list operation when appropriate
- Support checking for charge ID in addition to connector transaction ID for Stripe billing
However, looking at the current structure and the fact that we're already in a revenue recovery context, I need to think differently about how to implement this. Let me check how the data flows through the recovery incoming webhook processing more closely.
Looking at line 503-508 in the recovery_incoming.rs, I see the issue more clearly. The problem is that the
find_attempt_in_attempts_list_using_connector_transaction_idfunction is being called, but for first invoice webhooks, there may be no payment attempt in the DB yet.Let me approach this by modifying the recovery_incoming.rs file to add the support for charge_id and improve the fallback logic.
First, let me check if the
charge_idis already accessible in theRevenueRecoveryAttemptData:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.