text stringlengths 70 351k | source stringclasses 4 values |
|---|---|
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 update_profile_and_invalidate_routing_config_for_active_algorithm_id_update(
self,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
merchant_key_store: &domain::MerchantKeyStore,
algorithm_id: id_type::RoutingId,
transaction_type: &storage::enums::TransactionType,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
card_testing_guard_config: self
.card_testing_guard_config
.map(ForeignInto::foreign_into),
card_testing_secret_key,
is_debit_routing_enabled: self.is_debit_routing_enabled.unwrap_or_default(),
merchant_business_country: self.merchant_business_country,
},
)))
}
}
#[cfg(feature = "olap")]
pub async fn update_profile(
state: SessionState,
profile_id: &id_type::ProfileId,
key_store: domain::MerchantKeyStore,
request: api::ProfileUpdate,
) -> RouterResponse<api::ProfileResponse> {
let db = state.store.as_ref();
let key_manager_state = &(&state).into();
let business_profile = db
.find_business_profile_by_profile_id(key_manager_state, &key_store, profile_id)
.await
.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {
pub async fn update_profile(
state: SessionState,
profile_id: &id_type::ProfileId,
key_store: domain::MerchantKeyStore,
request: api::ProfileUpdate,
) -> RouterResponse<api::ProfileResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
}
Ok(service_api::ApplicationResponse::Json(
api_models::admin::ProfileResponse::foreign_try_from(business_profile)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to parse business profile details")?,
))
}
#[cfg(feature = "olap")]
pub async fn list_profile(
state: SessionState,
merchant_id: id_type::MerchantId,
profile_id_list: Option<Vec<id_type::ProfileId>>,
) -> RouterResponse<Vec<api_models::admin::ProfileResponse>> {
let db = state.store.as_ref();
let key_store = db
.get_merchant_key_store_by_merchant_id(
&(&state).into(),
&merchant_id,
&db.get_master_key().to_vec().into(),
)
.await
pub async fn list_profile(
state: SessionState,
merchant_id: id_type::MerchantId,
profile_id_list: Option<Vec<id_type::ProfileId>>,
) -> RouterResponse<Vec<api_models::admin::ProfileResponse>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
use diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
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 create_profile(
state: SessionState,
request: api::ProfileCreate,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
) -> RouterResponse<api_models::admin::ProfileResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 check_merchant_account_kv_status(
state: SessionState,
merchant_id: id_type::MerchantId,
) -> RouterResponse<api_models::admin::ToggleKVResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 toggle_kv_for_all_merchants(
state: SessionState,
enable: bool,
) -> RouterResponse<api_models::admin::ToggleAllKVResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 kv_for_merchant(
state: SessionState,
merchant_id: id_type::MerchantId,
enable: bool,
) -> RouterResponse<api_models::admin::ToggleKVResponse> {
<|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 diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
use hyperswitch_domain_models::merchant_connector_account::{
FromRequestEncryptableMerchantConnectorAccount, UpdateEncryptableMerchantConnectorAccount,
};
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 delete_connector(
state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
id: id_type::MerchantConnectorAccountId,
) -> RouterResponse<api::MerchantConnectorDeleteResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
format!(
"Failed while updating MerchantConnectorAccount: id: {:?}",
merchant_connector_id
)
})?;
let response = updated_mca.foreign_try_into()?;
Ok(service_api::ApplicationResponse::Json(response))
}
#[cfg(feature = "v1")]
pub async fn delete_connector(
state: SessionState,
merchant_id: id_type::MerchantId,
merchant_connector_id: id_type::MerchantConnectorAccountId,
) -> RouterResponse<api::MerchantConnectorDeleteResponse> {
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,
&db.get_master_key().to_vec().into(),
)
pub async fn delete_connector(
state: SessionState,
merchant_id: id_type::MerchantId,
merchant_connector_id: id_type::MerchantConnectorAccountId,
) -> RouterResponse<api::MerchantConnectorDeleteResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 update_connector(
state: SessionState,
merchant_id: &id_type::MerchantId,
profile_id: Option<id_type::ProfileId>,
merchant_connector_id: &id_type::MerchantConnectorAccountId,
req: api_models::admin::MerchantConnectorUpdate,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 list_payment_connectors(
state: SessionState,
merchant_id: id_type::MerchantId,
profile_id_list: Option<Vec<id_type::ProfileId>>,
) -> RouterResponse<Vec<api_models::admin::MerchantConnectorListResponse>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: merchant_connector_id.get_string_repr().to_string(),
})?;
core_utils::validate_profile_id_from_auth_layer(profile_id, &mca)?;
Ok(service_api::ApplicationResponse::Json(
mca.foreign_try_into()?,
))
}
#[cfg(feature = "v2")]
pub async fn retrieve_connector(
state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
id: id_type::MerchantConnectorAccountId,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
let store = state.store.as_ref();
let key_manager_state = &(&state).into();
let merchant_id = merchant_account.get_id();
let mca = store
.find_merchant_connector_account_by_id(key_manager_state, &id, &key_store)
pub async fn retrieve_connector(
state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
id: id_type::MerchantConnectorAccountId,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 retrieve_connector(
state: SessionState,
merchant_id: id_type::MerchantId,
profile_id: Option<id_type::ProfileId>,
merchant_connector_id: id_type::MerchantConnectorAccountId,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
1,
router_env::metric_attributes!(
("connector", req.connector_name.to_string()),
("merchant", merchant_id.clone()),
),
);
let mca_response = mca.foreign_try_into()?;
Ok(service_api::ApplicationResponse::Json(mca_response))
}
#[cfg(feature = "v1")]
async fn validate_pm_auth(
val: pii::SecretSerdeValue,
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
profile_id: &id_type::ProfileId,
) -> RouterResponse<()> {
let config =
serde_json::from_value::<api_models::pm_auth::PaymentMethodAuthConfig>(val.expose())
.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "invalid data received for payment method auth config".to_string(),
})
async fn validate_pm_auth(
val: pii::SecretSerdeValue,
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
merchant_account: domain::MerchantAccount,
profile_id: &id_type::ProfileId,
) -> RouterResponse<()> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
test_mode: self.test_mode,
business_country: self.business_country,
business_label: self.business_label.clone(),
business_sub_label: self.business_sub_label.clone(),
additional_merchant_data: encrypted_data.additional_merchant_data,
version: common_types::consts::API_VERSION,
})
}
/// If profile_id is not passed, use default profile if available, or
/// If business_details (business_country and business_label) are passed, get the business_profile
/// or return a `MissingRequiredField` error
async fn validate_and_get_business_profile(
self,
merchant_account: &domain::MerchantAccount,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
match self.profile_id.or(merchant_account.default_profile.clone()) {
Some(profile_id) => {
// Check whether this business profile belongs to the merchant
let business_profile = core_utils::validate_and_get_business_profile(
db,
/// If profile_id is not passed, use default profile if available, or
/// If business_details (business_country and business_label) are passed, get the business_profile
/// or return a `MissingRequiredField` error
async fn validate_and_get_business_profile(
self,
merchant_account: &domain::MerchantAccount,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
.update_default_fallback_routing_of_connectors_under_profile(
self.store,
default_routing_config_for_profile,
self.key_manager_state,
&self.key_store,
)
.await?
}
}
Ok(())
}
async fn retrieve_and_delete_from_default_fallback_routing_algorithm_if_routable_connector_exists(
&self,
) -> RouterResult<()> {
let profile_wrapper = ProfileWrapper::new(self.business_profile.clone());
let default_routing_config_for_profile =
&mut profile_wrapper.get_default_fallback_list_of_connector_under_profile()?;
if let Some(routable_connector_val) = self.routable_connector {
let choice = routing_types::RoutableConnectorChoice {
choice_kind: routing_types::RoutableChoiceKind::FullStruct,
connector: *routable_connector_val,
merchant_connector_id: Some(self.merchant_connector_id.clone()),
};
if default_routing_config_for_profile.contains(&choice.clone()) {
async fn retrieve_and_delete_from_default_fallback_routing_algorithm_if_routable_connector_exists(
&self,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
}
#[cfg(feature = "v2")]
struct DefaultFallbackRoutingConfigUpdate<'a> {
routable_connector: &'a Option<api_enums::RoutableConnectors>,
merchant_connector_id: &'a id_type::MerchantConnectorAccountId,
store: &'a dyn StorageInterface,
business_profile: domain::Profile,
key_store: hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,
key_manager_state: &'a KeyManagerState,
}
#[cfg(feature = "v2")]
impl DefaultFallbackRoutingConfigUpdate<'_> {
async fn retrieve_and_update_default_fallback_routing_algorithm_if_routable_connector_exists(
&self,
) -> RouterResult<()> {
let profile_wrapper = ProfileWrapper::new(self.business_profile.clone());
let default_routing_config_for_profile =
&mut profile_wrapper.get_default_fallback_list_of_connector_under_profile()?;
if let Some(routable_connector_val) = self.routable_connector {
let choice = routing_types::RoutableConnectorChoice {
choice_kind: routing_types::RoutableChoiceKind::FullStruct,
connector: *routable_connector_val,
merchant_connector_id: Some(self.merchant_connector_id.clone()),
};
if !default_routing_config_for_profile.contains(&choice.clone()) {
async fn retrieve_and_update_default_fallback_routing_algorithm_if_routable_connector_exists(
&self,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
}
}
Ok(())
}
}
struct ConnectorTypeAndConnectorName<'a> {
connector_type: &'a api_enums::ConnectorType,
connector_name: &'a api_enums::Connector,
}
impl ConnectorTypeAndConnectorName<'_> {
fn get_routable_connector(&self) -> RouterResult<Option<api_enums::RoutableConnectors>> {
let mut routable_connector =
api_enums::RoutableConnectors::from_str(&self.connector_name.to_string()).ok();
let pm_auth_connector =
api_enums::convert_pm_auth_connector(self.connector_name.to_string().as_str());
let authentication_connector =
api_enums::convert_authentication_connector(self.connector_name.to_string().as_str());
let tax_connector =
api_enums::convert_tax_connector(self.connector_name.to_string().as_str());
let billing_connector =
api_enums::convert_billing_connector(self.connector_name.to_string().as_str());
fn get_routable_connector(&self) -> RouterResult<Option<api_enums::RoutableConnectors>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
struct PMAuthConfigValidation<'a> {
connector_type: &'a api_enums::ConnectorType,
pm_auth_config: &'a Option<pii::SecretSerdeValue>,
db: &'a dyn StorageInterface,
merchant_id: &'a id_type::MerchantId,
profile_id: &'a id_type::ProfileId,
key_store: &'a domain::MerchantKeyStore,
key_manager_state: &'a KeyManagerState,
}
impl PMAuthConfigValidation<'_> {
async fn validate_pm_auth(&self, val: &pii::SecretSerdeValue) -> RouterResponse<()> {
let config = serde_json::from_value::<api_models::pm_auth::PaymentMethodAuthConfig>(
val.clone().expose(),
)
.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "invalid data received for payment method auth config".to_string(),
})
.attach_printable("Failed to deserialize Payment Method Auth config")?;
let all_mcas = self
.db
.find_merchant_connector_account_by_merchant_id_and_disabled_list(
self.key_manager_state,
async fn validate_pm_auth(&self, val: &pii::SecretSerdeValue) -> RouterResponse<()> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
}
}
}
struct ConnectorStatusAndDisabledValidation<'a> {
status: &'a Option<api_enums::ConnectorStatus>,
disabled: &'a Option<bool>,
auth: &'a types::ConnectorAuthType,
current_status: &'a api_enums::ConnectorStatus,
}
impl ConnectorStatusAndDisabledValidation<'_> {
fn validate_status_and_disabled(
&self,
) -> RouterResult<(api_enums::ConnectorStatus, Option<bool>)> {
let connector_status = match (self.status, self.auth) {
(
Some(common_enums::ConnectorStatus::Active),
types::ConnectorAuthType::TemporaryAuth,
) => {
return Err(errors::ApiErrorResponse::InvalidRequestData {
message: "Connector status cannot be active when using TemporaryAuth"
.to_string(),
}
.into());
fn validate_status_and_disabled(
&self,
) -> RouterResult<(api_enums::ConnectorStatus, Option<bool>)> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
threedsecureio::transformers::ThreedsecureioAuthType::try_from(self.auth_type)?;
Ok(())
}
}
}
}
struct ConnectorAuthTypeValidation<'a> {
auth_type: &'a types::ConnectorAuthType,
}
impl ConnectorAuthTypeValidation<'_> {
fn validate_connector_auth_type(
&self,
) -> Result<(), error_stack::Report<errors::ApiErrorResponse>> {
let validate_non_empty_field = |field_value: &str, field_name: &str| {
if field_value.trim().is_empty() {
Err(errors::ApiErrorResponse::InvalidDataFormat {
field_name: format!("connector_account_details.{}", field_name),
expected_format: "a non empty String".to_string(),
}
.into())
} else {
Ok(())
}
fn validate_connector_auth_type(
&self,
) -> Result<(), error_stack::Report<errors::ApiErrorResponse>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
db.find_merchant_account_by_merchant_id(&state.into(), merchant_id, key_store)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
}
struct ConnectorAuthTypeAndMetadataValidation<'a> {
connector_name: &'a api_models::enums::Connector,
auth_type: &'a types::ConnectorAuthType,
connector_meta_data: &'a Option<pii::SecretSerdeValue>,
}
impl ConnectorAuthTypeAndMetadataValidation<'_> {
pub fn validate_auth_and_metadata_type(
&self,
) -> Result<(), error_stack::Report<errors::ApiErrorResponse>> {
let connector_auth_type_validation = ConnectorAuthTypeValidation {
auth_type: self.auth_type,
};
connector_auth_type_validation.validate_connector_auth_type()?;
self.validate_auth_and_metadata_type_with_connector()
.map_err(|err| match *err.current_context() {
errors::ConnectorError::InvalidConnectorName => {
err.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "The connector name is invalid".to_string(),
})
pub fn validate_auth_and_metadata_type(
&self,
) -> Result<(), error_stack::Report<errors::ApiErrorResponse>> {
<|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 error_stack::{report, FutureExt, ResultExt};
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,
};
async fn get_parent_merchant(
state: &SessionState,
sub_merchants_enabled: Option<bool>,
parent_merchant: Option<&id_type::MerchantId>,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<Option<id_type::MerchantId>> {
<|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::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,
};
pub async fn merchant_account_delete(
state: SessionState,
merchant_id: id_type::MerchantId,
) -> RouterResponse<api::MerchantAccountDeleteResponse> {
{<|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 merchant_account_update(
state: SessionState,
merchant_id: &id_type::MerchantId,
_profile_id: Option<id_type::ProfileId>,
req: api::MerchantAccountUpdate,
) -> RouterResponse<api::MerchantAccountResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
payout_routing_algorithm: None,
default_profile: business_profile_id_update,
payment_link_config: None,
pm_collect_link_config,
routing_algorithm: self.routing_algorithm,
})
}
}
#[cfg(feature = "v2")]
#[async_trait::async_trait]
impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate {
async fn get_update_merchant_object(
self,
state: &SessionState,
_merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<storage::MerchantAccountUpdate> {
let key_manager_state = &state.into();
let key = key_store.key.get_inner().peek();
let merchant_details = self.get_merchant_details_as_secret().change_context(
errors::ApiErrorResponse::InvalidDataValue {
field_name: "merchant_details",
},
async fn get_update_merchant_object(
self,
state: &SessionState,
_merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<storage::MerchantAccountUpdate> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
Ok(service_api::ApplicationResponse::Json(
api::MerchantAccountResponse::foreign_try_from(merchant_account)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct response")?,
))
}
#[cfg(feature = "v1")]
/// For backwards compatibility, whenever new business labels are passed in
/// primary_business_details, create a profile
pub async fn create_profile_from_business_labels(
state: &SessionState,
db: &dyn StorageInterface,
key_store: &domain::MerchantKeyStore,
merchant_id: &id_type::MerchantId,
new_business_details: Vec<admin_types::PrimaryBusinessDetails>,
) -> RouterResult<()> {
let key_manager_state = &state.into();
let merchant_account = db
.find_merchant_account_by_merchant_id(key_manager_state, merchant_id, key_store)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
/// For backwards compatibility, whenever new business labels are passed in
/// primary_business_details, create a profile
pub async fn create_profile_from_business_labels(
state: &SessionState,
db: &dyn StorageInterface,
key_store: &domain::MerchantKeyStore,
merchant_id: &id_type::MerchantId,
new_business_details: Vec<admin_types::PrimaryBusinessDetails>,
) -> RouterResult<()> {
<|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 get_merchant_account(
state: SessionState,
req: api::MerchantId,
_profile_id: Option<id_type::ProfileId>,
) -> RouterResponse<api::MerchantAccountResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
use diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
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 list_merchant_account(
state: SessionState,
organization_id: api_models::organization::OrganizationId,
) -> RouterResponse<Vec<api::MerchantAccountResponse>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
})
.map(|business_profile| business_profiles_vector.push(business_profile))
.ok();
}
Ok(business_profiles_vector)
}
}
#[cfg(all(feature = "v2", feature = "olap"))]
#[async_trait::async_trait]
impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
identifier: &id_type::MerchantId,
) -> RouterResult<domain::MerchantAccount> {
let publishable_key = create_merchant_publishable_key();
let db = &*state.accounts_store;
let metadata = self.get_metadata_as_secret().change_context(
errors::ApiErrorResponse::InvalidDataValue {
field_name: "metadata",
},
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
identifier: &id_type::MerchantId,
) -> RouterResult<domain::MerchantAccount> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
use diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
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,
};
/// Create profile for each primary_business_details,
/// If there is no default profile in merchant account and only one primary_business_detail
/// is available, then create a default profile.
async fn create_profiles_for_each_business_details(
state: &SessionState,
merchant_account: domain::MerchantAccount,
primary_business_details: &Vec<admin_types::PrimaryBusinessDetails>,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<Vec<domain::Profile>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
/// If primary business details are empty, then create default profile
fn new(primary_business_details: Option<Vec<admin_types::PrimaryBusinessDetails>>) -> Self {
match primary_business_details {
Some(primary_business_details) if !primary_business_details.is_empty() => {
Self::CreateFromPrimaryBusinessDetails {
primary_business_details,
}
}
_ => Self::CreateDefaultProfile,
}
}
async fn create_profiles(
&self,
state: &SessionState,
merchant_account: &mut domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<()> {
match self {
Self::CreateFromPrimaryBusinessDetails {
primary_business_details,
} => {
let business_profiles = Self::create_profiles_for_each_business_details(
state,
merchant_account.clone(),
async fn create_profiles(
&self,
state: &SessionState,
merchant_account: &mut domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
let profile_id = self.profile.get_id().to_owned();
storage_impl::redis::cache::CacheKind::Routing(
format!(
"routing_config_{}_{}",
merchant_id.get_string_repr(),
profile_id.get_string_repr()
)
.into(),
)
}
pub async fn update_profile_and_invalidate_routing_config_for_active_algorithm_id_update(
self,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
merchant_key_store: &domain::MerchantKeyStore,
algorithm_id: id_type::RoutingId,
transaction_type: &storage::enums::TransactionType,
) -> RouterResult<()> {
let routing_cache_key = self.clone().get_routing_config_cache_key();
let (routing_algorithm_id, payout_routing_algorithm_id) = match transaction_type {
storage::enums::TransactionType::Payment => (Some(algorithm_id), None),
#[cfg(feature = "payouts")]
pub async fn update_profile_and_invalidate_routing_config_for_active_algorithm_id_update(
self,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
merchant_key_store: &domain::MerchantKeyStore,
algorithm_id: id_type::RoutingId,
transaction_type: &storage::enums::TransactionType,
) -> RouterResult<()> {
{
storage::enums::TransactionType::Payment => (Some(algorithm_id), None),<|fim_suffix|>
<|fim_middle|>
#[cfg(feature = "payouts")]
storage::enums::TransactionType::Payout => (None, Some(algorithm_id)),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
trait ProfileUpdateBridge {
async fn get_update_profile_object(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &domain::Profile,
) -> RouterResult<domain::ProfileUpdate>;
}
#[cfg(all(feature = "olap", feature = "v1"))]
#[async_trait::async_trait]
impl ProfileUpdateBridge for api::ProfileUpdate {
async fn get_update_profile_object(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &domain::Profile,
) -> RouterResult<domain::ProfileUpdate> {
if let Some(session_expiry) = &self.session_expiry {
helpers::validate_session_expiry(session_expiry.to_owned())?;
}
if let Some(intent_fulfillment_expiry) = self.intent_fulfillment_time {
helpers::validate_intent_fulfillment_expiry(intent_fulfillment_expiry)?;
}
async fn get_update_profile_object(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &domain::Profile,
) -> RouterResult<domain::ProfileUpdate> {
{
Ok(_) => Ok(payout_conf.foreign_into()),<|fim_suffix|>
<|fim_middle|>
Err(e) => Err(report!(errors::ApiErrorResponse::InvalidRequestData {
message: e.to_string()
})),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 transfer_key_store_to_key_manager(
state: SessionState,
req: admin_types::MerchantKeyTransferRequest,
) -> RouterResponse<admin_types::TransferKeyResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
default_fallback_routing
.expose()
.parse_value::<Vec<routing_types::RoutableConnectorChoice>>(
"Vec<RoutableConnectorChoice>",
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Business Profile default config has invalid structure")?
} else {
Vec::new()
};
Ok(fallback_connectors)
}
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(
pub fn get_default_routing_configs_from_profile(
&self,
) -> RouterResult<routing_types::ProfileDefaultRoutingConfig> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 fn get_default_fallback_list_of_connector_under_profile(
&self,
) -> RouterResult<Vec<routing_types::RoutableConnectorChoice>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 fn get_routing_algorithm_id<'a>(
&'a self,
transaction_data: &'a routing::TransactionData<'_>,
) -> Option<id_type::RoutingId> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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,
};
fn get_routing_config_cache_key(self) -> storage_impl::redis::cache::CacheKind<'static> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
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 fn new(profile: domain::Profile) -> Self {
{<|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 delete_profile(
state: SessionState,
profile_id: id_type::ProfileId,
merchant_id: &id_type::MerchantId,
) -> RouterResponse<bool> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
let profiles = core_utils::filter_objects_based_on_profile_id_list(profile_id_list, profiles);
let mut business_profiles = Vec::new();
for profile in profiles {
let business_profile = api_models::admin::ProfileResponse::foreign_try_from(profile)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to parse business profile details")?;
business_profiles.push(business_profile);
}
Ok(service_api::ApplicationResponse::Json(business_profiles))
}
pub async fn retrieve_profile(
state: SessionState,
profile_id: id_type::ProfileId,
key_store: domain::MerchantKeyStore,
) -> RouterResponse<api_models::admin::ProfileResponse> {
let db = state.store.as_ref();
let business_profile = db
.find_business_profile_by_profile_id(&(&state).into(), &key_store, &profile_id)
.await
.to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {
id: profile_id.get_string_repr().to_owned(),
})?;
pub async fn retrieve_profile(
state: SessionState,
profile_id: id_type::ProfileId,
key_store: domain::MerchantKeyStore,
) -> RouterResponse<api_models::admin::ProfileResponse> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 create_and_insert_business_profile(
state: &SessionState,
request: api::ProfileCreate,
merchant_account: domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
use masking::{ExposeInterface, PeekInterface, Secret};
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 fn get_frm_config_as_secret(
frm_configs: Option<Vec<api_models::admin::FrmConfigs>>,
) -> Option<Vec<Secret<serde_json::Value>>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 list_connectors_for_a_profile(
state: SessionState,
key_store: domain::MerchantKeyStore,
profile_id: id_type::ProfileId,
) -> RouterResponse<Vec<api_models::admin::MerchantConnectorListResponse>> {
let store = state.store.as_ref();
let key_manager_state = &(&state).into();
let merchant_connector_accounts = store
.list_connector_account_by_profile_id(key_manager_state, &profile_id, &key_store)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
let mut response = vec![];
for mca in merchant_connector_accounts.into_iter() {
response.push(mca.foreign_try_into()?);
}
Ok(service_api::ApplicationResponse::Json(response))
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
Ok(business_profile)
}
}
#[cfg(feature = "v1")]
struct PaymentMethodsEnabled<'a> {
payment_methods_enabled: &'a Option<Vec<api_models::admin::PaymentMethodsEnabled>>,
}
#[cfg(feature = "v1")]
impl PaymentMethodsEnabled<'_> {
fn get_payment_methods_enabled(&self) -> RouterResult<Option<Vec<pii::SecretSerdeValue>>> {
let mut vec = Vec::new();
let payment_methods_enabled = match self.payment_methods_enabled.clone() {
Some(val) => {
for pm in val.into_iter() {
let pm_value = pm
.encode_to_value()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"Failed while encoding to serde_json::Value, PaymentMethod",
)?;
vec.push(Secret::new(pm_value))
}
fn get_payment_methods_enabled(&self) -> RouterResult<Option<Vec<pii::SecretSerdeValue>>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
},
profile_id: business_profile.get_id().to_owned(),
applepay_verified_domains: None,
pm_auth_config: self.pm_auth_config.clone(),
status: connector_status,
connector_wallets_details: encrypted_data.connector_wallets_details,
additional_merchant_data: encrypted_data.additional_merchant_data,
version: common_types::consts::API_VERSION,
feature_metadata,
})
}
async fn validate_and_get_business_profile(
self,
merchant_account: &domain::MerchantAccount,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
let profile_id = self.profile_id;
// Check whether this profile belongs to the merchant
let business_profile = core_utils::validate_and_get_business_profile(
db,
key_manager_state,
async fn validate_and_get_business_profile(
self,
merchant_account: &domain::MerchantAccount,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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,
};
async fn get_merchant_connector_account_from_id(
self,
db: &dyn StorageInterface,
merchant_id: &id_type::MerchantId,
merchant_connector_id: &id_type::MerchantConnectorAccountId,
key_store: &domain::MerchantKeyStore,
key_manager_state: &KeyManagerState,
) -> RouterResult<domain::MerchantConnectorAccount> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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,
};
async fn get_merchant_connector_account_from_id(
self,
db: &dyn StorageInterface,
_merchant_id: &id_type::MerchantId,
merchant_connector_id: &id_type::MerchantConnectorAccountId,
key_store: &domain::MerchantKeyStore,
key_manager_state: &KeyManagerState,
) -> RouterResult<domain::MerchantConnectorAccount> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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,
};
async fn validate_pm_auth_config(&self) -> RouterResult<()> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
(None, _) => Some(false),
};
Ok((*connector_status, disabled))
}
}
struct ConnectorMetadata<'a> {
connector_metadata: &'a Option<pii::SecretSerdeValue>,
}
impl ConnectorMetadata<'_> {
fn validate_apple_pay_certificates_in_mca_metadata(&self) -> RouterResult<()> {
self.connector_metadata
.clone()
.map(api_models::payments::ConnectorMetadata::from_value)
.transpose()
.change_context(errors::ApiErrorResponse::InvalidDataFormat {
field_name: "metadata".to_string(),
expected_format: "connector metadata".to_string(),
})?
.and_then(|metadata| metadata.get_apple_pay_certificates())
.map(|(certificate, certificate_key)| {
client::create_identity_from_certificate_and_key(certificate, certificate_key)
})
fn validate_apple_pay_certificates_in_mca_metadata(&self) -> RouterResult<()> {
{<|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,
};
async fn validate_merchant_id(
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::MerchantAccount> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
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 list_merchant_account(
state: SessionState,
req: api_models::admin::MerchantAccountListRequest,
) -> RouterResponse<Vec<api::MerchantAccountResponse>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
let business_profile = self
.create_default_business_profile(state, merchant_account.clone(), key_store)
.await?;
merchant_account.default_profile = Some(business_profile.get_id().to_owned());
}
}
Ok(())
}
/// Create default profile
async fn create_default_business_profile(
&self,
state: &SessionState,
merchant_account: domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
let business_profile = create_and_insert_business_profile(
state,
api_models::admin::ProfileCreate::default(),
merchant_account.clone(),
key_store,
)
.await?;
/// Create default profile
async fn create_default_business_profile(
&self,
state: &SessionState,
merchant_account: domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
/// Create a new profile action from the given information
/// If primary business details exist, then create profiles from them
/// If primary business details are empty, then create default profile
fn new(primary_business_details: Option<Vec<admin_types::PrimaryBusinessDetails>>) -> Self {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
Self::Create
}
}
#[cfg(all(feature = "v2", feature = "olap"))]
/// Create an action to validate the provided organization_id
fn new(organization_id: id_type::OrganizationId) -> Self {
Self::Validate { organization_id }
}
#[cfg(feature = "olap")]
/// Apply the action, whether to create the organization or validate the given organization_id
async fn create_or_validate(
&self,
db: &dyn AccountsStorageInterface,
) -> RouterResult<diesel_models::organization::Organization> {
match self {
#[cfg(feature = "v1")]
Self::Create => {
let new_organization = api_models::organization::OrganizationNew::new(None);
let db_organization = ForeignFrom::foreign_from(new_organization);
db.insert_organization(db_organization)
.await
.to_duplicate_response(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error when creating organization")
/// Apply the action, whether to create the organization or validate the given organization_id
async fn create_or_validate(
&self,
db: &dyn AccountsStorageInterface,
) -> RouterResult<diesel_models::organization::Organization> {
<|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},
};
/// Create an action to validate the provided organization_id
fn new(organization_id: id_type::OrganizationId) -> Self {
{<|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},
};
/// Create an action to either create or validate the given organization_id
/// If organization_id is passed, then validate if this organization exists
/// If not passed, create a new organization
fn new(organization_id: Option<id_type::OrganizationId>) -> Self {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
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,
};
pub async fn get_organization(
state: SessionState,
org_id: api::OrganizationId,
) -> RouterResponse<api::OrganizationResponse> {
#[cfg(all(feature = "v1", feature = "olap"))]
{
CreateOrValidateOrganization::new(Some(org_id.organization_id))
.create_or_validate(state.accounts_store.as_ref())
.await
.map(ForeignFrom::foreign_from)
.map(service_api::ApplicationResponse::Json)
}
#[cfg(all(feature = "v2", feature = "olap"))]
{
CreateOrValidateOrganization::new(org_id.organization_id)
.create_or_validate(state.accounts_store.as_ref())
.await
.map(ForeignFrom::foreign_from)
.map(service_api::ApplicationResponse::Json)
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use diesel_models::configs;
use diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
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,
};
pub async fn update_organization(
state: SessionState,
org_id: api::OrganizationId,
req: api::OrganizationUpdateRequest,
) -> RouterResponse<api::OrganizationResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use diesel_models::{business_profile::CardTestingGuardConfig, organization::OrganizationBridge};
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,
};
pub async fn create_organization(
state: SessionState,
req: api::OrganizationCreateRequest,
) -> RouterResponse<api::OrganizationResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
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 add_publishable_key_to_decision_service(
state: &SessionState,
merchant_account: &domain::MerchantAccount,
) {
<|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 diesel_models::configs;
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 insert_merchant_configs(
db: &dyn StorageInterface,
merchant_id: &id_type::MerchantId,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use uuid::Uuid;
pub fn create_merchant_publishable_key() -> String {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
use std::str::FromStr;
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 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,
};
async fn connector_recipient_create_call(
state: &SessionState,
merchant_id: &id_type::MerchantId,
connector_name: String,
auth: &types::ConnectorAuthType,
data: &types::MerchantAccountData,
) -> RouterResult<String> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
state: SessionState,
req: admin_types::MerchantKeyTransferRequest,
) -> RouterResponse<admin_types::TransferKeyResponse> {
let resp = transfer_encryption_key(&state, req).await?;
Ok(service_api::ApplicationResponse::Json(
admin_types::TransferKeyResponse {
total_transferred: resp,
},
))
}
async fn process_open_banking_connectors(
state: &SessionState,
merchant_id: &id_type::MerchantId,
auth: &types::ConnectorAuthType,
connector_type: &api_enums::ConnectorType,
connector: &api_enums::Connector,
additional_merchant_data: types::AdditionalMerchantData,
) -> RouterResult<types::MerchantRecipientData> {
let new_merchant_data = match additional_merchant_data {
types::AdditionalMerchantData::OpenBankingRecipientData(merchant_data) => {
if connector_type != &api_enums::ConnectorType::PaymentProcessor {
return Err(errors::ApiErrorResponse::InvalidConnectorConfiguration {
config:
async fn process_open_banking_connectors(
state: &SessionState,
merchant_id: &id_type::MerchantId,
auth: &types::ConnectorAuthType,
connector_type: &api_enums::ConnectorType,
connector: &api_enums::Connector,
additional_merchant_data: types::AdditionalMerchantData,
) -> RouterResult<types::MerchantRecipientData> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
is_clear_pan_retries_enabled: self.is_clear_pan_retries_enabled,
force_3ds_challenge: self.force_3ds_challenge, //
is_debit_routing_enabled: self.is_debit_routing_enabled.unwrap_or_default(),
merchant_business_country: self.merchant_business_country,
},
)))
}
}
#[cfg(all(feature = "olap", feature = "v2"))]
#[async_trait::async_trait]
impl ProfileUpdateBridge for api::ProfileUpdate {
async fn get_update_profile_object(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &domain::Profile,
) -> RouterResult<domain::ProfileUpdate> {
if let Some(session_expiry) = &self.session_expiry {
helpers::validate_session_expiry(session_expiry.to_owned())?;
}
let webhook_details = self.webhook_details.map(ForeignInto::foreign_into);
let payment_link_config = self
async fn get_update_profile_object(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
business_profile: &domain::Profile,
) -> RouterResult<domain::ProfileUpdate> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
})
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("error while generating card testing secret key")?,
is_clear_pan_retries_enabled: self.is_clear_pan_retries_enabled.unwrap_or_default(),
force_3ds_challenge: self.force_3ds_challenge.unwrap_or_default(),
is_debit_routing_enabled: self.is_debit_routing_enabled.unwrap_or_default(),
merchant_business_country: self.merchant_business_country,
}))
}
#[cfg(feature = "v2")]
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
merchant_id: &id_type::MerchantId,
) -> RouterResult<domain::Profile> {
if let Some(session_expiry) = &self.session_expiry {
helpers::validate_session_expiry(session_expiry.to_owned())?;
}
// Generate a unique profile id
// TODO: the profile_id should be generated from the profile_name
let profile_id = common_utils::generate_profile_id_of_default_length();
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: &domain::MerchantKeyStore,
merchant_id: &id_type::MerchantId,
) -> RouterResult<domain::Profile> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
})?;
Ok(business_profile)
}
_ => Err(report!(errors::ApiErrorResponse::MissingRequiredField {
field_name: "profile_id or business_country, business_label"
})),
},
}
}
}
pub async fn create_connector(
state: SessionState,
req: api::MerchantConnectorCreate,
merchant_account: domain::MerchantAccount,
auth_profile_id: Option<id_type::ProfileId>,
key_store: domain::MerchantKeyStore,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
let store = state.store.as_ref();
let key_manager_state = &(&state).into();
#[cfg(feature = "dummy_connector")]
fp_utils::when(
req.connector_name
.validate_dummy_connector_create(state.conf.dummy_connector.enabled),
pub async fn create_connector(
state: SessionState,
req: api::MerchantConnectorCreate,
merchant_account: domain::MerchantAccount,
auth_profile_id: Option<id_type::ProfileId>,
key_store: domain::MerchantKeyStore,
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
{let store = state.store.as_ref();let key_manager_state = &(&state).into();<|fim_suffix|>
<|fim_middle|>
let mca_response = mca.foreign_try_into()?;Ok(service_api::ApplicationResponse::Json(mca_response))}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
}
Some(vec)
}
None => None,
};
Ok(payment_methods_enabled)
}
}
#[cfg(all(feature = "v1", feature = "olap"))]
#[async_trait::async_trait]
impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
business_profile: &domain::Profile,
key_manager_state: &KeyManagerState,
) -> RouterResult<domain::MerchantConnectorAccount> {
// If connector label is not passed in the request, generate one
let connector_label = self
.connector_label
.clone()
.or(core_utils::get_connector_label(
self.business_country,
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
business_profile: &domain::Profile,
key_manager_state: &KeyManagerState,
) -> RouterResult<domain::MerchantConnectorAccount> {
{
Some(connector_webhook_details) => {
connector_webhook_details.encode_to_value(
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(format!("Failed to serialize api_models::admin::MerchantConnectorWebhookDetails for Merchant: {:?}", business_profile.merchant_id))
.map(Some)?
.map(Secret::new)
}<|fim_suffix|>
<|fim_middle|>
None => None,
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
async fn validate_and_get_business_profile(
self,
merchant_account: &domain::MerchantAccount,
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile>;
}
#[cfg(all(feature = "v2", feature = "olap",))]
#[async_trait::async_trait]
impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
business_profile: &domain::Profile,
key_manager_state: &KeyManagerState,
) -> RouterResult<domain::MerchantConnectorAccount> {
// If connector label is not passed in the request, generate one
let connector_label = self.get_connector_label(business_profile.profile_name.clone());
let frm_configs = self.get_frm_config_as_secret();
let payment_methods_enabled = self.payment_methods_enabled;
// Validate Merchant api details and return error if not in correct format
let auth = types::ConnectorAuthType::from_option_secret_value(
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
business_profile: &domain::Profile,
key_manager_state: &KeyManagerState,
) -> RouterResult<domain::MerchantConnectorAccount> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
merchant_id,
merchant_connector_id,
key_store,
)
.await
.to_not_found_response(
errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: merchant_connector_id.get_string_repr().to_string(),
},
)
}
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
mca: &domain::MerchantConnectorAccount,
key_manager_state: &KeyManagerState,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<domain::MerchantConnectorAccountUpdate> {
let payment_methods_enabled = self.payment_methods_enabled.map(|pm_enabled| {
pm_enabled
.iter()
.flat_map(Encode::encode_to_value)
.map(Secret::new)
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
mca: &domain::MerchantConnectorAccount,
key_manager_state: &KeyManagerState,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<domain::MerchantConnectorAccountUpdate> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
trait MerchantAccountUpdateBridge {
async fn get_update_merchant_object(
self,
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<storage::MerchantAccountUpdate>;
}
#[cfg(feature = "v1")]
#[async_trait::async_trait]
impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate {
async fn get_update_merchant_object(
self,
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<storage::MerchantAccountUpdate> {
let key_manager_state = &state.into();
let key = key_store.key.get_inner().peek();
let db = state.store.as_ref();
let primary_business_details = self.get_primary_details_as_value().change_context(
errors::ApiErrorResponse::InvalidDataValue {
async fn get_update_merchant_object(
self,
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<storage::MerchantAccountUpdate> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
trait MerchantAccountCreateBridge {
async fn create_domain_model_from_request(
self,
state: &SessionState,
key: domain::MerchantKeyStore,
identifier: &id_type::MerchantId,
) -> RouterResult<domain::MerchantAccount>;
}
#[cfg(all(feature = "v1", feature = "olap"))]
#[async_trait::async_trait]
impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
identifier: &id_type::MerchantId,
) -> RouterResult<domain::MerchantAccount> {
let db = &*state.accounts_store;
let publishable_key = create_merchant_publishable_key();
let primary_business_details = self.get_primary_details_as_value().change_context(
errors::ApiErrorResponse::InvalidDataValue {
field_name: "primary_business_details",
},
async fn create_domain_model_from_request(
self,
state: &SessionState,
key_store: domain::MerchantKeyStore,
identifier: &id_type::MerchantId,
) -> RouterResult<domain::MerchantAccount> {
{let db = &*state.accounts_store;<|fim_suffix|>
<|fim_middle|>
Ok(domain_merchant_account)}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
}
#[cfg(all(feature = "v2", feature = "olap"))]
{
CreateOrValidateOrganization::new(org_id.organization_id)
.create_or_validate(state.accounts_store.as_ref())
.await
.map(ForeignFrom::foreign_from)
.map(service_api::ApplicationResponse::Json)
}
}
#[cfg(feature = "olap")]
pub async fn create_merchant_account(
state: SessionState,
req: api::MerchantAccountCreate,
) -> RouterResponse<api::MerchantAccountResponse> {
#[cfg(feature = "keymanager_create")]
use common_utils::{keymanager, types::keymanager::EncryptionTransferRequest};
let db = state.store.as_ref();
let key = services::generate_aes256_key()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to generate aes 256 key")?;
pub async fn create_merchant_account(
state: SessionState,
req: api::MerchantAccountCreate,
) -> RouterResponse<api::MerchantAccountResponse> {
{#[cfg(feature = "keymanager_create")]<|fim_suffix|>
<|fim_middle|>
Ok(service_api::ApplicationResponse::Json(
api::MerchantAccountResponse::foreign_try_from(merchant_account)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while generating response")?,
))}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
async fn create_domain_model_from_request(
self,
state: &SessionState,
key: &domain::MerchantKeyStore,
merchant_id: &id_type::MerchantId,
) -> RouterResult<domain::Profile>;
}
#[cfg(feature = "olap")]
#[async_trait::async_trait]
impl ProfileCreateBridge for api::ProfileCreate {
#[cfg(feature = "v1")]
async fn create_domain_model_from_request(
self,
state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
use common_utils::ext_traits::AsyncExt;
if let Some(session_expiry) = &self.session_expiry {
helpers::validate_session_expiry(session_expiry.to_owned())?;
}
if let Some(intent_fulfillment_expiry) = self.intent_fulfillment_time {
async fn create_domain_model_from_request(
self,
state: &SessionState,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<domain::Profile> {
{use common_utils::ext_traits::AsyncExt;<|fim_suffix|>
<|fim_middle|>
Ok(domain::Profile::from(domain::ProfileSetter {
profile_id,
merchant_id: merchant_account.get_id().clone(),
profile_name,
created_at: current_time,
modified_at: current_time,
return_url: self
.return_url
.map(|return_url| return_url.to_string())
.or(merchant_account.return_url.clone()),
enable_payment_response_hash: self
.enable_payment_response_hash
.unwrap_or(merchant_account.enable_payment_response_hash),
payment_response_hash_key: Some(payment_response_hash_key),
redirect_to_merchant_with_http_post: self
.redirect_to_merchant_with_http_post
.unwrap_or(merchant_account.redirect_to_merchant_with_http_post),
webhook_details: webhook_details.or(merchant_account.webhook_details.clone()),
metadata: self.metadata,
routing_algorithm: None,
intent_fulfillment_time: self
.intent_fulfillment_time
.map(i64::from)
.or(merchant_account.intent_fulfillment_time)
.or(Some(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME)),
frm_routing_algorithm: self
.frm_routing_algorithm
.or(merchant_account.frm_routing_algorithm.clone()),
#[cfg(feature = "payouts")]
payout_routing_algorithm: self
.payout_routing_algorithm
.or(merchant_account.payout_routing_algorithm.clone()),
#[cfg(not(feature = "payouts"))]
payout_routing_algorithm: None,
is_recon_enabled: merchant_account.is_recon_enabled,
applepay_verified_domains: self.applepay_verified_domains,
payment_link_config,
session_expiry: self
.session_expiry
.map(i64::from)
.or(Some(common_utils::consts::DEFAULT_SESSION_EXPIRY)),
authentication_connector_details: self
.authentication_connector_details
.map(ForeignInto::foreign_into),
payout_link_config,
is_connector_agnostic_mit_enabled: self.is_connector_agnostic_mit_enabled,
is_extended_card_info_enabled: None,
extended_card_info_config: None,
use_billing_as_payment_method_billing: self
.use_billing_as_payment_method_billing
.or(Some(true)),
collect_shipping_details_from_wallet_connector: self
.collect_shipping_details_from_wallet_connector
.or(Some(false)),
collect_billing_details_from_wallet_connector: self
.collect_billing_details_from_wallet_connector
.or(Some(false)),
outgoing_webhook_custom_http_headers,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: self.is_tax_connector_enabled,
always_collect_billing_details_from_wallet_connector: self
.always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector: self
.always_collect_shipping_details_from_wallet_connector,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
is_auto_retries_enabled: self.is_auto_retries_enabled.unwrap_or_default(),
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
always_request_extended_authorization: self.always_request_extended_authorization,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids: self.authentication_product_ids,
card_testing_guard_config,
card_testing_secret_key: card_testing_secret_key
.async_lift(|inner| async {
domain_types::crypto_operation(
&key_manager_state,
common_utils::type_name!(domain::Profile),
domain_types::CryptoOperation::EncryptOptional(inner),
km_types::Identifier::Merchant(key_store.merchant_id.clone()),
key.peek(),
)
.await
.and_then(|val| val.try_into_optionaloperation())
})
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("error while generating card testing secret key")?,
is_clear_pan_retries_enabled: self.is_clear_pan_retries_enabled.unwrap_or_default(),
force_3ds_challenge: self.force_3ds_challenge.unwrap_or_default(),
is_debit_routing_enabled: self.is_debit_routing_enabled.unwrap_or_default(),
merchant_business_country: self.merchant_business_country,
}))}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/admin.rs | crate: router
}),
errors::ConnectorError::FailedToObtainAuthType => {
err.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "The auth type is invalid for the connector".to_string(),
})
}
_ => err.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "The request body is invalid".to_string(),
}),
})
}
fn validate_auth_and_metadata_type_with_connector(
&self,
) -> Result<(), error_stack::Report<errors::ConnectorError>> {
use crate::connector::*;
match self.connector_name {
api_enums::Connector::Adyenplatform => {
adyenplatform::transformers::AdyenplatformAuthType::try_from(self.auth_type)?;
Ok(())
}
// api_enums::Connector::Payone => {payone::transformers::PayoneAuthType::try_from(val)?;Ok(())} Added as a template code for future usage
#[cfg(feature = "dummy_connector")]
api_enums::Connector::DummyConnector1
fn validate_auth_and_metadata_type_with_connector(
&self,
) -> Result<(), error_stack::Report<errors::ConnectorError>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/api_locking.rs | crate: router
use redis_interface as redis;
use router_env::{instrument, logger, tracing};
use super::errors::{self, RouterResult};
use crate::routes::{app::SessionStateInfo, lock_utils};
pub async fn free_lock_action<A>(
self,
state: &A,
merchant_id: common_utils::id_type::MerchantId,
) -> RouterResult<()>
where
A: SessionStateInfo,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/api_locking.rs | crate: router
use actix_web::rt::time as actix_time;
use error_stack::{report, ResultExt};
use redis_interface as redis;
use router_env::{instrument, logger, tracing};
use super::errors::{self, RouterResult};
use crate::routes::{app::SessionStateInfo, lock_utils};
pub async fn perform_locking_action<A>(
self,
state: &A,
merchant_id: common_utils::id_type::MerchantId,
) -> RouterResult<()>
where
A: SessionStateInfo,
{
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/api_locking.rs | crate: router
use actix_web::rt::time as actix_time;
use error_stack::{report, ResultExt};
use redis_interface as redis;
use router_env::{instrument, logger, tracing};
use super::errors::{self, RouterResult};
use crate::routes::{app::SessionStateInfo, lock_utils};
pub async fn perform_locking_action<A>(
self,
state: &A,
merchant_id: common_utils::id_type::MerchantId,
) -> RouterResult<()>
where
A: SessionStateInfo,
{
{
Ok(redis::SetnxReply::KeySet) => {
logger::info!("Lock acquired for locking input {:?}", input);
tracing::Span::current()
.record("redis_lock_acquired", redis_locking_key);
return Ok(());
}<|fim_suffix|>
<|fim_middle|>
Err(err) => {
return Err(err)
.change_context(errors::ApiErrorResponse::InternalServerError)
}
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/api_locking.rs | crate: router
use super::errors::{self, RouterResult};
fn get_redis_locking_key(&self, merchant_id: common_utils::id_type::MerchantId) -> String {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch/crates/router/src/core/api_locking.rs | crate: router
use super::errors::{self, RouterResult};
fn get_redis_locking_key(&self, merchant_id: common_utils::id_type::MerchantId) -> String {
format!(
"{}_{}_{}_{}",
API_LOCK_PREFIX,
merchant_id.get_string_repr(),
self.api_identifier,
self.unique_locking_key
)
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
async fn get_selected_config_from_redis(
db: &dyn StorageInterface,
payload: &api_models::pm_auth::ExchangeTokenCreateRequest,
) -> RouterResult<api_models::pm_auth::PaymentMethodAuthConnectorChoice> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use std::{collections::HashMap, str::FromStr};
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use masking::{ExposeInterface, PeekInterface, Secret};
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
async fn get_access_token_from_exchange_api(
connector: &PaymentAuthConnectorData,
connector_name: &str,
payload: &api_models::pm_auth::ExchangeTokenCreateRequest,
auth_type: &pm_auth_types::ConnectorAuthType,
state: &SessionState,
) -> RouterResult<Secret<String>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use std::{collections::HashMap, str::FromStr};
use masking::{ExposeInterface, PeekInterface, Secret};
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
pub async fn get_bank_account_creds(
connector: PaymentAuthConnectorData,
merchant_account: &domain::MerchantAccount,
connector_name: &str,
access_token: &Secret<String>,
auth_type: pm_auth_types::ConnectorAuthType,
state: &SessionState,
bank_account_id: Option<Secret<String>>,
) -> RouterResult<pm_auth_types::BankAccountCredentialsResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use common_enums::{enums::MerchantStorageScheme, PaymentMethodType};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
async fn store_in_db(
state: &SessionState,
key_store: &domain::MerchantKeyStore,
update_entries: Vec<(domain::PaymentMethod, storage::PaymentMethodUpdate)>,
new_entries: Vec<domain::PaymentMethod>,
db: &dyn StorageInterface,
storage_scheme: MerchantStorageScheme,
) -> RouterResult<()> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use helpers::PaymentAuthConnectorDataExt;
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
pub async fn exchange_token_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::ExchangeTokenCreateRequest,
) -> RouterResponse<()> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
_state: SessionState,
_merchant_account: domain::MerchantAccount,
_key_store: domain::MerchantKeyStore,
_payload: api_models::pm_auth::LinkTokenCreateRequest,
_headers: Option<hyperswitch_domain_models::payments::HeaderPayload>,
) -> RouterResponse<api_models::pm_auth::LinkTokenCreateResponse> {
todo!()
}
impl ForeignTryFrom<&types::ConnectorAuthType> for PlaidAuthType {
type Error = errors::ConnectorError;
fn foreign_try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
match auth_type {
types::ConnectorAuthType::BodyKey { api_key, key1 } => {
Ok::<Self, errors::ConnectorError>(Self {
client_id: api_key.to_owned(),
secret: key1.to_owned(),
})
}
_ => Err(errors::ConnectorError::FailedToObtainAuthType),
}
}
}
fn foreign_try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
{
types::ConnectorAuthType::BodyKey { api_key, key1 } => {
Ok::<Self, errors::ConnectorError>(Self {
client_id: api_key.to_owned(),
secret: key1.to_owned(),
})
}<|fim_suffix|>
<|fim_middle|>
_ => Err(errors::ConnectorError::FailedToObtainAuthType),
}
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use std::{collections::HashMap, str::FromStr};
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use common_utils::{
consts,
crypto::{HmacSha256, SignMessage},
ext_traits::{AsyncExt, ValueExt},
generate_id,
types::{self as util_types, AmountConvertor},
};
use masking::{ExposeInterface, PeekInterface, Secret};
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
async fn store_bank_details_in_payment_methods(
_key_store: domain::MerchantKeyStore,
_payload: api_models::pm_auth::ExchangeTokenCreateRequest,
_merchant_account: domain::MerchantAccount,
_state: SessionState,
_bank_account_details_resp: pm_auth_types::BankAccountCredentialsResponse,
_connector_details: (&str, Secret<String>),
_mca_id: common_utils::id_type::MerchantConnectorAccountId,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use hyperswitch_domain_models::payments::PaymentIntent;
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
pub async fn create_link_token(
_state: SessionState,
_merchant_account: domain::MerchantAccount,
_key_store: domain::MerchantKeyStore,
_payload: api_models::pm_auth::LinkTokenCreateRequest,
_headers: Option<hyperswitch_domain_models::payments::HeaderPayload>,
) -> RouterResponse<api_models::pm_auth::LinkTokenCreateResponse> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use common_enums::{enums::MerchantStorageScheme, PaymentMethodType};
use common_utils::{
consts,
crypto::{HmacSha256, SignMessage},
ext_traits::{AsyncExt, ValueExt},
generate_id,
types::{self as util_types, AmountConvertor},
};
use hyperswitch_domain_models::payments::PaymentIntent;
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
pub async fn retrieve_payment_method_from_auth_service(
state: &SessionState,
key_store: &domain::MerchantKeyStore,
auth_token: &payment_methods::BankAccountTokenData,
payment_intent: &PaymentIntent,
_customer: &Option<domain::Customer>,
) -> RouterResult<Option<(domain::PaymentMethodData, enums::PaymentMethod)>> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use std::{collections::HashMap, str::FromStr};
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use common_enums::{enums::MerchantStorageScheme, PaymentMethodType};
use hex;
use common_utils::{
consts,
crypto::{HmacSha256, SignMessage},
ext_traits::{AsyncExt, ValueExt},
generate_id,
types::{self as util_types, AmountConvertor},
};
use masking::{ExposeInterface, PeekInterface, Secret};
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
async fn store_bank_details_in_payment_methods(
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::ExchangeTokenCreateRequest,
merchant_account: domain::MerchantAccount,
state: SessionState,
bank_account_details_resp: pm_auth_types::BankAccountCredentialsResponse,
connector_details: (&str, Secret<String>),
mca_id: common_utils::id_type::MerchantConnectorAccountId,
) -> RouterResult<()> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/pm_auth.rs | crate: router
use std::{collections::HashMap, str::FromStr};
use api_models::{
enums,
payment_methods::{self, BankAccountAccessCreds},
};
use helpers::PaymentAuthConnectorDataExt;
use hyperswitch_domain_models::payments::PaymentIntent;
use pm_auth::{
connector::plaid::transformers::PlaidAuthType,
types::{
self as pm_auth_types,
api::{
auth_service::{BankAccountCredentials, ExchangeToken, LinkToken},
BoxedConnectorIntegration, PaymentAuthConnectorData,
},
},
};
use crate::{
core::{
errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt},
payment_methods::cards,
payments::helpers as oss_helpers,
pm_auth::helpers as pm_auth_helpers,
},
db::StorageInterface,
logger,
routes::SessionState,
services::{pm_auth as pm_auth_services, ApplicationResponse},
types::{self, domain, storage, transformers::ForeignTryFrom},
};
pub async fn create_link_token(
state: SessionState,
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
payload: api_models::pm_auth::LinkTokenCreateRequest,
headers: Option<hyperswitch_domain_models::payments::HeaderPayload>,
) -> RouterResponse<api_models::pm_auth::LinkTokenCreateResponse> {
{let db = &*state.store;<|fim_suffix|>
<|fim_middle|>
Ok(ApplicationResponse::Json(response))}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use api_models::{
payment_methods::PaymentMethodDataWalletInfo, payments::ConnectorMandateReferenceId,
};
use hyperswitch_domain_models::mandates::{
CommonMandateReference, PaymentsMandateReference, PaymentsMandateReferenceRecord,
};
use super::helpers;
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub async fn add_token_for_payment_method(
router_data: &mut types::RouterData<
api::PaymentMethodToken,
types::PaymentMethodTokenizationData,
types::PaymentsResponseData,
>,
payment_method_data_request: types::PaymentMethodTokenizationData,
state: SessionState,
merchant_connector_account_details: &hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccount,
) -> RouterResult<types::PspTokenResult> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use api_models::{
payment_methods::PaymentMethodDataWalletInfo, payments::ConnectorMandateReferenceId,
};
use common_enums::{ConnectorMandateStatus, PaymentMethod};
use common_utils::{
crypto::Encryptable,
ext_traits::{AsyncExt, Encode, ValueExt},
id_type, pii,
};
use hyperswitch_domain_models::mandates::{
CommonMandateReference, PaymentsMandateReference, PaymentsMandateReferenceRecord,
};
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub fn update_connector_mandate_details_status(
merchant_connector_id: id_type::MerchantConnectorAccountId,
mut payment_mandate_reference: PaymentsMandateReference,
status: ConnectorMandateStatus,
) -> RouterResult<Option<CommonMandateReference>> {
let mandate_reference = {
payment_mandate_reference
.entry(merchant_connector_id)
.and_modify(|pm| {
let update_rec = PaymentsMandateReferenceRecord {
connector_mandate_id: pm.connector_mandate_id.clone(),
payment_method_type: pm.payment_method_type,
original_payment_authorized_amount: pm.original_payment_authorized_amount,
original_payment_authorized_currency: pm.original_payment_authorized_currency,
mandate_metadata: pm.mandate_metadata.clone(),
connector_mandate_status: Some(status),
connector_mandate_request_reference_id: pm
.connector_mandate_request_reference_id
.clone(),
};
*pm = update_rec
});
Some(payment_mandate_reference)
};
Ok(Some(CommonMandateReference {
payments: mandate_reference,
payouts: None,
}))
} | ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use api_models::{
payment_methods::PaymentMethodDataWalletInfo, payments::ConnectorMandateReferenceId,
};
use common_enums::{ConnectorMandateStatus, PaymentMethod};
use common_utils::{
crypto::Encryptable,
ext_traits::{AsyncExt, Encode, ValueExt},
id_type, pii,
};
use hyperswitch_domain_models::mandates::{
CommonMandateReference, PaymentsMandateReference, PaymentsMandateReferenceRecord,
};
use masking::{ExposeInterface, Secret};
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub fn update_connector_mandate_details(
mandate_details: Option<CommonMandateReference>,
payment_method_type: Option<storage_enums::PaymentMethodType>,
authorized_amount: Option<i64>,
authorized_currency: Option<storage_enums::Currency>,
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
connector_mandate_id: Option<String>,
mandate_metadata: Option<Secret<serde_json::Value>>,
connector_mandate_request_reference_id: Option<String>,
) -> RouterResult<Option<CommonMandateReference>> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use std::collections::HashMap;
use api_models::{
payment_methods::PaymentMethodDataWalletInfo, payments::ConnectorMandateReferenceId,
};
use common_enums::{ConnectorMandateStatus, PaymentMethod};
use common_utils::{
crypto::Encryptable,
ext_traits::{AsyncExt, Encode, ValueExt},
id_type, pii,
};
use hyperswitch_domain_models::mandates::{
CommonMandateReference, PaymentsMandateReference, PaymentsMandateReferenceRecord,
};
use masking::{ExposeInterface, Secret};
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub fn add_connector_mandate_details_in_payment_method(
payment_method_type: Option<storage_enums::PaymentMethodType>,
authorized_amount: Option<i64>,
authorized_currency: Option<storage_enums::Currency>,
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
connector_mandate_id: Option<String>,
mandate_metadata: Option<Secret<serde_json::Value>>,
connector_mandate_request_reference_id: Option<String>,
) -> Option<CommonMandateReference> {
{<|fim_suffix|>
<|fim_middle|>
}}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use hyperswitch_domain_models::mandates::{
CommonMandateReference, PaymentsMandateReference, PaymentsMandateReferenceRecord,
};
use masking::{ExposeInterface, Secret};
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub fn update_router_data_with_payment_method_token_result<F: Clone, T>(
payment_method_token_result: types::PaymentMethodTokenResult,
router_data: &mut types::RouterData<F, T, types::PaymentsResponseData>,
is_retry_payment: bool,
should_continue_further: bool,
) -> bool {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use api_models::payment_methods::PaymentMethodsData;
use api_models::{
payment_methods::PaymentMethodDataWalletInfo, payments::ConnectorMandateReferenceId,
};
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub async fn save_network_token_in_locker(
state: &SessionState,
merchant_account: &domain::MerchantAccount,
card_data: &domain::Card,
payment_method_request: api::PaymentMethodCreate,
) -> RouterResult<(
Option<api_models::payment_methods::PaymentMethodResponse>,
Option<payment_methods::transformers::DataDuplicationCheck>,
Option<String>,
)> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
<|fim_prefix|>
// file: hyperswitch/crates/router/src/core/payments/tokenization.rs | crate: router
use api_models::payment_methods::PaymentMethodsData;
use api_models::{
payment_methods::PaymentMethodDataWalletInfo, payments::ConnectorMandateReferenceId,
};
use common_utils::{
crypto::Encryptable,
ext_traits::{AsyncExt, Encode, ValueExt},
id_type, pii,
};
use crate::{
consts,
core::{
errors::{self, ConnectorErrorExt, RouterResult, StorageErrorExt},
mandate,
payment_methods::{self, cards::create_encrypted_data, network_tokenization},
payments,
},
logger,
routes::{metrics, SessionState},
services,
types::{
self,
api::{self, CardDetailFromLocker, CardDetailsPaymentMethod, PaymentMethodCreateExt},
domain,
storage::enums as storage_enums,
},
utils::{generate_id, OptionExt},
};
pub async fn save_in_locker(
state: &SessionState,
merchant_account: &domain::MerchantAccount,
payment_method_request: api::PaymentMethodCreate,
) -> RouterResult<(
api_models::payment_methods::PaymentMethodResponse,
Option<payment_methods::transformers::DataDuplicationCheck>,
)> {
<|fim_suffix|>
<|fim_middle|>
}
| ast_fragments |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.