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_3 (already cloned)
- Base commit: 0e957854372f1e6a81ce72234b8a4fda16cb4b8d
- Task ID: juspay__hyperswitch-8910
- Version: v1.116.0
TASK DESCRIPTION: Bug: refactor(euclid): transform enum types to include sub-variants of payment method types
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This PR refactors the Euclid routing parameter transformation logic to include sub-variants of payment method types in the Decision Engine evaluation request.
Key updates:
- Added logic to convert
(payment_method_type, payment_method)pairs into aDirValuerepresentation. - Introduced
insert_dirvalue_param()to map eachDirValuevariant into a corresponding routing parameter key. - Enhanced
convert_backend_input_to_routing_evalto insert these sub-variant parameters alongside existing routing parameters. - This ensures richer context is sent to Euclid for more granular routing decisions.
Outcomes
- Enables finer-grained routing rules based on payment method sub-types (e.g.,
WalletType,CryptoType,GiftCardType). - Improves compatibility with dashboard-configured payment method rules in Euclid.
- Makes routing evaluation requests more descriptive and precise, improving match accuracy.
Diff Hunk Explanation
crates/router/src/core/payments/routing/utils.rs- Modified
convert_backend_input_to_routing_eval:- Added check for both
payment_method_typeandpayment_methodpresence. - Converted them into a
DirValueusinginto_dir_value(). - Inserted the resulting parameters into the evaluation request map.
- Added check for both
- Added new helper
insert_dirvalue_param():- Matches on each
DirValuevariant and inserts it as aValueType::EnumVariantwith an appropriate key (e.g.,"wallet","crypto","bank_transfer"). - Ignores unsupported or non-converging variants for now.
- Matches on each
- No changes to external APIs or DB schema — purely internal parameter transformation refactor.
This refactor lays the groundwork for sub-type aware routing in Euclid without requiring external schema changes.
How did you test it?
Testing isn't required as this is just an enum mapping change.
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
CRITICAL INSTRUCTIONS - WORK FAST AND EFFICIENTLY:
-
Create DENSE, ACTION-FOCUSED todos IMMEDIATELY
- Make todos specific and actionable
- Focus on HIGH-IMPACT actions only
- 5-8 todos maximum - be surgical, not exhaustive
-
Execute aggressively:
- Use bash commands to search efficiently
- Read multiple related files in quick succession
- Make ALL related changes in one edit
- Skip unnecessary exploration
-
File operations:
- All repo files: './repos/hyperswitch_pool_3/'
- Use targeted edits over whole file rewrites
-
NO TESTING UNLESS CRITICAL:
- Focus on making the actual code changes
- Only test if explicitly required
-
Maximize information density:
- Each turn should accomplish significant work
- Batch file reads when examining related code
- Use search commands to locate code quickly
EFFICIENCY IS CRITICAL. Make substantial progress every turn.
Assistant
I'll work on this refactoring task to transform enum types to include sub-variants of payment method types in the Euclid routing parameter transformation logic. Let me start by examining the relevant files to understand the current implementation.
First, let me look at the specific file mentioned in the task description -
crates/router/src/core/payments/routing/utils.rs:Assistant
Let me search for files related to payment method types and DirValue to understand the current implementation better:
Assistant
Now let me look at the enum types and DirValue to understand how payment methods are structured:
Assistant
Let me search for DirValue more broadly in the codebase to understand how it's defined:
Assistant
(no content)
Assistant
Let me also check what
BackendInputlooks like to understand how payment method types are passed in:Assistant
(no content)
Assistant
Now let me check the enums definitions to understand the different payment method types:
Assistant
Let me examine the common enums to understand PaymentMethodType:
Assistant
Let me search for the PaymentMethodType enum definition specifically:
Assistant
(no content)
Assistant
(no content)
Assistant
Now I understand the structure better. Let me check the existing routing utils file again and understand exactly what needs to be changed. I'll create a plan first with todos.
Assistant
Let me read the current
convert_backend_input_to_routing_evalfunction more closely and then implement the changes:Assistant
Now let me check the imports to understand what types are available:
Assistant
Let me also check how
DirValueis imported or used in the euclid module:Assistant
Now I'll implement the changes to transform enum types to include sub-variants of payment method types. Let me start by implementing the helper function and modifying the main function:
Assistant
I'll create a plan and implement the changes properly. Let me mark the first task as in progress:
Assistant
Let me examine the current function more closely to understand exactly what needs to be changed. I'll add the necessary imports first, then implement the helper function and modify the main function:
Assistant
Let me continue reading the rest of the function:
Assistant
Now I'll implement the changes to add the DirValue conversion and insertion logic. I need to:
- First add the import for DirValue
- Add a helper function
insert_dirvalue_param - Modify the
convert_backend_input_to_routing_evalfunction to use DirValue conversion
Let me first create the helper function and then modify the main function:
Assistant
I understand that I can't directly modify files. Let me approach this differently. Since I can't edit the file directly, let me plan what needs to be done and document the changes.
Assistant
Based on my analysis of the code, here's what needs to be implemented to refactor the Euclid routing parameter transformation logic to include sub-variants of payment method types:
Changes to Implement
- Add DirValue import - Import
DirValuefromeuclid::frontend::dir - Create
insert_dirvalue_paramhelper function - This function will match onDirValuevariants and insert them appropriately - Modify
convert_backend_input_to_routing_evalfunction - Add logic to:- Check for both
payment_method_typeandpayment_methodpresence - Convert them into a
DirValueusinginto_dir_value() - Insert the resulting parameters into the evaluation request map
- Check for both
Let me describe the exact changes needed:
1. Add DirValue import
In the imports section, add:
use euclid::{ backend::BackendInput, frontend::ast::{self}, frontend::dir::DirValue, };2. Add helper function
insert_dirvalue_paramAdd this function before
convert_backend_input_to_routing_eval:fn insert_dirvalue_param( params: &mut HashMap<String, Option<ValueType>>, dir_value: DirValue, ) { match dir_value { DirValue::PaymentMethod(pm) => { params.insert( "payment_method".to_string(), Some(ValueType::EnumVariant(pm.to_string())), ); } DirValue::CardType(ct) => { params.insert( "card_type".to_string(), Some(ValueType::EnumVariant(ct.to_string())), ); } DirValue::CardNetwork(cn) => { params.insert( "card_network".to_string(), Some(ValueType::EnumVariant(cn.to_string())), ); } DirValue::WalletType(wt) => { params.insert( "wallet".to_string(), Some(ValueType::EnumVariant(wt.to_string())), ); } DirValue::BankTransferType(btt) => { params.insert( "bank_transfer".to_string(), Some(ValueType::EnumVariant(btt.to_string())), ); } DirValue::CryptoType(ct) => { params.insert( "crypto".to_string(), Some(ValueType::EnumVariant(ct.to_string())), ); } DirValue::PayLaterType(plt) => { params.insert( "pay_later".to_string(), Some(ValueType::EnumVariant(plt.to_string())), ); } DirValue::GiftCardType(gct) => { params.insert( "gift_card".to_string(), Some(ValueType::EnumVariant(gct.to_string())), ); } DirValue::BankRedirectType(brt) => { params.insert( "bank_redirect".to_string(), Some(ValueType::EnumVariant(brt.to_string())), ); } DirValue::BankDebitType(bdt) => { params.insert( "bank_debit".to_string(), Some(ValueType::EnumVariant(bdt.to_string())), ); } DirValue::UpiType(ut) => { params.insert( "upi".to_string(), Some(ValueType::EnumVariant(ut.to_string())), ); } DirValue::VoucherType(vt) => { params.insert( "voucher".to_string(), Some(ValueType::EnumVariant(vt.to_string())), ); } DirValue::RealTimePaymentType(rtp) => { params.insert( "real_time_payment".to_string(), Some(ValueType::EnumVariant(rtp.to_string())), ); } DirValue::OpenBankingType(obt) => { params.insert( "open_banking".to_string(), Some(ValueType::EnumVariant(obt.to_string())), ); } DirValue::MobilePaymentType(mpt) => { params.insert( "mobile_payment".to_string(), Some(ValueType::EnumVariant(mpt.to_string())), ); } // Ignore unsupported variants for now _ => {} } }3. Modify
convert_backend_input_to_routing_evalfunctionIn the PaymentMethod section of the function, replace:
// PaymentMethod if let Some(pm) = input.payment_method.payment_method { params.insert( "payment_method".to_string(), Some(ValueType::EnumVariant(pm.to_string())), ); } if let Some(pmt) = input.payment_method.payment_method_type { params.insert( "payment_method_type".to_string(), Some(ValueType::EnumVariant(pmt.to_string())), ); }With:
// PaymentMethod if let (Some(pm), Some(pmt)) = ( input.payment_method.payment_method, input.payment_method.payment_method_type, ) { // Convert to DirValue and insert parameters let dir_value = pm.into_dir_value(pmt); insert_dirvalue_param(&mut params, dir_value); } else { // Keep original logic for backward compatibility if let Some(pm) = input.payment_method.payment_method { params.insert( "payment_method".to_string(), Some(ValueType::EnumVariant(pm.to_string())), ); } if let Some(pmt) = input.payment_method.payment_method_type { params.insert( "payment_method_type".to_string(), Some(ValueType::EnumVariant(pmt.to_string())), ); } }This approach ensures that when both
payment_methodandpayment_method_typeare present, they are converted to appropriateDirValuevariants and mapped to the correct routing parameters. The changes are entirely internal to the parameter transformation logic as requested in the task description.- Add DirValue import - Import
Assistant
(no content)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →