diff --git a/crates/common_types/Cargo.toml b/crates/common_types/Cargo.toml index 072d20b0ad6b..b21d7211a344 100644 --- a/crates/common_types/Cargo.toml +++ b/crates/common_types/Cargo.toml @@ -15,6 +15,5 @@ utoipa = { version = "4.2.0", features = ["preserve_order", "preserve_path_order common_enums = { version = "0.1.0", path = "../common_enums" } common_utils = { version = "0.1.0", path = "../common_utils"} - [lints] workspace = true diff --git a/crates/common_types/src/payments.rs b/crates/common_types/src/payments.rs index ce4fb4c2dd9b..e97dc48c014f 100644 --- a/crates/common_types/src/payments.rs +++ b/crates/common_types/src/payments.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use common_enums::enums; -use common_utils::{impl_to_sql_from_sql_json, types::MinorUnit}; +use common_utils::{errors, impl_to_sql_from_sql_json, types::MinorUnit}; use diesel::{sql_types::Jsonb, AsExpression, FromSqlRow}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; @@ -60,4 +60,15 @@ impl AuthenticationConnectorAccountMap { { &self.0 } + /// fn to get click to pay connector_account_id + pub fn get_click_to_pay_connector_account_id( + &self, + ) -> Result { + self.inner() + .get(&enums::AuthenticationProduct::ClickToPay) + .ok_or(errors::ValidationError::MissingRequiredField { + field_name: "authentication_product_id".to_string(), + }) + .cloned() + } } diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index aac567ecdd63..c358c26535e2 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -376,19 +376,9 @@ where should_continue_capture, ); - let merchants_eligible_for_authentication_service = state - .store - .as_ref() - .find_config_by_key(crate::consts::AUTHENTICATION_SERVICE_ELIGIBLE_CONFIG) - .await - .to_not_found_response(errors::ApiErrorResponse::ConfigNotFound)?; - let auth_eligible_array: Vec = - serde_json::from_str(&merchants_eligible_for_authentication_service.config) - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("unable to parse authentication service config")?; - let merchant_id = merchant_account.get_id(); - - if auth_eligible_array.contains(&merchant_id.get_string_repr().to_owned()) { + if helpers::is_merchant_eligible_authenthention_service(merchant_account.get_id(), state) + .await? + { let authentication_product_ids = business_profile .authentication_product_ids .clone() @@ -3430,17 +3420,17 @@ pub async fn get_session_token_for_click_to_pay( payment_intent: &hyperswitch_domain_models::payments::PaymentIntent, ) -> RouterResult { let click_to_pay_mca_id = authentication_product_ids - .inner() - .get(&common_enums::AuthenticationProduct::ClickToPay) - .ok_or(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Error while getting click_to_pay mca_id from business profile")?; + .get_click_to_pay_connector_account_id() + .change_context(errors::ApiErrorResponse::MissingRequiredField { + field_name: "authentication_product_ids", + })?; let key_manager_state = &(state).into(); let merchant_connector_account = state .store .find_by_merchant_connector_account_merchant_id_merchant_connector_id( key_manager_state, merchant_id, - click_to_pay_mca_id, + &click_to_pay_mca_id, key_store, ) .await diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 78cfdda33b49..5eaabd7d0d4b 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -9,7 +9,8 @@ use common_enums::ConnectorType; use common_utils::{ crypto::Encryptable, ext_traits::{AsyncExt, ByteSliceExt, Encode, ValueExt}, - fp_utils, generate_id, id_type, + fp_utils, generate_id, + id_type::{self}, new_type::{MaskedIban, MaskedSortCode}, pii, type_name, types::{ @@ -6162,3 +6163,22 @@ pub fn validate_platform_fees_for_marketplace( } Ok(()) } + +pub async fn is_merchant_eligible_authenthention_service( + merchant_id: &id_type::MerchantId, + state: &SessionState, +) -> RouterResult { + let merchants_eligible_for_authentication_service = state + .store + .as_ref() + .find_config_by_key(consts::AUTHENTICATION_SERVICE_ELIGIBLE_CONFIG) + .await + .to_not_found_response(errors::ApiErrorResponse::ConfigNotFound)?; + + let auth_eligible_array: Vec = + serde_json::from_str(&merchants_eligible_for_authentication_service.config) + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("unable to parse authentication service config")?; + + Ok(auth_eligible_array.contains(&merchant_id.get_string_repr().to_owned())) +} diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 1c3fb77c38ee..82bd398df231 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -1052,12 +1052,10 @@ impl Domain> for && business_profile.is_click_to_pay_enabled { let click_to_pay_mca_id = authentication_product_ids - .inner() - .get(&common_enums::enums::AuthenticationProduct::ClickToPay) - .ok_or(errors::ApiErrorResponse::InternalServerError) - .attach_printable( - "Error while getting click_to_pay mca_id from business profile", - )?; + .get_click_to_pay_connector_account_id() + .change_context(errors::ApiErrorResponse::MissingRequiredField { + field_name: "authentication_product_ids", + })?; let key_manager_state = &(state).into(); let merchant_id = &business_profile.merchant_id; @@ -1067,7 +1065,7 @@ impl Domain> for .find_by_merchant_connector_account_merchant_id_merchant_connector_id( key_manager_state, merchant_id, - click_to_pay_mca_id, + &click_to_pay_mca_id, key_store, ) .await