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(router): profile specific fallback derivation while routing payments #2806

Merged
merged 24 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2e2afe4
feat(router): profile specific fallback derivation while routing paym…
prajjwalkumar17 Nov 8, 2023
435005e
Merge branch 'main' into feat/profile_specific_fallback_routing
prajjwalkumar17 Nov 8, 2023
5d423fd
Merge branch 'main' into feat/profile_specific_fallback_routing
prajjwalkumar17 Nov 8, 2023
48ce244
refactor(router): resolved open-api errors
prajjwalkumar17 Nov 8, 2023
555b4da
Merge branch 'feat/profile_specific_fallback_routing' of https://gith…
prajjwalkumar17 Nov 8, 2023
83acfcf
feat(euclid): added routes for profile based fallbacks
prajjwalkumar17 Nov 8, 2023
aa6426e
chore: run formatter
github-actions[bot] Nov 8, 2023
d6ae03c
feat(euclid): added routes for profile based fallbacks
prajjwalkumar17 Nov 8, 2023
776bb2d
feat(euclid): added routes for profile based fallbacks
prajjwalkumar17 Nov 8, 2023
0d88d92
chore: run formatter
github-actions[bot] Nov 8, 2023
73b0e5e
feat(euclid): updated imports
prajjwalkumar17 Nov 8, 2023
0ba26d4
Merge branch 'feat/profile_specific_fallback_routing' of https://gith…
prajjwalkumar17 Nov 8, 2023
7922f65
Merge branch 'main' into feat/profile_specific_fallback_routing
prajjwalkumar17 Nov 8, 2023
824e51e
Merge branch 'main' into feat/profile_specific_fallback_routing
prajjwalkumar17 Nov 9, 2023
3d6a634
feat(euclid): ApiEventMetric addition
prajjwalkumar17 Nov 9, 2023
49d35bb
chore: run formatter
github-actions[bot] Nov 9, 2023
f68465f
feat(euclid): add APiEventMetric impl to a Wrapper struct
Aprabhat19 Nov 9, 2023
bd329c5
Merge branch 'main' into feat/profile_specific_fallback_routing
Aprabhat19 Nov 9, 2023
475a54e
Merge branch 'main' into feat/profile_specific_fallback_routing
Aprabhat19 Nov 9, 2023
b854930
make the type as a struct
Aprabhat19 Nov 10, 2023
45c509e
Merge branch 'feat/profile_specific_fallback_routing' of https://gith…
Aprabhat19 Nov 10, 2023
e6542db
Merge branch 'main' into feat/profile_specific_fallback_routing
prajjwalkumar17 Nov 10, 2023
0a35251
Merge branch 'main' into feat/profile_specific_fallback_routing
prajjwalkumar17 Nov 13, 2023
bcf1a57
feat(euclid): added the auth
prajjwalkumar17 Nov 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ readme = "README.md"
license.workspace = true

