Skip to content
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

feat: add routing support for v2 sdk session flow #6763

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

hrithikesh026
Copy link
Contributor

@hrithikesh026 hrithikesh026 commented Dec 6, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Added session routing support for session call in v2. And store the prerouting results in the payment_intent tabled prerouting_algorithm column.

Other changes:

  • used MerchantConnectorAccounts Wrapper instead of Vec<MerchantConnectorAccount> across the codebase.

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?

follow the steps mentioned in this PR.
#6502

In addition to that check if prerouting_algorithm column in payment_intent is updated.
use this query.

select prerouting_algorithm from payment_intent where id ='payment_id';

image

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

@hrithikesh026 hrithikesh026 added A-core Area: Core flows C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed api-v2 labels Dec 6, 2024
@hrithikesh026 hrithikesh026 added this to the December 2024 Release milestone Dec 6, 2024
@hrithikesh026 hrithikesh026 self-assigned this Dec 6, 2024
@hrithikesh026 hrithikesh026 requested review from a team as code owners December 6, 2024 06:34
Copy link

semanticdiff-com bot commented Dec 6, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/storage_impl/src/payments/payment_intent.rs  90% smaller
  crates/router/src/core/utils.rs  68% smaller
  crates/router/src/core/payments/operations/payment_session.rs  65% smaller
  crates/router/src/core/payment_methods/cards.rs  64% smaller
  crates/router/src/core/admin.rs  60% smaller
  crates/router/src/consts.rs  52% smaller
  crates/router/src/core/payout_link.rs  51% smaller
  crates/router/src/db/merchant_connector_account.rs  48% smaller
  crates/hyperswitch_interfaces/src/conversion_impls.rs  28% smaller
  crates/common_utils/src/macros.rs  21% smaller
  crates/router/src/core/payments/flows.rs  19% smaller
  crates/router/src/core/payments/operations/payment_session_intent.rs  17% smaller
  crates/hyperswitch_domain_models/src/payments/payment_intent.rs  15% smaller
  crates/router/src/core/payments/helpers.rs  14% smaller
  crates/hyperswitch_interfaces/src/connector_integration_v2.rs  10% smaller
  crates/router/src/core/payments/routing.rs  10% smaller
  crates/hyperswitch_connectors/src/default_implementations.rs  8% smaller
  crates/router/src/core/payments.rs  8% smaller
  crates/router/src/types/api/authentication.rs  7% smaller
  crates/router/src/types/storage.rs  6% smaller
  crates/hyperswitch_connectors/src/default_implementations_v2.rs  5% smaller
  crates/router/src/types/api/authentication_v2.rs  3% smaller
  crates/hyperswitch_domain_models/src/merchant_connector_account.rs  3% smaller
  crates/router/src/types/api.rs  1% smaller
  crates/router/src/types/api/fraud_check_v2.rs  1% smaller
  crates/hyperswitch_domain_models/src/payments.rs  1% smaller
  crates/hyperswitch_interfaces/src/configs.rs  1% smaller
  crates/hyperswitch_connectors/src/connectors/nexinets.rs  1% smaller
  crates/hyperswitch_connectors/src/connectors/helcim.rs  1% smaller
  crates/hyperswitch_interfaces/src/api.rs  1% smaller
  .typos.toml Unsupported file format
  crates/api_models/src/routing.rs  0% smaller
  crates/diesel_models/src/payment_intent.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/coinbase.rs  0% smaller
  crates/hyperswitch_domain_models/Cargo.toml Unsupported file format
  crates/hyperswitch_domain_models/src/configs.rs  0% smaller
  crates/hyperswitch_domain_models/src/consts.rs  0% smaller
  crates/hyperswitch_domain_models/src/lib.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_flow_types.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_flow_types/authentication.rs  0% smaller
  crates/hyperswitch_domain_models/src/routing.rs  0% smaller
  crates/hyperswitch_interfaces/src/api/authentication.rs  0% smaller
  crates/hyperswitch_interfaces/src/api/authentication_v2.rs  0% smaller
  crates/hyperswitch_interfaces/src/api/fraud_check.rs  0% smaller
  crates/hyperswitch_interfaces/src/api/fraud_check_v2.rs  0% smaller
  crates/hyperswitch_interfaces/src/connector_integration_interface.rs Unsupported file format
  crates/hyperswitch_interfaces/src/lib.rs  0% smaller
  crates/router/Cargo.toml Unsupported file format
  crates/router/src/core/payments/connector_integration_v2_impls.rs  0% smaller
  crates/router/src/core/payments/session_operation.rs  0% smaller
  crates/router/src/core/payments/transformers.rs  0% smaller
  crates/router/src/core/routing.rs  0% smaller
  crates/router/src/core/routing/helpers.rs  0% smaller
  crates/router/src/db/kafka_store.rs  0% smaller
  crates/router/src/services.rs  0% smaller
  crates/router/src/services/connector_integration_interface.rs Unsupported file format
  crates/router/src/types/api/fraud_check.rs  0% smaller

