text
stringlengths
70
351k
source
stringclasses
4 values
// file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::routing::DynamicRoutingAlgoAccessor; use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn retrieve_routing_algorithm_from_algorithm_id( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, authentication_profile_id: Option<common_utils::id_type::ProfileId>, algorithm_id: common_utils::id_type::RoutingId, ) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> { metrics::ROUTING_RETRIEVE_CONFIG.add(1, &[]); let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let routing_algorithm = RoutingAlgorithmUpdate::fetch_routing_algo(merchant_account.get_id(), &algorithm_id, db) .await?; let business_profile = core_utils::validate_and_get_business_profile( db, key_manager_state, &key_store, Some(&routing_algorithm.0.profile_id), merchant_account.get_id(), ) .await? .get_required_value("Profile") .change_context(errors::ApiErrorResponse::ResourceIdNotFound)?; core_utils::validate_profile_id_from_auth_layer(authentication_profile_id, &business_profile)?; let response = routing_types::MerchantRoutingAlgorithm::foreign_try_from(routing_algorithm.0) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("unable to parse routing algorithm")?; metrics::ROUTING_RETRIEVE_CONFIG_SUCCESS_RESPONSE.add(1, &[]); Ok(service_api::ApplicationResponse::Json(response)) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router let record = db .insert_routing_algorithm(algo) .await .to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?; let new_record = record.foreign_into(); metrics::ROUTING_CREATE_SUCCESS_RESPONSE.add(1, &[]); Ok(service_api::ApplicationResponse::Json(new_record)) } #[cfg(feature = "v2")] pub async fn link_routing_config_under_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, profile_id: common_utils::id_type::ProfileId, algorithm_id: common_utils::id_type::RoutingId, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { metrics::ROUTING_LINK_CONFIG.add(1, &[]); let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let routing_algorithm = pub async fn link_routing_config_under_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, profile_id: common_utils::id_type::ProfileId, algorithm_id: common_utils::id_type::RoutingId, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn create_routing_algorithm_under_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, authentication_profile_id: Option<common_utils::id_type::ProfileId>, request: routing_types::RoutingConfigRequest, transaction_type: enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use super::payouts; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::utils::ValueExt; use crate::{core::admin, utils::ValueExt}; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn retrieve_merchant_routing_dictionary( state: SessionState, merchant_account: domain::MerchantAccount, profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>, query_params: RoutingRetrieveQuery, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::RoutingKind> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router pub trait GetRoutableConnectorsForChoice { async fn get_routable_connectors( &self, db: &dyn StorageInterface, business_profile: &domain::Profile, ) -> RouterResult<RoutableConnectors>; } pub struct StraightThroughAlgorithmTypeSingle(pub serde_json::Value); #[async_trait] impl GetRoutableConnectorsForChoice for StraightThroughAlgorithmTypeSingle { async fn get_routable_connectors( &self, _db: &dyn StorageInterface, _business_profile: &domain::Profile, ) -> RouterResult<RoutableConnectors> { let straight_through_routing_algorithm = self .0 .clone() .parse_value::<api::routing::StraightThroughAlgorithm>("RoutingAlgorithm") .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to parse the straight through routing algorithm")?; let routable_connector = match straight_through_routing_algorithm { api::routing::StraightThroughAlgorithm::Single(connector) => { async fn get_routable_connectors( &self, _db: &dyn StorageInterface, _business_profile: &domain::Profile, ) -> RouterResult<RoutableConnectors> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router .await .change_context(errors::ApiErrorResponse::GenericNotFoundError { message: "Failed to invalidate the routing keys".to_string(), }) }) .await .transpose()?; Ok(service_api::ApplicationResponse::Json(new_record)) } #[cfg(all(feature = "v1", feature = "dynamic_routing"))] pub async fn contract_based_dynamic_routing_setup( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, profile_id: common_utils::id_type::ProfileId, feature_to_enable: routing_types::DynamicRoutingFeatures, config: Option<routing_types::ContractBasedRoutingConfig>, ) -> RouterResult<service_api::ApplicationResponse<routing_types::RoutingDictionaryRecord>> { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let business_profile: domain::Profile = core_utils::validate_and_get_business_profile( db, pub async fn contract_based_dynamic_routing_setup( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, profile_id: common_utils::id_type::ProfileId, feature_to_enable: routing_types::DynamicRoutingFeatures, config: Option<routing_types::ContractBasedRoutingConfig>, ) -> RouterResult<service_api::ApplicationResponse<routing_types::RoutingDictionaryRecord>> { {let db = state.store.as_ref();<|fim_suffix|> <|fim_middle|> Ok(service_api::ApplicationResponse::Json(new_record))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use std::collections::HashSet; use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub fn filter_network_transaction_id_flow_supported_connectors( self, nit_connectors: HashSet<String>, ) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; async fn get_routable_connectors( &self, db: &dyn StorageInterface, business_profile: &domain::Profile, ) -> RouterResult<RoutableConnectors> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn retrieve_default_routing_config( state: SessionState, profile_id: Option<common_utils::id_type::ProfileId>, merchant_account: domain::MerchantAccount, transaction_type: &enums::TransactionType, ) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use crate::{core::admin, utils::ValueExt}; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn retrieve_default_fallback_algorithm_for_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, profile_id: common_utils::id_type::ProfileId, ) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use common_utils::ext_traits::AsyncExt; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn fetch_routing_algo( merchant_id: &common_utils::id_type::MerchantId, algorithm_id: &common_utils::id_type::RoutingId, db: &dyn StorageInterface, ) -> RouterResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub fn create_new_routing_algorithm( request: &routing_types::RoutingConfigRequest, merchant_id: &common_utils::id_type::MerchantId, profile_id: common_utils::id_type::ProfileId, transaction_type: enums::TransactionType, ) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use hyperswitch_domain_models::{mandates, payment_address}; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub fn new( setup_mandate: Option<&'a mandates::MandateData>, payment_attempt: &'a storage::PaymentAttempt, payment_intent: &'a storage::PaymentIntent, payment_method_data: Option<&'a domain::PaymentMethodData>, address: &'a payment_address::PaymentAddress, recurring_details: Option<&'a mandates_api::RecurringDetails>, currency: storage_enums::Currency, ) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::routing::DynamicRoutingAlgoAccessor; use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use error_stack::ResultExt; use external_services::grpc_client::dynamic_routing::{ contract_routing_client::ContractBasedDynamicRouting, success_rate_client::SuccessBasedDynamicRouting, }; use router_env::logger; use storage_impl::redis::cache; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::utils::ValueExt; use crate::{core::admin, utils::ValueExt}; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn contract_based_routing_update_configs( state: SessionState, request: routing_types::ContractBasedRoutingConfig, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, algorithm_id: common_utils::id_type::RoutingId, profile_id: common_utils::id_type::ProfileId, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { {metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE.add( 1, router_env::metric_attributes!(("profile_id", profile_id.get_string_repr().to_owned())), );<|fim_suffix|> <|fim_middle|> Ok(service_api::ApplicationResponse::Json(new_record))}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::routing::DynamicRoutingAlgoAccessor; use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use external_services::grpc_client::dynamic_routing::{ contract_routing_client::ContractBasedDynamicRouting, success_rate_client::SuccessBasedDynamicRouting, }; use router_env::logger; use storage_impl::redis::cache; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn success_based_routing_update_configs( state: SessionState, request: routing_types::SuccessBasedRoutingConfig, algorithm_id: common_utils::id_type::RoutingId, profile_id: common_utils::id_type::ProfileId, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use rustc_hash::FxHashSet; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::utils::ValueExt; use crate::{core::admin, utils::ValueExt}; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn update_default_routing_config_for_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, updated_config: Vec<routing_types::RoutableConnectorChoice>, profile_id: common_utils::id_type::ProfileId, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::ProfileDefaultRoutingConfig> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::routing::DynamicRoutingAlgoAccessor; use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use super::payouts; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn unlink_routing_config( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, request: routing_types::RoutingConfigRequest, authentication_profile_id: Option<common_utils::id_type::ProfileId>, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn create_routing_algorithm_under_profile( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, authentication_profile_id: Option<common_utils::id_type::ProfileId>, request: routing_types::RoutingConfigRequest, transaction_type: enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { metrics::ROUTING_CREATE_REQUEST_RECEIVED.add(1, &[]); let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let name = request .name .get_required_value("name") .change_context(errors::ApiErrorResponse::MissingRequiredField { field_name: "name" }) .attach_printable("Name of config not given")?; let description = request .description .get_required_value("description") .change_context(errors::ApiErrorResponse::MissingRequiredField { field_name: "description", }) .attach_printable("Description of config not given")?; let algorithm = request .algorithm .get_required_value("algorithm") .change_context(errors::ApiErrorResponse::MissingRequiredField { field_name: "algorithm", }) .attach_printable("Algorithm of config not given")?; let algorithm_id = common_utils::generate_routing_id_of_default_length(); let profile_id = request .profile_id .get_required_value("profile_id") .change_context(errors::ApiErrorResponse::MissingRequiredField { field_name: "profile_id", }) .attach_printable("Profile_id not provided")?; let business_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("Profile")?; core_utils::validate_profile_id_from_auth_layer(authentication_profile_id, &business_profile)?; helpers::validate_connectors_in_routing_config( &state, &key_store, merchant_account.get_id(), &profile_id, &algorithm, ) .await?; let timestamp = common_utils::date_time::now(); let algo = RoutingAlgorithm { algorithm_id: algorithm_id.clone(), profile_id, merchant_id: merchant_account.get_id().to_owned(), name: name.clone(), description: Some(description.clone()), kind: algorithm.get_kind().foreign_into(), algorithm_data: serde_json::json!(algorithm), created_at: timestamp, modified_at: timestamp, algorithm_for: transaction_type.to_owned(), }; let record = db .insert_routing_algorithm(algo) .await .to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?; let new_record = record.foreign_into(); metrics::ROUTING_CREATE_SUCCESS_RESPONSE.add(1, &[]); Ok(service_api::ApplicationResponse::Json(new_record)) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router use api_models::routing::DynamicRoutingAlgoAccessor; use api_models::{ enums, mandates as mandates_api, routing, routing::{self as routing_types, RoutingRetrieveQuery}, }; use common_utils::ext_traits::AsyncExt; use diesel_models::routing_algorithm::RoutingAlgorithm; use error_stack::ResultExt; use router_env::logger; use super::{ errors::RouterResult, payments::{ routing::{self as payments_routing}, OperationSessionGetters, }, }; use crate::utils::ValueExt; use crate::{core::admin, utils::ValueExt}; use crate::{ core::{ errors::{self, CustomResult, RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, db::StorageInterface, routes::SessionState, services::api as service_api, types::{ api, domain, storage::{self, enums as storage_enums}, transformers::{ForeignInto, ForeignTryFrom}, }, utils::{self, OptionExt}, }; pub async fn contract_based_dynamic_routing_setup( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, profile_id: common_utils::id_type::ProfileId, feature_to_enable: routing_types::DynamicRoutingFeatures, config: Option<routing_types::ContractBasedRoutingConfig>, ) -> RouterResult<service_api::ApplicationResponse<routing_types::RoutingDictionaryRecord>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/routing.rs | crate: router algorithm_id, transaction_type, ) .await?; metrics::ROUTING_LINK_CONFIG_SUCCESS_RESPONSE.add(1, &[]); Ok(service_api::ApplicationResponse::Json( routing_algorithm.0.foreign_into(), )) } #[cfg(feature = "v1")] pub async fn link_routing_config( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, authentication_profile_id: Option<common_utils::id_type::ProfileId>, algorithm_id: common_utils::id_type::RoutingId, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { metrics::ROUTING_LINK_CONFIG.add(1, &[]); let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let routing_algorithm = db pub async fn link_routing_config( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, authentication_profile_id: Option<common_utils::id_type::ProfileId>, algorithm_id: common_utils::id_type::RoutingId, transaction_type: &enums::TransactionType, ) -> RouterResponse<routing_types::RoutingDictionaryRecord> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use analytics::health_check::HealthCheck; use api_models::health_check::HealthState; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_analytics( &self, ) -> CustomResult<HealthState, errors::HealthCheckDBError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use api_models::health_check::HealthState; use router_env::logger; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_redis(&self) -> CustomResult<HealthState, errors::HealthCheckRedisError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use analytics::health_check::HealthCheck; use api_models::health_check::HealthState; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_analytics( &self, ) -> CustomResult<HealthState, errors::HealthCheckDBError> { { analytics::AnalyticsProvider::Sqlx(client) => client .deep_health_check() .await .change_context(errors::HealthCheckDBError::SqlxAnalyticsError),<|fim_suffix|> <|fim_middle|> analytics::AnalyticsProvider::CombinedSqlx(sqlx_client, ckh_client) => { sqlx_client .deep_health_check() .await .change_context(errors::HealthCheckDBError::SqlxAnalyticsError)?; ckh_client .deep_health_check() .await .change_context(errors::HealthCheckDBError::ClickhouseAnalyticsError) } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use api_models::health_check::HealthCheckMap; use router_env::logger; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_grpc( &self, ) -> CustomResult<HealthCheckMap, errors::HealthCheckGRPCServiceError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use api_models::health_check::HealthState; use router_env::logger; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_outgoing( &self, ) -> CustomResult<HealthState, errors::HealthCheckOutGoing> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use api_models::health_check::HealthState; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_opensearch( &self, ) -> CustomResult<HealthState, errors::HealthCheckDBError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use api_models::health_check::HealthState; use error_stack::ResultExt; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_locker( &self, ) -> CustomResult<HealthState, errors::HealthCheckLockerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/health_check.rs | crate: router use api_models::health_check::HealthState; use crate::{ consts, core::errors::{self, CustomResult}, routes::app, services::api as services, }; async fn health_check_db(&self) -> CustomResult<HealthState, errors::HealthCheckDBError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/apple_pay_certificates_migration.rs | crate: router use api_models::apple_pay_certificates_migration; use common_utils::{errors::CustomResult, type_name, types::keymanager::Identifier}; use masking::{PeekInterface, Secret}; use super::{ errors::{self, StorageErrorExt}, payments::helpers, }; use crate::{ routes::SessionState, services::{self, logger}, types::{domain::types as domain_types, storage}, }; pub async fn apple_pay_certificates_migration( state: SessionState, req: &apple_pay_certificates_migration::ApplePayCertificatesMigrationRequest, ) -> CustomResult< services::ApplicationResponse< apple_pay_certificates_migration::ApplePayCertificatesMigrationResponse, >, errors::ApiErrorResponse, > { { Ok(_) => { logger::debug!( "Merchant connector accounts updated for merchant id {merchant_id:?}" ); migration_successful_merchant_ids.push(merchant_id.clone()); }<|fim_suffix|> <|fim_middle|> Err(error) => { logger::debug!( "Merchant connector accounts update failed with error {error} for merchant id {merchant_id:?}"); migration_failed_merchant_ids.push(merchant_id.clone()); } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/apple_pay_certificates_migration.rs | crate: router use api_models::apple_pay_certificates_migration; use common_utils::{errors::CustomResult, type_name, types::keymanager::Identifier}; use masking::{PeekInterface, Secret}; use super::{ errors::{self, StorageErrorExt}, payments::helpers, }; use crate::{ routes::SessionState, services::{self, logger}, types::{domain::types as domain_types, storage}, }; pub async fn apple_pay_certificates_migration( state: SessionState, req: &apple_pay_certificates_migration::ApplePayCertificatesMigrationRequest, ) -> CustomResult< services::ApplicationResponse< apple_pay_certificates_migration::ApplePayCertificatesMigrationResponse, >, errors::ApiErrorResponse, > { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; use crate::{ core::payments, routes::SessionState, services, types::{ api::{self}, domain, }, utils::OptionExt, }; pub async fn sync_relay_refund_with_gateway( state: &SessionState, merchant_account: &domain::MerchantAccount, relay_record: &relay::Relay, connector_account: domain::MerchantConnectorAccount, ) -> RouterResult<relay::RelayUpdate> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use common_utils::{ self, fp_utils, id_type::{self, GenerateId}, }; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; use crate::{ core::payments, routes::SessionState, services, types::{ api::{self}, domain, }, utils::OptionExt, }; pub async fn relay<T: RelayInterface>( state: SessionState, merchant_account: domain::MerchantAccount, profile_id_optional: Option<id_type::ProfileId>, key_store: domain::MerchantKeyStore, req: RelayRequestInner<T>, ) -> RouterResponse<relay_api_models::RelayResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; fn generate_response(value: relay::Relay) -> RouterResult<api_models::relay::RelayResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; use crate::{ core::payments, routes::SessionState, services, types::{ api::{self}, domain, }, utils::OptionExt, }; async fn process_relay( state: &SessionState, merchant_account: domain::MerchantAccount, connector_account: domain::MerchantConnectorAccount, relay_record: &relay::Relay, ) -> RouterResult<relay::RelayUpdate> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use common_enums::RelayStatus; use common_utils::{ self, fp_utils, id_type::{self, GenerateId}, }; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; use crate::{ core::payments, routes::SessionState, services, types::{ api::{self}, domain, }, utils::OptionExt, }; pub async fn relay_retrieve( state: SessionState, merchant_account: domain::MerchantAccount, profile_id_optional: Option<id_type::ProfileId>, key_store: domain::MerchantKeyStore, req: relay_api_models::RelayRetrieveRequest, ) -> RouterResponse<relay_api_models::RelayResponse> { { Err(error) => { if error.current_context().is_db_not_found() { Err(error).change_context(errors::ApiErrorResponse::GenericNotFoundError { message: "relay not found".to_string(), })? } else { Err(error) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("error while fetch relay record")? } }<|fim_suffix|> <|fim_middle|> Ok(relay) => relay, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use std::marker::PhantomData; use api_models::relay as relay_api_models; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; pub fn from_relay_request(relay_request: relay_api_models::RelayRequest) -> RouterResult<Self> { { Some(relay_api_models::RelayData::Refund(ref_data)) => Ok(Self { connector_resource_id: relay_request.connector_resource_id, connector_id: relay_request.connector_id, relay_type: PhantomData, data: ref_data, }),<|fim_suffix|> <|fim_middle|> None => Err(errors::ApiErrorResponse::InvalidRequestData { message: "Relay data is required for relay type refund".to_string(), })?, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use common_enums::RelayStatus; use hyperswitch_domain_models::relay; fn should_call_connector_for_relay_refund_status(relay: &relay::Relay, force_sync: bool) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use common_enums::RelayStatus; use common_utils::{ self, fp_utils, id_type::{self, GenerateId}, }; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; use crate::{ core::payments, routes::SessionState, services, types::{ api::{self}, domain, }, utils::OptionExt, }; pub async fn relay_flow_decider( state: SessionState, merchant_account: domain::MerchantAccount, profile_id_optional: Option<id_type::ProfileId>, key_store: domain::MerchantKeyStore, request: relay_api_models::RelayRequest, ) -> RouterResponse<relay_api_models::RelayResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use common_enums::RelayStatus; use common_utils::{ self, fp_utils, id_type::{self, GenerateId}, }; use hyperswitch_domain_models::relay; fn get_domain_models( relay_request: RelayRequestInner<Self>, merchant_id: &id_type::MerchantId, profile_id: &id_type::ProfileId, ) -> relay::Relay { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/relay.rs | crate: router use std::marker::PhantomData; use api_models::relay as relay_api_models; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; pub fn from_relay_request(relay_request: relay_api_models::RelayRequest) -> RouterResult<Self> { match relay_request.data { Some(relay_api_models::RelayData::Refund(ref_data)) => Ok(Self { connector_resource_id: relay_request.connector_resource_id, connector_id: relay_request.connector_id, relay_type: PhantomData, data: ref_data, }), None => Err(errors::ApiErrorResponse::InvalidRequestData { message: "Relay data is required for relay type refund".to_string(), })?, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; fn validate_relay_request(req: &Self::Request) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/relay.rs | crate: router use api_models::relay as relay_api_models; use common_enums::RelayStatus; use common_utils::{ self, fp_utils, id_type::{self, GenerateId}, }; use hyperswitch_domain_models::relay; use super::errors::{self, ConnectorErrorExt, RouterResponse, RouterResult, StorageErrorExt}; use crate::{ core::payments, routes::SessionState, services, types::{ api::{self}, domain, }, utils::OptionExt, }; pub async fn relay_retrieve( state: SessionState, merchant_account: domain::MerchantAccount, profile_id_optional: Option<id_type::ProfileId>, key_store: domain::MerchantKeyStore, req: relay_api_models::RelayRetrieveRequest, ) -> RouterResponse<relay_api_models::RelayResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use common_utils::{ext_traits::Encode, id_type}; use error_stack::{report, ResultExt}; use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; pub async fn get_customer_mandates( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, customer_id: id_type::CustomerId, ) -> RouterResponse<Vec<mandates::MandateResponse>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use common_utils::{ext_traits::Encode, id_type}; use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; pub async fn update_connector_mandate_id( db: &dyn StorageInterface, merchant_id: &id_type::MerchantId, mandate_ids_opt: Option<String>, payment_method_id: Option<String>, resp: Result<types::PaymentsResponseData, types::ErrorResponse>, storage_scheme: MerchantStorageScheme, ) -> RouterResponse<mandates::MandateResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; pub async fn get_mandate( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: mandates::MandateId, ) -> RouterResponse<mandates::MandateResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router fn get_insensitive_payment_method_data_if_exists<F, FData>( router_data: &types::RouterData<F, FData, types::PaymentsResponseData>, ) -> Option<domain::PaymentMethodData> where FData: MandateBehaviour, { match &router_data.request.get_payment_method_data() { domain::PaymentMethodData::Card(_) => None, _ => Some(router_data.request.get_payment_method_data()), } } pub async fn mandate_procedure<F, FData>( state: &SessionState, resp: &types::RouterData<F, FData, types::PaymentsResponseData>, customer_id: &Option<id_type::CustomerId>, pm_id: Option<String>, merchant_connector_id: Option<id_type::MerchantConnectorAccountId>, storage_scheme: MerchantStorageScheme, payment_id: &id_type::PaymentId, ) -> errors::RouterResult<Option<String>> where FData: MandateBehaviour, { let Ok(ref response) = resp.response else { pub async fn mandate_procedure<F, FData>( state: &SessionState, resp: &types::RouterData<F, FData, types::PaymentsResponseData>, customer_id: &Option<id_type::CustomerId>, pm_id: Option<String>, merchant_connector_id: Option<id_type::MerchantConnectorAccountId>, storage_scheme: MerchantStorageScheme, payment_id: &id_type::PaymentId, ) -> errors::RouterResult<Option<String>> where FData: MandateBehaviour, { { types::PaymentsResponseData::TransactionResponse { mandate_reference, network_txn_id, .. } => (mandate_reference.clone(), network_txn_id.clone()),<|fim_suffix|> <|fim_middle|> _ => (Box::new(None), None), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; fn foreign_from(resp: Result<types::PaymentsResponseData, types::ErrorResponse>) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use api_models::payments; use futures::future; use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; pub async fn retrieve_mandates_list( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, constraints: api_models::mandates::MandateListConstraints, ) -> RouterResponse<Vec<api_models::mandates::MandateResponse>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; fn get_insensitive_payment_method_data_if_exists<F, FData>( router_data: &types::RouterData<F, FData, types::PaymentsResponseData>, ) -> Option<domain::PaymentMethodData> where FData: MandateBehaviour, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use common_utils::{ext_traits::Encode, id_type}; use diesel_models::enums as storage_enums; use router_env::{instrument, logger, tracing}; use super::payments::helpers as payment_helper; use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; pub async fn mandate_procedure<F, FData>( state: &SessionState, resp: &types::RouterData<F, FData, types::PaymentsResponseData>, customer_id: &Option<id_type::CustomerId>, pm_id: Option<String>, merchant_connector_id: Option<id_type::MerchantConnectorAccountId>, storage_scheme: MerchantStorageScheme, payment_id: &id_type::PaymentId, ) -> errors::RouterResult<Option<String>> where FData: MandateBehaviour, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/mandate.rs | crate: router use diesel_models::enums as storage_enums; use super::payments::helpers as payment_helper; use crate::{ core::{ errors::{self, RouterResponse, StorageErrorExt}, payments::CallConnectorAction, }, db::StorageInterface, routes::{metrics, SessionState}, services, types::{ self, api::{ mandates::{self, MandateResponseExt}, ConnectorData, GetToken, }, domain, storage::{self, enums::MerchantStorageScheme}, transformers::ForeignFrom, }, utils::OptionExt, }; pub async fn revoke_mandate( state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: mandates::MandateId, ) -> RouterResponse<mandates::MandateRevokedResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; /// Filter Objects based on profile ids pub(super) fn filter_objects_based_on_profile_id_list< T: GetProfileId, U: IntoIterator<Item = T> + FromIterator<T>, >( profile_id_list_auth_layer: Option<Vec<common_utils::id_type::ProfileId>>, object_list: U, ) -> U { if let Some(profile_id_list) = profile_id_list_auth_layer { let profile_ids_to_filter: HashSet<_> = profile_id_list.iter().collect(); object_list .into_iter() .filter_map(|item| { if item .get_profile_id() .is_some_and(|profile_id| profile_ids_to_filter.contains(profile_id)) { Some(item) } else { None } }) .collect() } else { object_list } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use error_stack::{report, ResultExt}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn get_profile_id_from_business_details( key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, business_country: Option<api_models::enums::CountryAlpha2>, business_label: Option<&String>, merchant_account: &domain::MerchantAccount, request_profile_id: Option<&common_utils::id_type::ProfileId>, db: &dyn StorageInterface, should_validate: bool, ) -> RouterResult<common_utils::id_type::ProfileId> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; /// Create the connector label /// { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; /// Validate whether the profile_id exists and is associated with the merchant_id pub async fn validate_and_get_business_profile( db: &dyn StorageInterface, key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, profile_id: Option<&common_utils::id_type::ProfileId>, merchant_id: &common_utils::id_type::MerchantId, ) -> RouterResult<Option<domain::Profile>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn test_filter_objects_based_on_profile_id_list() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router message: "Couldn't find profile_id in record for authentication".to_string(), } .into(), ) .attach_printable(format!("Couldn't find profile_id in entity {:?}", object)), (None, None) | (None, Some(_)) => Ok(()), } } pub(crate) trait ValidatePlatformMerchant { fn get_platform_merchant_id(&self) -> Option<&common_utils::id_type::MerchantId>; fn validate_platform_merchant( &self, auth_platform_merchant_id: Option<&common_utils::id_type::MerchantId>, ) -> CustomResult<(), errors::ApiErrorResponse> { let data_platform_merchant_id = self.get_platform_merchant_id(); match (data_platform_merchant_id, auth_platform_merchant_id) { (Some(data_platform_merchant_id), Some(auth_platform_merchant_id)) => { common_utils::fp_utils::when( data_platform_merchant_id != auth_platform_merchant_id, || { Err(report!(errors::ApiErrorResponse::PaymentNotFound)).attach_printable(format!( "Data platform merchant id: {data_platform_merchant_id:?} does not match with auth platform merchant id: {auth_platform_merchant_id:?}")) }, fn validate_platform_merchant( &self, auth_platform_merchant_id: Option<&common_utils::id_type::MerchantId>, ) -> CustomResult<(), errors::ApiErrorResponse> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router { Some(item) } else { None } }) .collect() } else { object_list } } pub(crate) fn validate_profile_id_from_auth_layer<T: GetProfileId + std::fmt::Debug>( profile_id_auth_layer: Option<common_utils::id_type::ProfileId>, object: &T, ) -> RouterResult<()> { match (profile_id_auth_layer, object.get_profile_id()) { (Some(auth_profile_id), Some(object_profile_id)) => { auth_profile_id.eq(object_profile_id).then_some(()).ok_or( errors::ApiErrorResponse::PreconditionFailed { message: "Profile id authentication failed. Please use the correct JWT token" .to_string(), } .into(), ) pub(crate) fn validate_profile_id_from_auth_layer<T: GetProfileId + std::fmt::Debug>( profile_id_auth_layer: Option<common_utils::id_type::ProfileId>, object: &T, ) -> RouterResult<()> { { (Some(auth_profile_id), Some(object_profile_id)) => { auth_profile_id.eq(object_profile_id).then_some(()).ok_or( errors::ApiErrorResponse::PreconditionFailed { message: "Profile id authentication failed. Please use the correct JWT token" .to_string(), } .into(), ) }<|fim_suffix|> <|fim_middle|> (None, None) | (None, Some(_)) => Ok(()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn get_platform_merchant_id(&self) -> Option<&common_utils::id_type::MerchantId> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use error_stack::{report, ResultExt}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn validate_platform_merchant( &self, auth_platform_merchant_id: Option<&common_utils::id_type::MerchantId>, ) -> CustomResult<(), errors::ApiErrorResponse> { { (Some(data_platform_merchant_id), Some(auth_platform_merchant_id)) => { common_utils::fp_utils::when( data_platform_merchant_id != auth_platform_merchant_id, || { Err(report!(errors::ApiErrorResponse::PaymentNotFound)).attach_printable(format!( "Data platform merchant id: {data_platform_merchant_id:?} does not match with auth platform merchant id: {auth_platform_merchant_id:?}")) }, ) }<|fim_suffix|> <|fim_middle|> (None, None) => Ok(()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use common_enums::{IntentStatus, RequestIncrementalAuthorization}; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use error_stack::{report, ResultExt}; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use masking::{ExposeInterface, PeekInterface}; use maud::{html, PreEscaped}; use router_env::{instrument, tracing}; use uuid::Uuid; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::core::payments; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub(crate) fn validate_profile_id_from_auth_layer<T: GetProfileId + std::fmt::Debug>( profile_id_auth_layer: Option<common_utils::id_type::ProfileId>, object: &T, ) -> RouterResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_enums::{IntentStatus, RequestIncrementalAuthorization}; pub fn get_incremental_authorization_allowed_value( incremental_authorization_allowed: Option<bool>, request_incremental_authorization: Option<RequestIncrementalAuthorization>, ) -> Option<bool> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_enums::{IntentStatus, RequestIncrementalAuthorization}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn get_request_incremental_authorization_value( request_incremental_authorization: Option<bool>, capture_method: Option<common_enums::CaptureMethod>, ) -> RouterResult<Option<RequestIncrementalAuthorization>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn get_flow_name<F>() -> RouterResult<String> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; pub fn get_external_authentication_request_poll_id( payment_id: &common_utils::id_type::PaymentId, ) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; pub fn get_poll_id(merchant_id: &common_utils::id_type::MerchantId, unique_id: String) -> String { merchant_id.get_poll_id(&unique_id) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn connector_needs_business_sub_label(connector_name: &str) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use crate::core::payments; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn get_connector_request_reference_id( conf: &Settings, merchant_id: &common_utils::id_type::MerchantId, payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt, ) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn is_merchant_enabled_for_payment_id_as_connector_request_id( conf: &Settings, merchant_id: &common_utils::id_type::MerchantId, ) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use api_models::enums::{DisputeStage, DisputeStatus}; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn validate_dispute_stage_and_dispute_status( prev_dispute_stage: DisputeStage, prev_dispute_status: DisputeStatus, dispute_stage: DisputeStage, dispute_status: DisputeStatus, ) -> CustomResult<(), errors::WebhooksFlowError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use api_models::enums::{DisputeStage, DisputeStatus}; pub fn validate_dispute_status( prev_dispute_status: DisputeStatus, dispute_status: DisputeStatus, ) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use api_models::enums::{DisputeStage, DisputeStatus}; pub fn validate_dispute_stage( prev_dispute_stage: DisputeStage, dispute_stage: DisputeStage, ) -> bool { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; fn new_profile_id(profile_id: &'static str) -> common_utils::id_type::ProfileId { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; pub fn new(profile_id: &'static str) -> Self { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn test_generate_id() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router fn validate_id_proper_response() { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router fn validate_id_length_constraint() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use uuid::Uuid; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn validate_uuid(uuid: String, key: &str) -> Result<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn validate_id(id: String, key: &str) -> Result<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; fn invalid_id_format_error(key: &str) -> errors::ApiErrorResponse { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn get_or_generate_uuid( key: &str, provided_id: Option<&String>, ) -> Result<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn get_or_generate_id( key: &str, provided_id: &Option<String>, prefix: &str, ) -> Result<String, errors::ApiErrorResponse> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_refund_router_data<'a, F>( _state: &'a SessionState, _connector_id: &str, _merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, _money: (MinorUnit, enums::Currency), _payment_intent: &'a storage::PaymentIntent, _payment_attempt: &storage::PaymentAttempt, _refund: &'a storage::Refund, _creds_identifier: Option<String>, _split_refunds: Option<router_request_types::SplitRefundsRequest>, ) -> RouterResult<types::RefundsRouterData<F>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_payout_router_data<'a, F>( _state: &SessionState, _connector_data: &api::ConnectorData, _merchant_account: &domain::MerchantAccount, _payout_data: &mut PayoutData, ) -> RouterResult<types::PayoutsRouterData<F>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_retrieve_file_router_data<'a>( state: &'a SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, file_metadata: &diesel_models::file::FileMetadata, connector_id: &str, ) -> RouterResult<types::RetrieveFileRouterData> { let profile_id = file_metadata .profile_id .as_ref() .ok_or(errors::ApiErrorResponse::MissingRequiredField { field_name: "profile_id", }) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("profile_id is not set in file_metadata")?; let merchant_connector_account = helpers::get_merchant_connector_account( state, merchant_account.get_id(), None, key_store, profile_id, connector_id, file_metadata.merchant_connector_id.as_ref(), ) .await?; let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on(); let auth_type: types::ConnectorAuthType = merchant_connector_account .get_connector_account_details() .parse_value("ConnectorAuthType") .change_context(errors::ApiErrorResponse::InternalServerError)?; let router_data = types::RouterData { flow: PhantomData, merchant_id: merchant_account.get_id().clone(), connector: connector_id.to_string(), tenant_id: state.tenant.tenant_id.clone(), customer_id: None, connector_customer: None, payment_id: common_utils::id_type::PaymentId::get_irrelevant_id("dispute") .get_string_repr() .to_owned(), attempt_id: IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW.to_string(), status: diesel_models::enums::AttemptStatus::default(), payment_method: diesel_models::enums::PaymentMethod::default(), connector_auth_type: auth_type, description: None, address: PaymentAddress::default(), auth_type: diesel_models::enums::AuthenticationType::default(), connector_meta_data: merchant_connector_account.get_metadata(), connector_wallets_details: merchant_connector_account.get_connector_wallets_details(), amount_captured: None, minor_amount_captured: None, payment_method_status: None, request: types::RetrieveFileRequestData { provider_file_id: file_metadata .provider_file_id .clone() .ok_or(errors::ApiErrorResponse::InternalServerError) .attach_printable("Missing provider file id")?, }, response: Err(ErrorResponse::default()), access_token: None, session_token: None, reference_id: None, payment_method_token: None, recurring_mandate_payment_data: None, preprocessing_id: None, payment_method_balance: None, connector_request_reference_id: IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_DISPUTE_FLOW .to_string(), #[cfg(feature = "payouts")] payout_method_data: None, #[cfg(feature = "payouts")] quote_id: None, test_mode, connector_api_version: None, connector_http_status_code: None, external_latency: None, apple_pay_flow: None, frm_metadata: None, refund_id: None, dispute_id: None, connector_response: None, integrity_check: Ok(()), additional_merchant_data: None, header_payload: None, connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, }; Ok(router_data) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_defend_dispute_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, dispute: &storage::Dispute, ) -> RouterResult<types::DefendDisputeRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>( state: &SessionState, merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, payment_data: &mut PaymentData<F>, merchant_connector_account: &MerchantConnectorAccount, ) -> RouterResult<types::PaymentsTaxCalculationRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_upload_file_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, create_file_request: &api::CreateFileRequest, connector_id: &str, file_key: String, ) -> RouterResult<types::UploadFileRouterData> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_submit_evidence_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, dispute: &storage::Dispute, submit_evidence_request_data: types::SubmitEvidenceRequestData, ) -> RouterResult<types::SubmitEvidenceRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_accept_dispute_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, dispute: &storage::Dispute, ) -> RouterResult<types::AcceptDisputeRouterData> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::core::payments; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub fn get_split_refunds( split_refund_input: super::refunds::transformers::SplitRefundInput, ) -> RouterResult<Option<router_request_types::SplitRefundsRequest>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{crypto::Encryptable, pii::Email}; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use error_stack::{report, ResultExt}; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::core::payments; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_payout_router_data<'a, F>( state: &SessionState, connector_data: &api::ConnectorData, merchant_account: &domain::MerchantAccount, payout_data: &mut PayoutData, ) -> RouterResult<types::PayoutsRouterData<F>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/utils.rs | crate: router use std::{collections::HashSet, marker::PhantomData, str::FromStr}; use api_models::enums::{DisputeStage, DisputeStatus}; use api_models::payouts::PayoutVendorAccountDetails; use common_utils::{ errors::CustomResult, ext_traits::AsyncExt, types::{keymanager::KeyManagerState, ConnectorTransactionIdTrait, MinorUnit}, }; use hyperswitch_domain_models::{ merchant_connector_account::MerchantConnectorAccount, payment_address::PaymentAddress, router_data::ErrorResponse, router_request_types, types::OrderDetailsWithAmount, }; use super::payments::helpers; use super::payouts::{helpers as payout_helpers, PayoutData}; use crate::core::payments; use crate::{ configs::Settings, consts, core::{ errors::{self, RouterResult, StorageErrorExt}, payments::PaymentData, }, db::StorageInterface, routes::SessionState, types::{ self, api, domain, storage::{self, enums}, PollConfig, }, utils::{generate_id, generate_uuid, OptionExt, ValueExt}, }; pub async fn construct_refund_router_data<'a, F>( state: &'a SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, money: (MinorUnit, enums::Currency), payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, refund: &'a storage::Refund, creds_identifier: Option<String>, split_refunds: Option<router_request_types::SplitRefundsRequest>, ) -> RouterResult<types::RefundsRouterData<F>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/admin.rs | crate: router use common_utils::{ date_time, ext_traits::{AsyncExt, Encode, OptionExt, ValueExt}, fp_utils, id_type, pii, type_name, types::keymanager::{self as km_types, KeyManagerState, ToEncryptable}, }; use crate::{ consts, core::{ encryption::transfer_encryption_key, errors::{self, RouterResponse, RouterResult, StorageErrorExt}, payment_methods::{cards, transformers}, payments::helpers, pm_auth::helpers::PaymentAuthConnectorDataExt, routing, utils as core_utils, }, db::{AccountsStorageInterface, StorageInterface}, routes::{metrics, SessionState}, services::{ self, api::{self as service_api, client}, authentication, pm_auth as payment_initiation_service, }, types::{ self, api::{self, admin}, domain::{ self, types::{self as domain_types, AsyncLift}, }, storage::{self, enums::MerchantStorageScheme}, transformers::{ForeignInto, ForeignTryFrom, ForeignTryInto}, }, utils, }; pub async fn enable_platform_account( state: SessionState, merchant_id: id_type::MerchantId, ) -> RouterResponse<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/admin.rs | crate: router code: err.code, message: err.message, connector: connector.connector_name.to_string(), status_code: err.status_code, reason: err.reason, })?; let recipient_id = recipient_create_resp.recipient_id; Ok(recipient_id) } async fn locker_recipient_create_call( state: &SessionState, merchant_id: &id_type::MerchantId, data: &types::MerchantAccountData, ) -> RouterResult<String> { let enc_data = serde_json::to_string(data) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to convert to MerchantAccountData json to String")?; let merchant_id_string = merchant_id.get_string_repr().to_owned(); let cust_id = id_type::CustomerId::try_from(std::borrow::Cow::from(merchant_id_string)) .change_context(errors::ApiErrorResponse::InternalServerError) async fn locker_recipient_create_call( state: &SessionState, merchant_id: &id_type::MerchantId, data: &types::MerchantAccountData, ) -> RouterResult<String> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/admin.rs | crate: router use common_utils::{ date_time, ext_traits::{AsyncExt, Encode, OptionExt, ValueExt}, fp_utils, id_type, pii, type_name, types::keymanager::{self as km_types, KeyManagerState, ToEncryptable}, }; use pm_auth::{connector::plaid::transformers::PlaidAuthType, types as pm_auth_types}; use regex::Regex; use crate::types::transformers::ForeignFrom; use crate::{ consts, core::{ encryption::transfer_encryption_key, errors::{self, RouterResponse, RouterResult, StorageErrorExt}, payment_methods::{cards, transformers}, payments::helpers, pm_auth::helpers::PaymentAuthConnectorDataExt, routing, utils as core_utils, }, db::{AccountsStorageInterface, StorageInterface}, routes::{metrics, SessionState}, services::{ self, api::{self as service_api, client}, authentication, pm_auth as payment_initiation_service, }, types::{ self, api::{self, admin}, domain::{ self, types::{self as domain_types, AsyncLift}, }, storage::{self, enums::MerchantStorageScheme}, transformers::{ForeignInto, ForeignTryFrom, ForeignTryInto}, }, utils, }; fn validate_bank_account_data(data: &types::MerchantAccountData) -> RouterResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/admin.rs | crate: router business_profile, profile_update, ) .await .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound { id: profile_id.get_string_repr().to_owned(), })?; } Ok(service_api::ApplicationResponse::Json(ext_card_info_choice)) } pub async fn connector_agnostic_mit_toggle( state: SessionState, merchant_id: &id_type::MerchantId, profile_id: &id_type::ProfileId, connector_agnostic_mit_choice: admin_types::ConnectorAgnosticMitChoice, ) -> RouterResponse<admin_types::ConnectorAgnosticMitChoice> { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let key_store = db .get_merchant_key_store_by_merchant_id( key_manager_state, merchant_id, pub async fn connector_agnostic_mit_toggle( state: SessionState, merchant_id: &id_type::MerchantId, profile_id: &id_type::ProfileId, connector_agnostic_mit_choice: admin_types::ConnectorAgnosticMitChoice, ) -> RouterResponse<admin_types::ConnectorAgnosticMitChoice> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/admin.rs | crate: router key_manager_state, merchant_key_store, self.profile, 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( state: SessionState, merchant_id: &id_type::MerchantId, profile_id: &id_type::ProfileId, ext_card_info_choice: admin_types::ExtendedCardInfoChoice, ) -> RouterResponse<admin_types::ExtendedCardInfoChoice> { let db = state.store.as_ref(); let key_manager_state = &(&state).into(); let key_store = db .get_merchant_key_store_by_merchant_id( key_manager_state, merchant_id, pub async fn extended_card_info_toggle( state: SessionState, merchant_id: &id_type::MerchantId, profile_id: &id_type::ProfileId, ext_card_info_choice: admin_types::ExtendedCardInfoChoice, ) -> RouterResponse<admin_types::ExtendedCardInfoChoice> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/router/src/core/admin.rs | crate: router pub fn get_default_routing_configs_from_profile( &self, ) -> RouterResult<routing_types::ProfileDefaultRoutingConfig> { let profile_id = self.profile.get_id().to_owned(); let connectors = self.get_default_fallback_list_of_connector_under_profile()?; Ok(routing_types::ProfileDefaultRoutingConfig { profile_id, connectors, }) } pub async fn update_default_fallback_routing_of_connectors_under_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")?, ); pub async fn update_default_fallback_routing_of_connectors_under_profile( self, db: &dyn StorageInterface, updated_config: &Vec<routing_types::RoutableConnectorChoice>, key_manager_state: &KeyManagerState, merchant_key_store: &domain::MerchantKeyStore, ) -> RouterResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments