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_1 (already cloned)
- Base commit: 33cd60e64288b2a6bb24cc27b9d319fdbeab46ef
- Task ID: juspay__hyperswitch-8190
- Version: v1.114.0
TASK DESCRIPTION: Bug: refactor(dynamic_routing): add logic for creating merchant account in decision engine
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
Merchant account creation on decision-engine is pre-requisite for making success based routing calls to it. Since toggle SR endpoint on Hyperswitch is the place where rule creation API of DE is being called, we can check whether merchant_account exists in DE, if exists, toggle endpoint will go ahead with creating the rule. If not, it will first call DE to create a merchant_account and then create the rule. I have created the
is_merchant_created_in_decision_engineflag inside thedynamic_routing_algorithmcolumn which is of type JSON in profile table. I have added a#[serde(default)]attribute on top ofis_merchant_created_in_decision_engine. Hence it shouldn't break for older profiles which doesn't have this field itself.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?
- Create merchant_account and API key in Hyperswitch.
- Toggle SR for the default profile created above.
curl --location --request POST 'http://localhost:8080/account/merchant_1748681084/business_profile/pro_3gHXWoq1Xh3AKi6tNZV1/dynamic_routing/success_based/toggle?enable=dynamic_connector_selection' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: xyz' Assistant
I'll help you implement the dynamic routing refactor to add logic for creating merchant accounts in the decision engine. Let me start by understanding the current codebase structure and locating the relevant files.
Assistant
I'll work on implementing the dynamic routing refactor to add logic for creating merchant accounts in the decision engine. Let me start by exploring the codebase structure to understand where the relevant files are located.
Assistant
Let me search for files related to dynamic routing and decision engine integration:
Assistant
(no content)
Assistant
Let me search for the toggle endpoint and dynamic routing files more broadly:
Assistant
Let me examine the routing module to understand the structure better:
Assistant
Now let me look at the helper functions to understand how the dynamic routing is implemented:
Assistant
Let me search for the update_decision_engine_dynamic_routing_setup function mentioned in the code:
Assistant
Let me examine the routing helpers file to understand how dynamic routing works:
Assistant
Let me look at the business profile structure to understand how dynamic_routing_algorithm is defined:
Assistant
Let me look at the diesel models to understand the profile structure:
Assistant
Let me find the profile model:
Assistant
(no content)
Assistant
Now let me search for the DynamicRoutingAlgorithmRef to understand how it's structured:
Assistant
Let me check the routing API models to understand the structure:
Assistant
Now let me check how the helpers module implements the enable_dynamic_routing_algorithm function to understand where we need to add the merchant account creation logic:
Assistant
Let me continue reading the helpers file to find the enable_dynamic_routing_algorithm function:
Assistant
Let me search for the function definition:
Assistant
(no content)
Assistant
Let me search around the line numbers where this function is likely defined by looking for the function declaration:
Assistant
Let me continue reading to find the end of the function:
Assistant
Now I've found the key information. Let me also look at the routing.rs file to see how toggle_specific_dynamic_routing is called:
Assistant
Now I understand the codebase structure. Let me examine the routing endpoint to understand how we need to add the merchant account creation logic. Let me also look at the current implementation of the
enable_decision_engine_dynamic_routing_setupfunction to understand how it works.Based on my analysis, I now have a clearer picture of the implementation needed. Let me update the todo list and proceed with the implementation:
Assistant
Looking at the code more carefully, I need to understand how the merchant account creation should work in the decision engine. Let me analyze the existing implementation in
enable_decision_engine_dynamic_routing_setupandcreate_decision_engine_merchantfunctions.Based on the task description, I need to:
- Check if merchant account exists in the decision engine before enabling routing
- If not, create the merchant account in the decision engine first
- Then proceed with enabling the routing
Let me now modify the
enable_specific_routing_algorithmfunction inhelpers.rsto implement this logic:Assistant
I see that I don't have permission to write to the file directly. Let me first check if there's already a flag in the structure for the merchant account status. Based on the task description, it mentions that they already created an
is_merchant_created_in_decision_engineflag in thedynamic_routing_algorithmcolumn with#[serde(default)]attribute.Let me first examine the current
DynamicRoutingAlgorithmRefstructure to understand the proper way to add the field:Assistant
I can see that the
DynamicRoutingAlgorithmRefstruct doesn't currently have the flag. According to the task description, this field is expected to be in thedynamic_routing_algorithmcolumn in the database, which is a JSON field. This means the field is added to the JSON stored in the database rather than to the Rust struct itself. The task description says the#[serde(default)]attribute was added, which means the field should be deserialized gracefully even if it doesn't exist in older profiles.However, since we're modifying the codebase, I need to make changes in the appropriate way. Let me instead focus on modifying the implementation correctly by checking for the existence of the field properly. Since I can't actually edit the file, let me summarize what I need to do and provide a comprehensive solution.
Let me also see if I can get the current structure by reading the code more carefully to understand how to properly implement the check:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.