[features]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts"]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "profile_specific_fallback_routing"]
s3 = ["dep:aws-sdk-s3", "dep:aws-config"]
kms = ["external_services/kms", "dep:aws-config"]
email = ["external_services/email", "dep:aws-config"]
basilisk = ["kms"]
stripe = ["dep:serde_qs"]
release = ["kms", "stripe", "basilisk", "s3", "email", "business_profile_routing", "accounts_cache", "kv_store"]
release = ["kms", "stripe", "basilisk", "s3", "email", "business_profile_routing", "accounts_cache", "kv_store", "profile_specific_fallback_routing"]
olap = ["data_models/olap", "storage_impl/olap", "scheduler/olap"]
oltp = ["data_models/oltp", "storage_impl/oltp"]
kv_store = ["scheduler/kv_store"]
Expand All @@ -24,6 +24,7 @@ openapi = ["olap", "oltp", "payouts"]
vergen = ["router_env/vergen"]
backwards_compatibility = ["api_models/backwards_compatibility", "euclid/backwards_compatibility", "kgraph_utils/backwards_compatibility"]
business_profile_routing=["api_models/business_profile_routing"]
profile_specific_fallback_routing = []
dummy_connector = ["api_models/dummy_connector", "euclid/dummy_connector", "kgraph_utils/dummy_connector"]
connector_choice_mca_id = ["api_models/connector_choice_mca_id", "euclid/connector_choice_mca_id", "kgraph_utils/connector_choice_mca_id"]
external_access_dc = ["dummy_connector"]
Expand Down
70 changes: 59 additions & 11 deletions crates/router/src/core/payments/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ pub struct SessionRoutingPmTypeInput<'a> {
routing_algorithm: &'a MerchantAccountRoutingAlgorithm,
backend_input: dsl_inputs::BackendInput,
allowed_connectors: FxHashMap<String, api::GetToken>,
#[cfg(feature = "business_profile_routing")]
#[cfg(any(
feature = "business_profile_routing",
feature = "profile_specific_fallback_routing"
))]
profile_id: Option<String>,
}
static ROUTING_CACHE: StaticCache<CachedAlgorithm> = StaticCache::new();
Expand Down Expand Up @@ -207,10 +210,22 @@ pub async fn perform_static_routing_v1<F: Clone>(
let algorithm_id = if let Some(id) = algorithm_ref.algorithm_id {
id
} else {
let fallback_config =
routing_helpers::get_merchant_default_config(&*state.clone().store, merchant_id)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?;
let fallback_config = routing_helpers::get_merchant_default_config(
&*state.clone().store,
#[cfg(not(feature = "profile_specific_fallback_routing"))]
merchant_id,
#[cfg(feature = "profile_specific_fallback_routing")]
{
payment_data
.payment_intent
.profile_id
.as_ref()
.get_required_value("profile_id")
.change_context(errors::RoutingError::ProfileIdMissing)?
},
)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?;

return Ok(fallback_config);
};
Expand Down Expand Up @@ -616,10 +631,22 @@ pub async fn perform_fallback_routing<F: Clone>(
eligible_connectors: Option<&Vec<api_enums::RoutableConnectors>>,
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {
let fallback_config =
routing_helpers::get_merchant_default_config(&*state.store, &key_store.merchant_id)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?;
let fallback_config = routing_helpers::get_merchant_default_config(
&*state.store,
#[cfg(not(feature = "profile_specific_fallback_routing"))]
&key_store.merchant_id,
#[cfg(feature = "profile_specific_fallback_routing")]
{
payment_data
.payment_intent
.profile_id
.as_ref()
.get_required_value("profile_id")
.change_context(errors::RoutingError::ProfileIdMissing)?
},
)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?;
let backend_input = make_dsl_input(payment_data)?;

perform_kgraph_filtering(
Expand Down Expand Up @@ -819,8 +846,11 @@ pub async fn perform_session_flow_routing(
routing_algorithm: &routing_algorithm,
backend_input: backend_input.clone(),
allowed_connectors,
#[cfg(feature = "business_profile_routing")]
profile_id: session_input.payment_intent.clone().profile_id,
#[cfg(any(
feature = "business_profile_routing",
feature = "profile_specific_fallback_routing"
))]
profile_id: session_input.payment_intent.profile_id.clone(),
};
let maybe_choice = perform_session_routing_for_pm_type(session_pm_input).await?;

Expand Down Expand Up @@ -880,7 +910,16 @@ async fn perform_session_routing_for_pm_type(
} else {
routing_helpers::get_merchant_default_config(
&*session_pm_input.state.clone().store,
#[cfg(not(feature = "profile_specific_fallback_routing"))]
merchant_id,
#[cfg(feature = "profile_specific_fallback_routing")]
{
session_pm_input
.profile_id
.as_ref()
.get_required_value("profile_id")
.change_context(errors::RoutingError::ProfileIdMissing)?
},
)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?
Expand All @@ -903,7 +942,16 @@ async fn perform_session_routing_for_pm_type(
if final_selection.is_empty() {
let fallback = routing_helpers::get_merchant_default_config(
&*session_pm_input.state.clone().store,
#[cfg(not(feature = "profile_specific_fallback_routing"))]
merchant_id,
#[cfg(feature = "profile_specific_fallback_routing")]
{
session_pm_input
.profile_id
.as_ref()
.get_required_value("profile_id")
.change_context(errors::RoutingError::ProfileIdMissing)?
},
)
.await
.change_context(errors::RoutingError::FallbackConfigFetchFailed)?;
Expand Down
Loading