Skip to content

Commit

Permalink
addressed pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sahkal committed Dec 20, 2024
1 parent edae612 commit be0ffa9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
1 change: 0 additions & 1 deletion crates/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion crates/common_types/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<common_utils::id_type::MerchantConnectorAccountId, errors::ValidationError> {
self.inner()
.get(&enums::AuthenticationProduct::ClickToPay)
.ok_or(errors::ValidationError::MissingRequiredField {
field_name: "authentication_product_id".to_string(),
})
.cloned()
}
}
26 changes: 8 additions & 18 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> =
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()
Expand Down Expand Up @@ -3430,17 +3420,17 @@ pub async fn get_session_token_for_click_to_pay(
payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,
) -> RouterResult<api_models::payments::SessionToken> {
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
Expand Down
22 changes: 21 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<bool> {
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<String> =
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()))
}
12 changes: 5 additions & 7 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,12 +1052,10 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> 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;
Expand All @@ -1067,7 +1065,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> 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
Expand Down

0 comments on commit be0ffa9

Please sign in to comment.