@hrithikesh026 hrithikesh026 added M-database-changes Metadata: This PR involves database schema changes and removed M-database-changes Metadata: This PR involves database schema changes labels Dec 9, 2024
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 24, 2024
@hrithikesh026 hrithikesh026 requested review from jarnura and removed request for a team January 20, 2025 06:49
Comment on lines 1262 to 1286
let chosen_connectors = if let Some(ref algorithm_id) = algorithm_id {
let cached_algorithm = ensure_algorithm_cached_v1(
&session_pm_input.state.clone(),
merchant_id,
algorithm_id,
session_pm_input.profile_id,
transaction_type,
)
.await?;

match cached_algorithm.as_ref() {
CachedAlgorithm::Single(conn) => vec![(**conn).clone()],
CachedAlgorithm::Priority(plist) => plist.clone(),
CachedAlgorithm::VolumeSplit(splits) => perform_volume_split(splits.to_vec())
.change_context(errors::RoutingError::ConnectorSelectionFailed)?,
CachedAlgorithm::Advanced(interpreter) => execute_dsl_and_get_connector_v1(
session_pm_input.backend_input.clone(),
interpreter,
)?,
}
} else {
profile_wrapper
.get_default_fallback_list_of_connector_under_profile()
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of writing a if else, use a function call here which return the required value and move the logic to a function. Avoid writing if else in the flows instead flow a function based approach.

.await?;

if final_selection.is_empty() {
let fallback = profile_wrapper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chosen_connectors itself derived from get_default_fallback_list_of_connector_under_profile if algorithm_id not present, how the below cases is different from that?

.payment_intent
.metadata
.clone()
.map(|val| val.parse_value("routing_parameters"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this as impl based function

@@ -534,9 +534,10 @@ pub struct PaymentIntentUpdateFields {
#[diesel(table_name = payment_intent)]
pub struct PaymentIntentUpdateInternal {
pub status: Option<storage_enums::IntentStatus>,
pub active_attempt_id: Option<common_utils::id_type::GlobalAttemptId>,
pub prerouting_algorithm: Option<serde_json::Value>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is reason for making this as algorithm instead of algorithm id?

And why we need to make this as UnTyped Value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prerouting_algorithm is actually the result after running routing algorithm.

Comment on lines 82 to 87
pub state: &'a SessionState,
pub country: Option<CountryAlpha2>,
pub key_store: &'a domain::MerchantKeyStore,
pub merchant_account: &'a domain::MerchantAccount,
pub payment_intent: &'a oss_storage::PaymentIntent,
pub chosen: api::SessionConnectorDatas,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only chosen, country and individual fields from payment intent should be present here.

// Store the routing results in payment intent
payment_data.payment_intent.prerouting_algorithm = Some(
pre_routing
.encode_to_value()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be strict type in payment intent domain type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows api-v2 C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants