mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
refactor(routing): Refactor fallback routing apis for v2 (#5592)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -251,7 +251,7 @@ pub struct BusinessProfile {
|
|||||||
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<String>,
|
||||||
// pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
||||||
@ -289,7 +289,7 @@ pub struct BusinessProfileNew {
|
|||||||
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<String>,
|
||||||
// pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
||||||
@ -324,7 +324,7 @@ pub struct BusinessProfileUpdateInternal {
|
|||||||
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<String>,
|
||||||
// pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
||||||
@ -358,7 +358,7 @@ impl BusinessProfileUpdateInternal {
|
|||||||
// order_fulfillment_time_origin,
|
// order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id,
|
frm_routing_algorithm_id,
|
||||||
payout_routing_algorithm_id,
|
payout_routing_algorithm_id,
|
||||||
// default_fallback_routing,
|
default_fallback_routing,
|
||||||
} = self;
|
} = self;
|
||||||
BusinessProfile {
|
BusinessProfile {
|
||||||
profile_id: source.profile_id,
|
profile_id: source.profile_id,
|
||||||
@ -407,7 +407,7 @@ impl BusinessProfileUpdateInternal {
|
|||||||
frm_routing_algorithm_id: frm_routing_algorithm_id.or(source.frm_routing_algorithm_id),
|
frm_routing_algorithm_id: frm_routing_algorithm_id.or(source.frm_routing_algorithm_id),
|
||||||
payout_routing_algorithm_id: payout_routing_algorithm_id
|
payout_routing_algorithm_id: payout_routing_algorithm_id
|
||||||
.or(source.payout_routing_algorithm_id),
|
.or(source.payout_routing_algorithm_id),
|
||||||
// default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
|
default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,7 +451,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
|
|||||||
// order_fulfillment_time_origin: new.order_fulfillment_time_origin,
|
// order_fulfillment_time_origin: new.order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id: new.frm_routing_algorithm_id,
|
frm_routing_algorithm_id: new.frm_routing_algorithm_id,
|
||||||
payout_routing_algorithm_id: new.payout_routing_algorithm_id,
|
payout_routing_algorithm_id: new.payout_routing_algorithm_id,
|
||||||
// default_fallback_routing: new.default_fallback_routing,
|
default_fallback_routing: new.default_fallback_routing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -208,6 +208,7 @@ diesel::table! {
|
|||||||
frm_routing_algorithm_id -> Nullable<Varchar>,
|
frm_routing_algorithm_id -> Nullable<Varchar>,
|
||||||
#[max_length = 64]
|
#[max_length = 64]
|
||||||
payout_routing_algorithm_id -> Nullable<Varchar>,
|
payout_routing_algorithm_id -> Nullable<Varchar>,
|
||||||
|
default_fallback_routing -> Nullable<Jsonb>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -439,7 +439,7 @@ pub struct BusinessProfile {
|
|||||||
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<String>,
|
||||||
// pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
||||||
@ -470,7 +470,7 @@ pub struct BusinessProfileGeneralUpdate {
|
|||||||
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
// pub order_fulfillment_time_origin: Option<OrderFulfillmentTimeOrigin>,
|
||||||
pub frm_routing_algorithm_id: Option<String>,
|
pub frm_routing_algorithm_id: Option<String>,
|
||||||
pub payout_routing_algorithm_id: Option<String>,
|
pub payout_routing_algorithm_id: Option<String>,
|
||||||
// pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
|
||||||
@ -481,6 +481,9 @@ pub enum BusinessProfileUpdate {
|
|||||||
routing_algorithm_id: Option<String>,
|
routing_algorithm_id: Option<String>,
|
||||||
payout_routing_algorithm_id: Option<String>,
|
payout_routing_algorithm_id: Option<String>,
|
||||||
},
|
},
|
||||||
|
DefaultRoutingFallbackUpdate {
|
||||||
|
default_fallback_routing: Option<pii::SecretSerdeValue>,
|
||||||
|
},
|
||||||
ExtendedCardInfoUpdate {
|
ExtendedCardInfoUpdate {
|
||||||
is_extended_card_info_enabled: Option<bool>,
|
is_extended_card_info_enabled: Option<bool>,
|
||||||
},
|
},
|
||||||
@ -522,7 +525,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
|
|||||||
// order_fulfillment_time_origin,
|
// order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id,
|
frm_routing_algorithm_id,
|
||||||
payout_routing_algorithm_id,
|
payout_routing_algorithm_id,
|
||||||
// default_fallback_routing,
|
default_fallback_routing,
|
||||||
} = *update;
|
} = *update;
|
||||||
Self {
|
Self {
|
||||||
profile_name,
|
profile_name,
|
||||||
@ -553,7 +556,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
|
|||||||
// order_fulfillment_time_origin,
|
// order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id,
|
frm_routing_algorithm_id,
|
||||||
payout_routing_algorithm_id,
|
payout_routing_algorithm_id,
|
||||||
// default_fallback_routing,
|
default_fallback_routing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BusinessProfileUpdate::RoutingAlgorithmUpdate {
|
BusinessProfileUpdate::RoutingAlgorithmUpdate {
|
||||||
@ -587,7 +590,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
|
|||||||
// order_fulfillment_time_origin: None,
|
// order_fulfillment_time_origin: None,
|
||||||
frm_routing_algorithm_id: None,
|
frm_routing_algorithm_id: None,
|
||||||
payout_routing_algorithm_id,
|
payout_routing_algorithm_id,
|
||||||
// default_fallback_routing: None,
|
default_fallback_routing: None,
|
||||||
},
|
},
|
||||||
BusinessProfileUpdate::ExtendedCardInfoUpdate {
|
BusinessProfileUpdate::ExtendedCardInfoUpdate {
|
||||||
is_extended_card_info_enabled,
|
is_extended_card_info_enabled,
|
||||||
@ -619,7 +622,7 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
|
|||||||
// order_fulfillment_time: None,
|
// order_fulfillment_time: None,
|
||||||
// order_fulfillment_time_origin: None,
|
// order_fulfillment_time_origin: None,
|
||||||
frm_routing_algorithm_id: None,
|
frm_routing_algorithm_id: None,
|
||||||
// default_fallback_routing: None,
|
default_fallback_routing: None,
|
||||||
},
|
},
|
||||||
BusinessProfileUpdate::ConnectorAgnosticMitUpdate {
|
BusinessProfileUpdate::ConnectorAgnosticMitUpdate {
|
||||||
is_connector_agnostic_mit_enabled,
|
is_connector_agnostic_mit_enabled,
|
||||||
@ -651,7 +654,39 @@ impl From<BusinessProfileUpdate> for BusinessProfileUpdateInternal {
|
|||||||
// order_fulfillment_time: None,
|
// order_fulfillment_time: None,
|
||||||
// order_fulfillment_time_origin: None,
|
// order_fulfillment_time_origin: None,
|
||||||
frm_routing_algorithm_id: None,
|
frm_routing_algorithm_id: None,
|
||||||
// default_fallback_routing: None,
|
default_fallback_routing: None,
|
||||||
|
},
|
||||||
|
BusinessProfileUpdate::DefaultRoutingFallbackUpdate {
|
||||||
|
default_fallback_routing,
|
||||||
|
} => Self {
|
||||||
|
profile_name: None,
|
||||||
|
modified_at: now,
|
||||||
|
return_url: None,
|
||||||
|
enable_payment_response_hash: None,
|
||||||
|
payment_response_hash_key: None,
|
||||||
|
redirect_to_merchant_with_http_post: None,
|
||||||
|
webhook_details: None,
|
||||||
|
metadata: None,
|
||||||
|
is_recon_enabled: None,
|
||||||
|
applepay_verified_domains: None,
|
||||||
|
payment_link_config: None,
|
||||||
|
session_expiry: None,
|
||||||
|
authentication_connector_details: None,
|
||||||
|
payout_link_config: None,
|
||||||
|
is_extended_card_info_enabled: None,
|
||||||
|
extended_card_info_config: None,
|
||||||
|
is_connector_agnostic_mit_enabled: None,
|
||||||
|
use_billing_as_payment_method_billing: None,
|
||||||
|
collect_shipping_details_from_wallet_connector: None,
|
||||||
|
collect_billing_details_from_wallet_connector: None,
|
||||||
|
outgoing_webhook_custom_http_headers: None,
|
||||||
|
routing_algorithm_id: None,
|
||||||
|
payout_routing_algorithm_id: None,
|
||||||
|
intent_fulfillment_time: None,
|
||||||
|
// order_fulfillment_time: None,
|
||||||
|
// order_fulfillment_time_origin: None,
|
||||||
|
frm_routing_algorithm_id: None,
|
||||||
|
default_fallback_routing,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -699,7 +734,7 @@ impl super::behaviour::Conversion for BusinessProfile {
|
|||||||
// order_fulfillment_time: self.order_fulfillment_time,
|
// order_fulfillment_time: self.order_fulfillment_time,
|
||||||
// order_fulfillment_time_origin: self.order_fulfillment_time_origin,
|
// order_fulfillment_time_origin: self.order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id: self.frm_routing_algorithm_id,
|
frm_routing_algorithm_id: self.frm_routing_algorithm_id,
|
||||||
// default_fallback_routing: self.default_fallback_routing,
|
default_fallback_routing: self.default_fallback_routing,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -760,7 +795,7 @@ impl super::behaviour::Conversion for BusinessProfile {
|
|||||||
// order_fulfillment_time_origin: item.order_fulfillment_time_origin,
|
// order_fulfillment_time_origin: item.order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id: item.frm_routing_algorithm_id,
|
frm_routing_algorithm_id: item.frm_routing_algorithm_id,
|
||||||
payout_routing_algorithm_id: item.payout_routing_algorithm_id,
|
payout_routing_algorithm_id: item.payout_routing_algorithm_id,
|
||||||
// default_fallback_routing: item.default_fallback_routing,
|
default_fallback_routing: item.default_fallback_routing,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
@ -805,7 +840,7 @@ impl super::behaviour::Conversion for BusinessProfile {
|
|||||||
// order_fulfillment_time_origin: self.order_fulfillment_time_origin,
|
// order_fulfillment_time_origin: self.order_fulfillment_time_origin,
|
||||||
frm_routing_algorithm_id: self.frm_routing_algorithm_id,
|
frm_routing_algorithm_id: self.frm_routing_algorithm_id,
|
||||||
payout_routing_algorithm_id: self.payout_routing_algorithm_id,
|
payout_routing_algorithm_id: self.payout_routing_algorithm_id,
|
||||||
// default_fallback_routing: self.default_fallback_routing,
|
default_fallback_routing: self.default_fallback_routing,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3718,6 +3718,62 @@ impl BusinessProfileWrapper {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_default_fallback_list_of_connector_under_profile(
|
||||||
|
&self,
|
||||||
|
) -> RouterResult<Vec<routing_types::RoutableConnectorChoice>> {
|
||||||
|
use common_utils::ext_traits::OptionExt;
|
||||||
|
use masking::ExposeOptionInterface;
|
||||||
|
|
||||||
|
self.profile
|
||||||
|
.default_fallback_routing
|
||||||
|
.clone()
|
||||||
|
.expose_option()
|
||||||
|
.parse_value::<Vec<routing_types::RoutableConnectorChoice>>(
|
||||||
|
"Vec<RoutableConnectorChoice>",
|
||||||
|
)
|
||||||
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.attach_printable("Merchant default config has invalid structure")
|
||||||
|
}
|
||||||
|
pub fn get_default_routing_configs_from_profile(
|
||||||
|
&self,
|
||||||
|
) -> RouterResult<routing_types::ProfileDefaultRoutingConfig> {
|
||||||
|
let profile_id = self.profile.profile_id.clone();
|
||||||
|
let connectors = self.get_default_fallback_list_of_connector_under_profile()?;
|
||||||
|
|
||||||
|
Ok(routing_types::ProfileDefaultRoutingConfig {
|
||||||
|
profile_id,
|
||||||
|
connectors,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_default_routing_for_profile(
|
||||||
|
self,
|
||||||
|
db: &dyn StorageInterface,
|
||||||
|
updated_config: &Vec<routing_types::RoutableConnectorChoice>,
|
||||||
|
key_manager_state: &KeyManagerState,
|
||||||
|
merchant_key_store: &domain::MerchantKeyStore,
|
||||||
|
) -> RouterResult<()> {
|
||||||
|
let default_fallback_routing = Secret::from(
|
||||||
|
updated_config
|
||||||
|
.encode_to_value()
|
||||||
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.attach_printable("Failed to convert routing ref to value")?,
|
||||||
|
);
|
||||||
|
let business_profile_update = domain::BusinessProfileUpdate::DefaultRoutingFallbackUpdate {
|
||||||
|
default_fallback_routing: Some(default_fallback_routing),
|
||||||
|
};
|
||||||
|
|
||||||
|
db.update_business_profile_by_profile_id(
|
||||||
|
key_manager_state,
|
||||||
|
merchant_key_store,
|
||||||
|
self.profile,
|
||||||
|
business_profile_update,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
|
.attach_printable("Failed to update routing algorithm ref in business profile")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn extended_card_info_toggle(
|
pub async fn extended_card_info_toggle(
|
||||||
|
|||||||
@ -640,7 +640,90 @@ pub async fn unlink_routing_config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//feature update
|
#[cfg(all(
|
||||||
|
feature = "v2",
|
||||||
|
feature = "routing_v2",
|
||||||
|
feature = "business_profile_v2"
|
||||||
|
))]
|
||||||
|
pub async fn update_default_fallback_routing(
|
||||||
|
state: SessionState,
|
||||||
|
merchant_account: domain::MerchantAccount,
|
||||||
|
key_store: domain::MerchantKeyStore,
|
||||||
|
profile_id: String,
|
||||||
|
updated_list_of_connectors: Vec<routing_types::RoutableConnectorChoice>,
|
||||||
|
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
|
||||||
|
metrics::ROUTING_UPDATE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||||
|
let db = state.store.as_ref();
|
||||||
|
let key_manager_state = &(&state).into();
|
||||||
|
let profile = core_utils::validate_and_get_business_profile(
|
||||||
|
db,
|
||||||
|
key_manager_state,
|
||||||
|
&key_store,
|
||||||
|
Some(&profile_id),
|
||||||
|
merchant_account.get_id(),
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.get_required_value("BusinessProfile")?;
|
||||||
|
let profile_wrapper = admin::BusinessProfileWrapper::new(profile);
|
||||||
|
let default_list_of_connectors =
|
||||||
|
profile_wrapper.get_default_fallback_list_of_connector_under_profile()?;
|
||||||
|
|
||||||
|
utils::when(
|
||||||
|
default_list_of_connectors.len() != updated_list_of_connectors.len(),
|
||||||
|
|| {
|
||||||
|
Err(errors::ApiErrorResponse::PreconditionFailed {
|
||||||
|
message: "current config and updated config have different lengths".to_string(),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let existing_set_of_default_connectors: FxHashSet<String> = FxHashSet::from_iter(
|
||||||
|
default_list_of_connectors
|
||||||
|
.iter()
|
||||||
|
.map(|conn_choice| conn_choice.to_string()),
|
||||||
|
);
|
||||||
|
let updated_set_of_default_connectors: FxHashSet<String> = FxHashSet::from_iter(
|
||||||
|
updated_list_of_connectors
|
||||||
|
.iter()
|
||||||
|
.map(|conn_choice| conn_choice.to_string()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let symmetric_diff_between_existing_and_updated_connectors: Vec<String> =
|
||||||
|
existing_set_of_default_connectors
|
||||||
|
.symmetric_difference(&updated_set_of_default_connectors)
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
utils::when(
|
||||||
|
!symmetric_diff_between_existing_and_updated_connectors.is_empty(),
|
||||||
|
|| {
|
||||||
|
Err(errors::ApiErrorResponse::InvalidRequestData {
|
||||||
|
message: format!(
|
||||||
|
"connector mismatch between old and new configs ({})",
|
||||||
|
symmetric_diff_between_existing_and_updated_connectors.join(", ")
|
||||||
|
),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
profile_wrapper
|
||||||
|
.update_default_routing_for_profile(
|
||||||
|
db,
|
||||||
|
&updated_list_of_connectors,
|
||||||
|
key_manager_state,
|
||||||
|
&key_store,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
metrics::ROUTING_UPDATE_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
|
||||||
|
Ok(service_api::ApplicationResponse::Json(
|
||||||
|
updated_list_of_connectors,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
any(feature = "v1", feature = "v2"),
|
||||||
|
not(any(feature = "routing_v2", feature = "business_profile_v2"))
|
||||||
|
))]
|
||||||
pub async fn update_default_routing_config(
|
pub async fn update_default_routing_config(
|
||||||
state: SessionState,
|
state: SessionState,
|
||||||
merchant_account: domain::MerchantAccount,
|
merchant_account: domain::MerchantAccount,
|
||||||
@ -693,6 +776,42 @@ pub async fn update_default_routing_config(
|
|||||||
Ok(service_api::ApplicationResponse::Json(updated_config))
|
Ok(service_api::ApplicationResponse::Json(updated_config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "v2",
|
||||||
|
feature = "routing_v2",
|
||||||
|
feature = "business_profile_v2"
|
||||||
|
))]
|
||||||
|
pub async fn retrieve_default_fallback_algorithm_for_profile(
|
||||||
|
state: SessionState,
|
||||||
|
merchant_account: domain::MerchantAccount,
|
||||||
|
key_store: domain::MerchantKeyStore,
|
||||||
|
profile_id: String,
|
||||||
|
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
|
||||||
|
metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||||
|
let db = state.store.as_ref();
|
||||||
|
let key_manager_state = &(&state).into();
|
||||||
|
let profile = core_utils::validate_and_get_business_profile(
|
||||||
|
db,
|
||||||
|
key_manager_state,
|
||||||
|
&key_store,
|
||||||
|
Some(&profile_id),
|
||||||
|
merchant_account.get_id(),
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.get_required_value("BusinessProfile")?;
|
||||||
|
|
||||||
|
let connectors_choice = admin::BusinessProfileWrapper::new(profile)
|
||||||
|
.get_default_fallback_list_of_connector_under_profile()?;
|
||||||
|
|
||||||
|
metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
|
||||||
|
Ok(service_api::ApplicationResponse::Json(connectors_choice))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
any(feature = "v1", feature = "v2"),
|
||||||
|
not(any(feature = "routing_v2", feature = "business_profile_v2"))
|
||||||
|
))]
|
||||||
|
|
||||||
pub async fn retrieve_default_routing_config(
|
pub async fn retrieve_default_routing_config(
|
||||||
state: SessionState,
|
state: SessionState,
|
||||||
merchant_account: domain::MerchantAccount,
|
merchant_account: domain::MerchantAccount,
|
||||||
@ -712,7 +831,6 @@ pub async fn retrieve_default_routing_config(
|
|||||||
service_api::ApplicationResponse::Json(conn_choice)
|
service_api::ApplicationResponse::Json(conn_choice)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
feature = "v2",
|
feature = "v2",
|
||||||
feature = "routing_v2",
|
feature = "routing_v2",
|
||||||
|
|||||||
@ -1469,21 +1469,8 @@ impl BusinessProfile {
|
|||||||
web::scope("/{profile_id}")
|
web::scope("/{profile_id}")
|
||||||
.service(
|
.service(
|
||||||
web::resource("/fallback_routing")
|
web::resource("/fallback_routing")
|
||||||
.route(web::get().to(|state, req| {
|
.route(web::get().to(routing::routing_retrieve_default_config))
|
||||||
routing::routing_retrieve_default_config(
|
.route(web::post().to(routing::routing_update_default_config)),
|
||||||
state,
|
|
||||||
req,
|
|
||||||
&TransactionType::Payment,
|
|
||||||
)
|
|
||||||
}))
|
|
||||||
.route(web::post().to(|state, req, payload| {
|
|
||||||
routing::routing_update_default_config(
|
|
||||||
state,
|
|
||||||
req,
|
|
||||||
payload,
|
|
||||||
&TransactionType::Payment,
|
|
||||||
)
|
|
||||||
})),
|
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/activate_routing_algorithm").route(web::patch().to(
|
web::resource("/activate_routing_algorithm").route(web::patch().to(
|
||||||
|
|||||||
@ -280,7 +280,55 @@ pub async fn routing_unlink_config(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "olap")]
|
#[cfg(all(
|
||||||
|
feature = "olap",
|
||||||
|
feature = "v2",
|
||||||
|
feature = "routing_v2",
|
||||||
|
feature = "business_profile_v2"
|
||||||
|
))]
|
||||||
|
#[instrument(skip_all)]
|
||||||
|
pub async fn routing_update_default_config(
|
||||||
|
state: web::Data<AppState>,
|
||||||
|
req: HttpRequest,
|
||||||
|
path: web::Path<String>,
|
||||||
|
json_payload: web::Json<Vec<routing_types::RoutableConnectorChoice>>,
|
||||||
|
) -> impl Responder {
|
||||||
|
let wrapper = routing_types::ProfileDefaultRoutingConfig {
|
||||||
|
profile_id: path.into_inner(),
|
||||||
|
connectors: json_payload.into_inner(),
|
||||||
|
};
|
||||||
|
Box::pin(oss_api::server_wrap(
|
||||||
|
Flow::RoutingUpdateDefaultConfig,
|
||||||
|
state,
|
||||||
|
&req,
|
||||||
|
wrapper,
|
||||||
|
|state, auth: auth::AuthenticationData, wrapper, _| {
|
||||||
|
routing::update_default_fallback_routing(
|
||||||
|
state,
|
||||||
|
auth.merchant_account,
|
||||||
|
auth.key_store,
|
||||||
|
wrapper.profile_id,
|
||||||
|
wrapper.updated_config,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
#[cfg(not(feature = "release"))]
|
||||||
|
auth::auth_type(
|
||||||
|
&auth::HeaderAuth(auth::ApiKeyAuth),
|
||||||
|
&auth::JWTAuth(Permission::RoutingWrite),
|
||||||
|
req.headers(),
|
||||||
|
),
|
||||||
|
#[cfg(feature = "release")]
|
||||||
|
&auth::JWTAuth(Permission::RoutingWrite),
|
||||||
|
api_locking::LockAction::NotApplicable,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "olap",
|
||||||
|
any(feature = "v1", feature = "v2"),
|
||||||
|
not(any(feature = "routing_v2", feature = "business_profile_v2"))
|
||||||
|
))]
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
pub async fn routing_update_default_config(
|
pub async fn routing_update_default_config(
|
||||||
state: web::Data<AppState>,
|
state: web::Data<AppState>,
|
||||||
@ -314,7 +362,49 @@ pub async fn routing_update_default_config(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "olap")]
|
#[cfg(all(
|
||||||
|
feature = "olap",
|
||||||
|
feature = "v2",
|
||||||
|
feature = "routing_v2",
|
||||||
|
feature = "business_profile_v2"
|
||||||
|
))]
|
||||||
|
#[instrument(skip_all)]
|
||||||
|
pub async fn routing_retrieve_default_config(
|
||||||
|
state: web::Data<AppState>,
|
||||||
|
req: HttpRequest,
|
||||||
|
path: web::Path<String>,
|
||||||
|
) -> impl Responder {
|
||||||
|
Box::pin(oss_api::server_wrap(
|
||||||
|
Flow::RoutingRetrieveDefaultConfig,
|
||||||
|
state,
|
||||||
|
&req,
|
||||||
|
path.into_inner(),
|
||||||
|
|state, auth: auth::AuthenticationData, profile_id, _| {
|
||||||
|
routing::retrieve_default_fallback_algorithm_for_profile(
|
||||||
|
state,
|
||||||
|
auth.merchant_account,
|
||||||
|
auth.key_store,
|
||||||
|
profile_id,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
#[cfg(not(feature = "release"))]
|
||||||
|
auth::auth_type(
|
||||||
|
&auth::HeaderAuth(auth::ApiKeyAuth),
|
||||||
|
&auth::JWTAuth(Permission::RoutingRead),
|
||||||
|
req.headers(),
|
||||||
|
),
|
||||||
|
#[cfg(feature = "release")]
|
||||||
|
&auth::JWTAuth(Permission::RoutingRead),
|
||||||
|
api_locking::LockAction::NotApplicable,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "olap",
|
||||||
|
any(feature = "v1", feature = "v2"),
|
||||||
|
not(any(feature = "routing_v2", feature = "business_profile_v2"))
|
||||||
|
))]
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
pub async fn routing_retrieve_default_config(
|
pub async fn routing_retrieve_default_config(
|
||||||
state: web::Data<AppState>,
|
state: web::Data<AppState>,
|
||||||
|
|||||||
@ -1,18 +1,22 @@
|
|||||||
-- This adds back dropped columns in `up.sql`.
|
-- This adds back dropped columns in `up.sql`.
|
||||||
-- However, if the old columns were dropped, then we won't have data previously
|
-- However, if the old columns were dropped, then we won't have data previously
|
||||||
-- stored in these columns.
|
-- stored in these columns.
|
||||||
ALTER TABLE business_profile
|
ALTER TABLE
|
||||||
ADD COLUMN routing_algorithm JSON DEFAULT NULL,
|
business_profile
|
||||||
|
ADD
|
||||||
|
COLUMN routing_algorithm JSON DEFAULT NULL,
|
||||||
-- ADD COLUMN intent_fulfillment_time BIGINT DEFAULT NULL,
|
-- ADD COLUMN intent_fulfillment_time BIGINT DEFAULT NULL,
|
||||||
ADD COLUMN frm_routing_algorithm JSONB DEFAULT NULL,
|
ADD
|
||||||
ADD COLUMN payout_routing_algorithm JSONB DEFAULT NULL;
|
COLUMN frm_routing_algorithm JSONB DEFAULT NULL,
|
||||||
|
ADD
|
||||||
|
COLUMN payout_routing_algorithm JSONB DEFAULT NULL;
|
||||||
|
|
||||||
ALTER TABLE business_profile
|
ALTER TABLE
|
||||||
DROP COLUMN routing_algorithm_id,
|
business_profile DROP COLUMN routing_algorithm_id,
|
||||||
-- DROP COLUMN order_fulfillment_time,
|
-- DROP COLUMN order_fulfillment_time,
|
||||||
-- DROP COLUMN order_fulfillment_time_origin,
|
-- DROP COLUMN order_fulfillment_time_origin,
|
||||||
DROP COLUMN frm_routing_algorithm_id,
|
DROP COLUMN frm_routing_algorithm_id,
|
||||||
DROP COLUMN payout_routing_algorithm_id;
|
DROP COLUMN payout_routing_algorithm_id,
|
||||||
-- DROP COLUMN default_fallback_routing;
|
DROP COLUMN default_fallback_routing;
|
||||||
|
|
||||||
-- DROP TYPE "OrderFulfillmentTimeOrigin";
|
-- DROP TYPE "OrderFulfillmentTimeOrigin";
|
||||||
@ -1,17 +1,21 @@
|
|||||||
-- CREATE TYPE "OrderFulfillmentTimeOrigin" AS ENUM ('create', 'confirm');
|
-- CREATE TYPE "OrderFulfillmentTimeOrigin" AS ENUM ('create', 'confirm');
|
||||||
|
ALTER TABLE
|
||||||
ALTER TABLE business_profile
|
business_profile
|
||||||
ADD COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
|
ADD
|
||||||
-- ADD COLUMN order_fulfillment_time BIGINT DEFAULT NULL,
|
COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
|
||||||
-- ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
|
-- ADD COLUMN order_fulfillment_time BIGINT DEFAULT NULL,
|
||||||
ADD COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
|
-- ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
|
||||||
ADD COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL;
|
ADD
|
||||||
-- ADD COLUMN default_fallback_routing JSONB DEFAULT NULL;
|
COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
|
||||||
|
ADD
|
||||||
|
COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
|
||||||
|
ADD
|
||||||
|
COLUMN default_fallback_routing JSONB DEFAULT NULL;
|
||||||
|
|
||||||
-- Note: This query should not be run on higher environments as this leads to data loss.
|
-- Note: This query should not be run on higher environments as this leads to data loss.
|
||||||
-- The application will work fine even without these queries being run.
|
-- The application will work fine even without these queries being run.
|
||||||
ALTER TABLE business_profile
|
ALTER TABLE
|
||||||
DROP COLUMN routing_algorithm,
|
business_profile DROP COLUMN routing_algorithm,
|
||||||
-- DROP COLUMN intent_fulfillment_time,
|
-- DROP COLUMN intent_fulfillment_time,
|
||||||
DROP COLUMN frm_routing_algorithm,
|
DROP COLUMN frm_routing_algorithm,
|
||||||
DROP COLUMN payout_routing_algorithm;
|
DROP COLUMN payout_routing_algorithm;
|
||||||
Reference in New Issue
Block a user