diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs index 0f87748d27..b3ef64b3e3 100644 --- a/crates/diesel_models/src/merchant_account.rs +++ b/crates/diesel_models/src/merchant_account.rs @@ -56,6 +56,7 @@ pub struct MerchantAccount { pub recon_status: storage_enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, + pub version: common_enums::ApiVersion, } #[cfg(all( @@ -90,6 +91,7 @@ pub struct MerchantAccountSetter { pub recon_status: storage_enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, + pub version: common_enums::ApiVersion, } #[cfg(all( @@ -126,6 +128,7 @@ impl From for MerchantAccount { recon_status: item.recon_status, payment_link_config: item.payment_link_config, pm_collect_link_config: item.pm_collect_link_config, + version: item.version, } } } @@ -151,14 +154,12 @@ pub struct MerchantAccount { pub publishable_key: Option, pub storage_scheme: storage_enums::MerchantStorageScheme, pub metadata: Option, - pub routing_algorithm: Option, pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, - pub frm_routing_algorithm: Option, - pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: storage_enums::ReconStatus, pub id: common_utils::id_type::MerchantId, + pub version: common_enums::ApiVersion, } #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] @@ -173,11 +174,9 @@ impl From for MerchantAccount { metadata: item.metadata, created_at: item.created_at, modified_at: item.modified_at, - frm_routing_algorithm: item.frm_routing_algorithm, - routing_algorithm: item.routing_algorithm, - payout_routing_algorithm: item.payout_routing_algorithm, organization_id: item.organization_id, recon_status: item.recon_status, + version: item.version, } } } @@ -190,13 +189,11 @@ pub struct MerchantAccountSetter { pub publishable_key: Option, pub storage_scheme: storage_enums::MerchantStorageScheme, pub metadata: Option, - pub routing_algorithm: Option, pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, - pub frm_routing_algorithm: Option, - pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: storage_enums::ReconStatus, + pub version: common_enums::ApiVersion, } impl MerchantAccount { @@ -248,6 +245,7 @@ pub struct MerchantAccountNew { pub recon_status: storage_enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, + pub version: common_enums::ApiVersion, } #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] @@ -258,14 +256,12 @@ pub struct MerchantAccountNew { pub merchant_details: Option, pub publishable_key: Option, pub metadata: Option, - pub routing_algorithm: Option, pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, - pub frm_routing_algorithm: Option, - pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: storage_enums::ReconStatus, pub id: common_utils::id_type::MerchantId, + pub version: common_enums::ApiVersion, } #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] @@ -277,10 +273,7 @@ pub struct MerchantAccountUpdateInternal { pub publishable_key: Option, pub storage_scheme: Option, pub metadata: Option, - pub routing_algorithm: Option, pub modified_at: time::PrimitiveDateTime, - pub frm_routing_algorithm: Option, - pub payout_routing_algorithm: Option, pub organization_id: Option, pub recon_status: Option, } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 08a4e68c88..a1df3a889c 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -665,6 +665,7 @@ diesel::table! { recon_status -> ReconStatus, payment_link_config -> Nullable, pm_collect_link_config -> Nullable, + version -> ApiVersion, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index b5cfc00ae1..8821c7c897 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -647,16 +647,14 @@ diesel::table! { publishable_key -> Nullable, storage_scheme -> MerchantStorageScheme, metadata -> Nullable, - routing_algorithm -> Nullable, created_at -> Timestamp, modified_at -> Timestamp, - frm_routing_algorithm -> Nullable, - payout_routing_algorithm -> Nullable, #[max_length = 32] organization_id -> Varchar, recon_status -> ReconStatus, #[max_length = 64] id -> Varchar, + version -> ApiVersion, } } diff --git a/crates/hyperswitch_domain_models/src/consts.rs b/crates/hyperswitch_domain_models/src/consts.rs new file mode 100644 index 0000000000..8499cd3d82 --- /dev/null +++ b/crates/hyperswitch_domain_models/src/consts.rs @@ -0,0 +1,14 @@ +//! Constants that are used in the domain models. + +#[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "customer_v2"), + not(feature = "merchant_account_v2") +))] +pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V1; + +#[cfg(all( + feature = "v2", + any(feature = "customer_v2", feature = "merchant_account_v2") +))] +pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V2; diff --git a/crates/hyperswitch_domain_models/src/customer.rs b/crates/hyperswitch_domain_models/src/customer.rs index b1a8f8dfdb..7f217632de 100644 --- a/crates/hyperswitch_domain_models/src/customer.rs +++ b/crates/hyperswitch_domain_models/src/customer.rs @@ -1,7 +1,6 @@ use api_models::customers::CustomerRequestWithEncryption; // #[cfg(all(feature = "v2", feature = "customer_v2"))] // use common_enums::SoftDeleteStatus; -use common_enums::ApiVersion; use common_utils::{ crypto, date_time, encryption::Encryption, @@ -36,7 +35,7 @@ pub struct Customer { pub address_id: Option, pub default_payment_method_id: Option, pub updated_by: Option, - pub version: ApiVersion, + pub version: common_enums::ApiVersion, } #[cfg(all(feature = "v2", feature = "customer_v2"))] @@ -54,12 +53,12 @@ pub struct Customer { pub modified_at: PrimitiveDateTime, pub default_payment_method_id: Option, pub updated_by: Option, - pub version: ApiVersion, pub merchant_reference_id: Option, pub default_billing_address: Option, pub default_shipping_address: Option, // pub status: Option, pub id: String, + pub version: common_enums::ApiVersion, } #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] @@ -196,8 +195,8 @@ impl super::behaviour::Conversion for Customer { updated_by: self.updated_by, default_billing_address: self.default_billing_address.map(Encryption::from), default_shipping_address: self.default_shipping_address.map(Encryption::from), - // status: self.status, version: self.version, + // status: self.status, }) } @@ -250,8 +249,8 @@ impl super::behaviour::Conversion for Customer { updated_by: item.updated_by, default_billing_address: item.default_billing_address, default_shipping_address: item.default_shipping_address, - // status: item.status, version: item.version, + // status: item.status, }) } @@ -275,7 +274,7 @@ impl super::behaviour::Conversion for Customer { default_billing_address: self.default_billing_address, default_shipping_address: self.default_shipping_address, // status: self.status, - version: self.version, + version: crate::consts::API_VERSION, }) } } diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs index cabeda2ccc..85f3511691 100644 --- a/crates/hyperswitch_domain_models/src/lib.rs +++ b/crates/hyperswitch_domain_models/src/lib.rs @@ -1,6 +1,7 @@ pub mod api; pub mod behaviour; pub mod business_profile; +pub mod consts; pub mod customer; pub mod errors; pub mod mandates; diff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rs index 27592e84a4..c86dff60ea 100644 --- a/crates/hyperswitch_domain_models/src/merchant_account.rs +++ b/crates/hyperswitch_domain_models/src/merchant_account.rs @@ -49,6 +49,7 @@ pub struct MerchantAccount { pub recon_status: diesel_models::enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, + pub version: common_enums::ApiVersion, } #[cfg(all( @@ -85,6 +86,7 @@ pub struct MerchantAccountSetter { pub recon_status: diesel_models::enums::ReconStatus, pub payment_link_config: Option, pub pm_collect_link_config: Option, + pub version: common_enums::ApiVersion, } #[cfg(all( @@ -121,6 +123,7 @@ impl From for MerchantAccount { recon_status: item.recon_status, payment_link_config: item.payment_link_config, pm_collect_link_config: item.pm_collect_link_config, + version: item.version, } } } @@ -135,11 +138,8 @@ pub struct MerchantAccountSetter { pub publishable_key: String, pub storage_scheme: MerchantStorageScheme, pub metadata: Option, - pub routing_algorithm: Option, - pub frm_routing_algorithm: Option, pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, - pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: diesel_models::enums::ReconStatus, } @@ -154,11 +154,8 @@ impl From for MerchantAccount { publishable_key, storage_scheme, metadata, - routing_algorithm, - frm_routing_algorithm, created_at, modified_at, - payout_routing_algorithm, organization_id, recon_status, } = item; @@ -169,11 +166,8 @@ impl From for MerchantAccount { publishable_key, storage_scheme, metadata, - routing_algorithm, - frm_routing_algorithm, created_at, modified_at, - payout_routing_algorithm, organization_id, recon_status, } @@ -189,11 +183,8 @@ pub struct MerchantAccount { pub publishable_key: String, pub storage_scheme: MerchantStorageScheme, pub metadata: Option, - pub routing_algorithm: Option, - pub frm_routing_algorithm: Option, pub created_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime, - pub payout_routing_algorithm: Option, pub organization_id: common_utils::id_type::OrganizationId, pub recon_status: diesel_models::enums::ReconStatus, } @@ -263,9 +254,6 @@ pub enum MerchantAccountUpdate { merchant_details: OptionalEncryptableValue, publishable_key: Option, metadata: Option, - routing_algorithm: Option, - frm_routing_algorithm: Option, - payout_routing_algorithm: Option, }, StorageSchemeUpdate { storage_scheme: MerchantStorageScheme, @@ -455,20 +443,14 @@ impl From for MerchantAccountUpdateInternal { MerchantAccountUpdate::Update { merchant_name, merchant_details, - routing_algorithm, publishable_key, metadata, - frm_routing_algorithm, - payout_routing_algorithm, } => Self { merchant_name: merchant_name.map(Encryption::from), merchant_details: merchant_details.map(Encryption::from), - frm_routing_algorithm, - routing_algorithm, publishable_key, metadata, modified_at: now, - payout_routing_algorithm, storage_scheme: None, organization_id: None, recon_status: None, @@ -480,9 +462,6 @@ impl From for MerchantAccountUpdateInternal { merchant_details: None, publishable_key: None, metadata: None, - routing_algorithm: None, - frm_routing_algorithm: None, - payout_routing_algorithm: None, organization_id: None, recon_status: None, }, @@ -494,9 +473,6 @@ impl From for MerchantAccountUpdateInternal { publishable_key: None, storage_scheme: None, metadata: None, - routing_algorithm: None, - frm_routing_algorithm: None, - payout_routing_algorithm: None, organization_id: None, }, MerchantAccountUpdate::ModifiedAtUpdate => Self { @@ -506,9 +482,6 @@ impl From for MerchantAccountUpdateInternal { publishable_key: None, storage_scheme: None, metadata: None, - routing_algorithm: None, - frm_routing_algorithm: None, - payout_routing_algorithm: None, organization_id: None, recon_status: None, }, @@ -531,13 +504,11 @@ impl super::behaviour::Conversion for MerchantAccount { publishable_key: Some(self.publishable_key), storage_scheme: self.storage_scheme, metadata: self.metadata, - routing_algorithm: self.routing_algorithm, created_at: self.created_at, modified_at: self.modified_at, - frm_routing_algorithm: self.frm_routing_algorithm, - payout_routing_algorithm: self.payout_routing_algorithm, organization_id: self.organization_id, recon_status: self.recon_status, + version: crate::consts::API_VERSION, }; Ok(diesel_models::MerchantAccount::from(setter)) @@ -593,11 +564,8 @@ impl super::behaviour::Conversion for MerchantAccount { publishable_key, storage_scheme: item.storage_scheme, metadata: item.metadata, - routing_algorithm: item.routing_algorithm, - frm_routing_algorithm: item.frm_routing_algorithm, created_at: item.created_at, modified_at: item.modified_at, - payout_routing_algorithm: item.payout_routing_algorithm, organization_id: item.organization_id, recon_status: item.recon_status, }) @@ -616,13 +584,11 @@ impl super::behaviour::Conversion for MerchantAccount { merchant_details: self.merchant_details.map(Encryption::from), publishable_key: Some(self.publishable_key), metadata: self.metadata, - routing_algorithm: self.routing_algorithm, created_at: now, modified_at: now, - frm_routing_algorithm: self.frm_routing_algorithm, - payout_routing_algorithm: self.payout_routing_algorithm, organization_id: self.organization_id, recon_status: self.recon_status, + version: crate::consts::API_VERSION, }) } } @@ -664,6 +630,7 @@ impl super::behaviour::Conversion for MerchantAccount { recon_status: self.recon_status, payment_link_config: self.payment_link_config, pm_collect_link_config: self.pm_collect_link_config, + version: self.version, }; Ok(diesel_models::MerchantAccount::from(setter)) @@ -740,6 +707,7 @@ impl super::behaviour::Conversion for MerchantAccount { recon_status: item.recon_status, payment_link_config: item.payment_link_config, pm_collect_link_config: item.pm_collect_link_config, + version: item.version, }) } .await @@ -777,6 +745,7 @@ impl super::behaviour::Conversion for MerchantAccount { recon_status: self.recon_status, payment_link_config: self.payment_link_config, pm_collect_link_config: self.pm_collect_link_config, + version: crate::consts::API_VERSION, }) } } diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs index 383de01cd4..bdf8db2828 100644 --- a/crates/router/src/consts.rs +++ b/crates/router/src/consts.rs @@ -130,9 +130,3 @@ pub const CONNECTOR_CREDS_TOKEN_TTL: i64 = 900; //max_amount allowed is 999999999 in minor units pub const MAX_ALLOWED_AMOUNT: i64 = 999999999; - -#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] -pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V1; - -#[cfg(all(feature = "v2", feature = "customer_v2"))] -pub const API_VERSION: common_enums::ApiVersion = common_enums::ApiVersion::V2; diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 821057764e..5c800a0dc2 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -400,6 +400,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { recon_status: diesel_models::enums::ReconStatus::NotRequested, payment_link_config: None, pm_collect_link_config, + version: hyperswitch_domain_models::consts::API_VERSION, }, ) } @@ -680,17 +681,11 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate { .and_then(|val| val.try_into_optionaloperation()) }) .await?, - routing_algorithm: Some(serde_json::json!({ - "algorithm_id": null, - "timestamp": 0 - })), publishable_key, metadata, storage_scheme: MerchantStorageScheme::PostgresOnly, created_at: date_time::now(), modified_at: date_time::now(), - frm_routing_algorithm: None, - payout_routing_algorithm: None, organization_id: organization.get_organization_id(), recon_status: diesel_models::enums::ReconStatus::NotRequested, }), @@ -955,7 +950,7 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate { key_manager_state, type_name!(storage::MerchantAccount), domain_types::CryptoOperation::EncryptOptional(inner), - km_types::Identifier::Merchant(key_store.merchant_id.clone()), + identifier.clone(), key, ) .await @@ -1049,9 +1044,6 @@ impl MerchantAccountUpdateBridge for api::MerchantAccountUpdate { .attach_printable("Unable to encrypt merchant details")?, metadata, publishable_key: None, - frm_routing_algorithm: None, - payout_routing_algorithm: None, - routing_algorithm: None, }) } } diff --git a/crates/router/src/core/conditional_config.rs b/crates/router/src/core/conditional_config.rs index e845d54ee7..4c96ebc7d2 100644 --- a/crates/router/src/core/conditional_config.rs +++ b/crates/router/src/core/conditional_config.rs @@ -1,28 +1,42 @@ -use api_models::{ - conditional_configs::{DecisionManager, DecisionManagerRecord, DecisionManagerResponse}, - routing, +use api_models::conditional_configs::{ + DecisionManager, DecisionManagerRecord, DecisionManagerResponse, }; -use common_utils::ext_traits::{Encode, StringExt, ValueExt}; -use diesel_models::configs; +use common_utils::ext_traits::StringExt; use error_stack::ResultExt; -use euclid::frontend::ast; -use storage_impl::redis::cache; -use super::routing::helpers::update_merchant_active_algorithm_ref; use crate::{ core::errors::{self, RouterResponse}, routes::SessionState, services::api as service_api, types::domain, - utils::OptionExt, }; +#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] +pub async fn upsert_conditional_config( + _state: SessionState, + _key_store: domain::MerchantKeyStore, + _merchant_account: domain::MerchantAccount, + _request: DecisionManager, +) -> RouterResponse { + todo!() +} + +#[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") +))] pub async fn upsert_conditional_config( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, request: DecisionManager, ) -> RouterResponse { + use common_utils::ext_traits::{Encode, OptionExt, ValueExt}; + use diesel_models::configs; + use storage_impl::redis::cache; + + use super::routing::helpers::update_merchant_active_algorithm_ref; + let db = state.store.as_ref(); let (name, prog) = match request { DecisionManager::DecisionManagerv0(ccr) => { @@ -51,7 +65,7 @@ pub async fn upsert_conditional_config( } }; let timestamp = common_utils::date_time::now_unix_timestamp(); - let mut algo_id: routing::RoutingAlgorithmRef = merchant_account + let mut algo_id: api_models::routing::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() .map(|val| val.parse_value("routing algorithm")) @@ -63,7 +77,7 @@ pub async fn upsert_conditional_config( let key = merchant_account.get_id().get_payment_config_routing_id(); let read_config_key = db.find_config_by_key(&key).await; - ast::lowering::lower_program(prog.clone()) + euclid::frontend::ast::lowering::lower_program(prog.clone()) .change_context(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid Request Data".to_string(), }) @@ -149,14 +163,32 @@ pub async fn upsert_conditional_config( } } +#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] +pub async fn delete_conditional_config( + _state: SessionState, + _key_store: domain::MerchantKeyStore, + _merchant_account: domain::MerchantAccount, +) -> RouterResponse<()> { + todo!() +} + +#[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") +))] pub async fn delete_conditional_config( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, ) -> RouterResponse<()> { + use common_utils::ext_traits::ValueExt; + use storage_impl::redis::cache; + + use super::routing::helpers::update_merchant_active_algorithm_ref; + let db = state.store.as_ref(); let key = merchant_account.get_id().get_payment_config_routing_id(); - let mut algo_id: routing::RoutingAlgorithmRef = merchant_account + let mut algo_id: api_models::routing::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() .map(|value| value.parse_value("routing algorithm")) diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs index 69bf4052d7..e3169e611f 100644 --- a/crates/router/src/core/customers.rs +++ b/crates/router/src/core/customers.rs @@ -15,7 +15,6 @@ use router_env::{instrument, tracing}; #[cfg(all(feature = "v2", feature = "customer_v2"))] use crate::core::payment_methods::cards::create_encrypted_data; use crate::{ - consts::API_VERSION, core::errors::{self, StorageErrorExt}, db::StorageInterface, pii::PeekInterface, @@ -181,7 +180,7 @@ impl CustomerCreateBridge for customers::CustomerRequest { modified_at: common_utils::date_time::now(), default_payment_method_id: None, updated_by: None, - version: API_VERSION, + version: hyperswitch_domain_models::consts::API_VERSION, }) } @@ -268,7 +267,7 @@ impl CustomerCreateBridge for customers::CustomerRequest { default_billing_address: encrypted_customer_billing_address.map(Into::into), default_shipping_address: encrypted_customer_shipping_address.map(Into::into), // status: Some(customer_domain::SoftDeleteStatus::Active) - version: API_VERSION, + version: hyperswitch_domain_models::consts::API_VERSION, }) } diff --git a/crates/router/src/core/fraud_check.rs b/crates/router/src/core/fraud_check.rs index 64fadd0e33..114dff566c 100644 --- a/crates/router/src/core/fraud_check.rs +++ b/crates/router/src/core/fraud_check.rs @@ -1,10 +1,9 @@ use std::fmt::Debug; -use api_models::{admin::FrmConfigs, enums as api_enums}; +use api_models::{self, enums as api_enums}; use common_enums::CaptureMethod; -use common_utils::ext_traits::OptionExt; use error_stack::ResultExt; -use masking::{ExposeInterface, PeekInterface}; +use masking::PeekInterface; use router_env::{ logger, tracing::{self, instrument}, @@ -120,7 +119,25 @@ where Ok(router_data_res) } -pub async fn should_call_frm( +#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] +pub async fn should_call_frm( + _merchant_account: &domain::MerchantAccount, + _payment_data: &payments::PaymentData, + _state: &SessionState, + _key_store: domain::MerchantKeyStore, +) -> RouterResult<( + bool, + Option, + Option, + Option, +)> { + // Frm routing algorithm is not present in the merchant account + // it has to be fetched from the business profile + todo!() +} + +#[cfg(all(feature = "v1", not(feature = "merchant_account_v2")))] +pub async fn should_call_frm( merchant_account: &domain::MerchantAccount, payment_data: &payments::PaymentData, state: &SessionState, @@ -130,13 +147,13 @@ pub async fn should_call_frm( Option, Option, Option, -)> -where - F: Send + Clone, -{ +)> { + use common_utils::ext_traits::OptionExt; + use masking::ExposeInterface; + + let db = &*state.store; match merchant_account.frm_routing_algorithm.clone() { Some(frm_routing_algorithm_value) => { - let db = &*state.store; let frm_routing_algorithm_struct: FrmRoutingAlgorithm = frm_routing_algorithm_value .clone() .parse_value("FrmRoutingAlgorithm") @@ -191,7 +208,7 @@ where .ok(); match frm_configs_option { Some(frm_configs_value) => { - let frm_configs_struct: Vec = frm_configs_value + let frm_configs_struct: Vec = frm_configs_value .into_iter() .map(|config| { config .expose() diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index e5c8ef57b2..145f8d63f8 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -3292,6 +3292,10 @@ pub async fn call_surcharge_decision_management( billing_address: Option, response_payment_method_types: &mut [ResponsePaymentMethodsEnabled], ) -> errors::RouterResult { + #[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") + ))] let algorithm_ref: routing_types::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() @@ -3300,6 +3304,17 @@ pub async fn call_surcharge_decision_management( .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not decode the routing algorithm")? .unwrap_or_default(); + + #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] + let algorithm_ref: routing_types::RoutingAlgorithmRef = business_profile + .routing_algorithm + .clone() + .map(|val| val.parse_value("routing algorithm")) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Could not decode the routing algorithm")? + .unwrap_or_default(); + let (surcharge_results, merchant_sucharge_configs) = perform_surcharge_decision_management_for_payment_method_list( &state, @@ -3344,6 +3359,10 @@ pub async fn call_surcharge_decision_management_for_saved_card( payment_intent: storage::PaymentIntent, customer_payment_method_response: &mut api::CustomerPaymentMethodsListResponse, ) -> errors::RouterResult<()> { + #[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") + ))] let algorithm_ref: routing_types::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() @@ -3352,6 +3371,17 @@ pub async fn call_surcharge_decision_management_for_saved_card( .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not decode the routing algorithm")? .unwrap_or_default(); + + #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] + let algorithm_ref: routing_types::RoutingAlgorithmRef = business_profile + .routing_algorithm + .clone() + .map(|val| val.parse_value("routing algorithm")) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Could not decode the routing algorithm")? + .unwrap_or_default(); + let surcharge_results = perform_surcharge_decision_management_for_saved_cards( state, algorithm_ref, diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 00cc4839b4..6b8c19925e 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -181,7 +181,13 @@ where .to_not_found_response(errors::ApiErrorResponse::CustomerNotFound) .attach_printable("Failed while fetching/creating customer")?; - call_decision_manager(state, &merchant_account, &mut payment_data).await?; + call_decision_manager( + state, + &merchant_account, + &business_profile, + &mut payment_data, + ) + .await?; let connector = get_connector_choice( &operation, @@ -491,6 +497,7 @@ where call_surcharge_decision_management_for_session_flow( state, &merchant_account, + &business_profile, &mut payment_data, &connectors, ) @@ -621,11 +628,16 @@ where pub async fn call_decision_manager( state: &SessionState, merchant_account: &domain::MerchantAccount, + _business_profile: &domain::BusinessProfile, payment_data: &mut PaymentData, ) -> RouterResult<()> where O: Send + Clone, { + #[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") + ))] let algorithm_ref: api::routing::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() @@ -635,6 +647,16 @@ where .attach_printable("Could not decode the routing algorithm")? .unwrap_or_default(); + #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] + let algorithm_ref: api::routing::RoutingAlgorithmRef = _business_profile + .routing_algorithm + .clone() + .map(|val| val.parse_value("routing algorithm")) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Could not decode the routing algorithm")? + .unwrap_or_default(); + let output = perform_decision_management( state, algorithm_ref, @@ -737,7 +759,8 @@ pub fn get_connector_data( #[instrument(skip_all)] pub async fn call_surcharge_decision_management_for_session_flow( state: &SessionState, - merchant_account: &domain::MerchantAccount, + _merchant_account: &domain::MerchantAccount, + _business_profile: &domain::BusinessProfile, payment_data: &mut PaymentData, session_connector_data: &[api::SessionConnectorData], ) -> RouterResult> @@ -763,7 +786,12 @@ where .iter() .map(|session_connector_data| session_connector_data.payment_method_type) .collect(); - let algorithm_ref: api::routing::RoutingAlgorithmRef = merchant_account + + #[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") + ))] + let algorithm_ref: api::routing::RoutingAlgorithmRef = _merchant_account .routing_algorithm .clone() .map(|val| val.parse_value("routing algorithm")) @@ -771,6 +799,17 @@ where .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not decode the routing algorithm")? .unwrap_or_default(); + + #[cfg(all(feature = "v2", feature = "merchant_account_v2"))] + let algorithm_ref: api::routing::RoutingAlgorithmRef = _business_profile + .routing_algorithm + .clone() + .map(|val| val.parse_value("routing algorithm")) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Could not decode the routing algorithm")? + .unwrap_or_default(); + let surcharge_results = surcharge_decision_configs::perform_surcharge_decision_management_for_session_flow( state, diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 1fe84121d5..07ffcf443b 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1729,7 +1729,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R>( address_id: None, default_payment_method_id: None, updated_by: None, - version: common_enums::ApiVersion::V1, + version: hyperswitch_domain_models::consts::API_VERSION, }; metrics::CUSTOMER_CREATED.add(&metrics::CONTEXT, 1, &[]); db.insert_customer(new_customer, key_manager_state, key_store, storage_scheme) diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs index 4714992799..83afcefbb7 100644 --- a/crates/router/src/core/payouts/helpers.rs +++ b/crates/router/src/core/payouts/helpers.rs @@ -691,7 +691,7 @@ pub(super) async fn get_or_create_customer_details( address_id: None, default_payment_method_id: None, updated_by: None, - version: consts::API_VERSION, + version: hyperswitch_domain_models::consts::API_VERSION, }; Ok(Some( diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs index c73c3907d5..d9ab7d12bd 100644 --- a/crates/router/src/core/payouts/validator.rs +++ b/crates/router/src/core/payouts/validator.rs @@ -79,7 +79,6 @@ pub async fn validate_create_request( // Payout ID let db: &dyn StorageInterface = &*state.store; - let key_manager_state = &state.into(); let payout_id = core_utils::get_or_generate_uuid("payout_id", req.payout_id.as_ref())?; match validate_uniqueness_of_payout_id_against_merchant_id( db, @@ -147,7 +146,7 @@ pub async fn validate_create_request( not(feature = "merchant_account_v2") ))] let profile_id = core_utils::get_profile_id_from_business_details( - key_manager_state, + &state.into(), merchant_key_store, req.business_country, req.business_label.as_ref(), diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs index 8cfb710a8c..e388be764d 100644 --- a/crates/router/src/core/routing/helpers.rs +++ b/crates/router/src/core/routing/helpers.rs @@ -181,8 +181,7 @@ pub async fn update_merchant_active_algorithm_ref( _config_key: cache::CacheKind<'_>, _algorithm_id: routing_types::RoutingAlgorithmRef, ) -> RouterResult<()> { - // TODO: handle updating the active routing algorithm for v2 in merchant account - Ok(()) + todo!() } pub async fn update_business_profile_active_algorithm_ref( diff --git a/crates/router/src/core/surcharge_decision_config.rs b/crates/router/src/core/surcharge_decision_config.rs index 03e4f33737..461764ca42 100644 --- a/crates/router/src/core/surcharge_decision_config.rs +++ b/crates/router/src/core/surcharge_decision_config.rs @@ -1,31 +1,32 @@ -use api_models::{ - routing, - surcharge_decision_configs::{ - SurchargeDecisionConfigReq, SurchargeDecisionManagerRecord, - SurchargeDecisionManagerResponse, - }, +use api_models::surcharge_decision_configs::{ + SurchargeDecisionConfigReq, SurchargeDecisionManagerRecord, SurchargeDecisionManagerResponse, }; -use common_utils::ext_traits::{Encode, StringExt, ValueExt}; -use diesel_models::configs; +use common_utils::ext_traits::StringExt; use error_stack::ResultExt; -use euclid::frontend::ast; -use storage_impl::redis::cache; -use super::routing::helpers::update_merchant_active_algorithm_ref; use crate::{ core::errors::{self, RouterResponse}, routes::SessionState, services::api as service_api, types::domain, - utils::OptionExt, }; +#[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") +))] pub async fn upsert_surcharge_decision_config( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, request: SurchargeDecisionConfigReq, ) -> RouterResponse { + use common_utils::ext_traits::{Encode, OptionExt, ValueExt}; + use diesel_models::configs; + use storage_impl::redis::cache; + + use super::routing::helpers::update_merchant_active_algorithm_ref; + let db = state.store.as_ref(); let name = request.name; @@ -39,7 +40,7 @@ pub async fn upsert_surcharge_decision_config( let merchant_surcharge_configs = request.merchant_surcharge_configs; let timestamp = common_utils::date_time::now_unix_timestamp(); - let mut algo_id: routing::RoutingAlgorithmRef = merchant_account + let mut algo_id: api_models::routing::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() .map(|val| val.parse_value("routing algorithm")) @@ -53,7 +54,7 @@ pub async fn upsert_surcharge_decision_config( .get_payment_method_surcharge_routing_id(); let read_config_key = db.find_config_by_key(&key).await; - ast::lowering::lower_program(program.clone()) + euclid::frontend::ast::lowering::lower_program(program.clone()) .change_context(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid Request Data".to_string(), }) @@ -141,16 +142,35 @@ pub async fn upsert_surcharge_decision_config( } } +#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] +pub async fn upsert_surcharge_decision_config( + _state: SessionState, + _key_store: domain::MerchantKeyStore, + _merchant_account: domain::MerchantAccount, + _request: SurchargeDecisionConfigReq, +) -> RouterResponse { + todo!(); +} + +#[cfg(all( + any(feature = "v1", feature = "v2"), + not(feature = "merchant_account_v2") +))] pub async fn delete_surcharge_decision_config( state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, ) -> RouterResponse<()> { + use common_utils::ext_traits::ValueExt; + use storage_impl::redis::cache; + + use super::routing::helpers::update_merchant_active_algorithm_ref; + let db = state.store.as_ref(); let key = merchant_account .get_id() .get_payment_method_surcharge_routing_id(); - let mut algo_id: routing::RoutingAlgorithmRef = merchant_account + let mut algo_id: api_models::routing::RoutingAlgorithmRef = merchant_account .routing_algorithm .clone() .map(|value| value.parse_value("routing algorithm")) @@ -172,6 +192,15 @@ pub async fn delete_surcharge_decision_config( Ok(service_api::ApplicationResponse::StatusOk) } +#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] +pub async fn delete_surcharge_decision_config( + _state: SessionState, + _key_store: domain::MerchantKeyStore, + _merchant_account: domain::MerchantAccount, +) -> RouterResponse<()> { + todo!() +} + pub async fn retrieve_surcharge_decision_config( state: SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/types/domain.rs b/crates/router/src/types/domain.rs index 011da36be3..2d2897aa22 100644 --- a/crates/router/src/types/domain.rs +++ b/crates/router/src/types/domain.rs @@ -12,8 +12,14 @@ mod business_profile { }; } +mod customers { + pub use hyperswitch_domain_models::customer::*; +} + +pub use customers::*; +pub use merchant_account::*; + mod address; -mod customer; mod event; mod merchant_connector_account; mod merchant_key_store { @@ -27,9 +33,7 @@ pub mod user_key_store; pub use address::*; pub use business_profile::*; -pub use customer::*; pub use event::*; -pub use merchant_account::*; pub use merchant_connector_account::*; pub use merchant_key_store::*; pub use payments::*; diff --git a/crates/router/src/types/domain/customer.rs b/crates/router/src/types/domain/customer.rs deleted file mode 100644 index 6f42cae0b4..0000000000 --- a/crates/router/src/types/domain/customer.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hyperswitch_domain_models::customer::*; diff --git a/crates/router/src/types/domain/merchant_account.rs b/crates/router/src/types/domain/merchant_account.rs deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/migrations/2024-08-08-075600_add_api_version_to_merchant_account/down.sql b/migrations/2024-08-08-075600_add_api_version_to_merchant_account/down.sql new file mode 100644 index 0000000000..c123c73d90 --- /dev/null +++ b/migrations/2024-08-08-075600_add_api_version_to_merchant_account/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE merchant_account DROP COLUMN version; diff --git a/migrations/2024-08-08-075600_add_api_version_to_merchant_account/up.sql b/migrations/2024-08-08-075600_add_api_version_to_merchant_account/up.sql new file mode 100644 index 0000000000..68dd1d1d80 --- /dev/null +++ b/migrations/2024-08-08-075600_add_api_version_to_merchant_account/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE merchant_account +ADD COLUMN IF NOT EXISTS version "ApiVersion" NOT NULL DEFAULT 'v1'; diff --git a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql b/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql index 60e6c17b08..8880dda3a5 100644 --- a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql +++ b/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql @@ -44,3 +44,12 @@ ADD COLUMN is_recon_enabled BOOLEAN NOT NULL DEFAULT FALSE; ALTER TABLE merchant_account ADD COLUMN webhook_details JSONB NULL; + +ALTER TABLE merchant_account +ADD COLUMN routing_algorithm JSON; + +ALTER TABLE merchant_account +ADD COLUMN frm_routing_algorithm JSONB; + +ALTER TABLE merchant_account +ADD COLUMN payout_routing_algorithm JSONB; diff --git a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql b/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql index e9a349e613..0129f1b1cf 100644 --- a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql +++ b/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql @@ -26,3 +26,9 @@ ALTER TABLE merchant_account DROP pm_collect_link_config; ALTER TABLE merchant_account DROP is_recon_enabled; ALTER TABLE merchant_account DROP webhook_details; + +ALTER TABLE merchant_account DROP routing_algorithm; + +ALTER TABLE merchant_account DROP frm_routing_algorithm; + +ALTER TABLE merchant_account DROP payout_routing_algorithm;