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 a97f01e commit 55029ed
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 54 deletions.
18 changes: 12 additions & 6 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,8 @@ pub struct ProfileCreate {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[nutype::nutype(
Expand Down Expand Up @@ -2089,7 +2090,8 @@ pub struct ProfileCreate {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2225,7 +2227,8 @@ pub struct ProfileResponse {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2348,7 +2351,8 @@ pub struct ProfileResponse {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2478,7 +2482,8 @@ pub struct ProfileUpdate {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2589,7 +2594,8 @@ pub struct ProfileUpdate {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down
19 changes: 19 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3507,3 +3507,22 @@ pub enum StripeChargeType {
Direct,
Destination,
}

#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthenticationProduct {
ClickToPay,
}
1 change: 1 addition & 0 deletions crates/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ 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: 8 additions & 5 deletions crates/common_types/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ impl_to_sql_from_sql_json!(StripeSplitPaymentRequest);
#[diesel(sql_type = Jsonb)]
#[serde(deny_unknown_fields)]
/// Hashmap to store mca_id's with product names
pub struct MerchantConnectorAccountMap(
HashMap<String, common_utils::id_type::MerchantConnectorAccountId>,
pub struct AuthenticationConnectorAccountMap(
HashMap<enums::AuthenticationProduct, common_utils::id_type::MerchantConnectorAccountId>,
);
impl_to_sql_from_sql_json!(MerchantConnectorAccountMap);
impl_to_sql_from_sql_json!(AuthenticationConnectorAccountMap);

impl MerchantConnectorAccountMap {
impl AuthenticationConnectorAccountMap {
/// get inner hashmap
pub fn inner(&self) -> &HashMap<String, common_utils::id_type::MerchantConnectorAccountId> {
pub fn inner(
&self,
) -> &HashMap<enums::AuthenticationProduct, common_utils::id_type::MerchantConnectorAccountId>
{
&self.0
}
}
18 changes: 12 additions & 6 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub struct Profile {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -103,7 +104,8 @@ pub struct ProfileNew {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -145,7 +147,8 @@ pub struct ProfileUpdateInternal {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: Option<bool>,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -305,7 +308,8 @@ pub struct Profile {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

impl Profile {
Expand Down Expand Up @@ -365,7 +369,8 @@ pub struct ProfileNew {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -409,7 +414,8 @@ pub struct ProfileUpdateInternal {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: Option<bool>,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down
18 changes: 12 additions & 6 deletions crates/hyperswitch_domain_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub struct Profile {
pub is_auto_retries_enabled: bool,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -101,7 +102,8 @@ pub struct ProfileSetter {
pub is_auto_retries_enabled: bool,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -201,7 +203,8 @@ pub struct ProfileGeneralUpdate {
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
pub is_click_to_pay_enabled: Option<bool>,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -729,7 +732,8 @@ pub struct Profile {
pub version: common_enums::ApiVersion,
pub is_network_tokenization_enabled: bool,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -771,7 +775,8 @@ pub struct ProfileSetter {
pub is_tax_connector_enabled: bool,
pub is_network_tokenization_enabled: bool,
pub is_click_to_pay_enabled: bool,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -872,7 +877,8 @@ pub struct ProfileGeneralUpdate {
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
pub is_network_tokenization_enabled: Option<bool>,
pub is_click_to_pay_enabled: Option<bool>,
pub authentication_product_ids: Option<common_types::payments::MerchantConnectorAccountMap>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down
18 changes: 7 additions & 11 deletions crates/hyperswitch_domain_models/src/merchant_connector_account.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(feature = "v2")]
use api_models::admin;
#[cfg(feature = "v2")]
use common_utils::ext_traits::ValueExt;
use common_utils::{
crypto::Encryptable,
date_time,
encryption::Encryption,
errors::{CustomResult, ValidationError},
ext_traits::ValueExt,
id_type, pii, type_name,
types::keymanager::{Identifier, KeyManagerState, ToEncryptable},
};
Expand All @@ -21,9 +20,10 @@ use serde_json::Value;
use super::behaviour;
#[cfg(feature = "v2")]
use crate::errors::api_error_response::ApiErrorResponse;
#[cfg(feature = "v2")]
use crate::router_data;
use crate::type_encryption::{crypto_operation, CryptoOperation};
use crate::{
router_data,
type_encryption::{crypto_operation, CryptoOperation},
};

#[cfg(feature = "v1")]
#[derive(Clone, Debug, router_derive::ToEncryption)]
Expand Down Expand Up @@ -64,12 +64,8 @@ impl MerchantConnectorAccount {
}
pub fn get_connector_account_details(
&self,
) -> error_stack::Result<
crate::router_data::ConnectorAuthType,
common_utils::errors::ParsingError,
> {
use common_utils::ext_traits::ValueExt;

) -> error_stack::Result<router_data::ConnectorAuthType, common_utils::errors::ParsingError>
{
self.connector_account_details
.get_inner()
.clone()
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,7 @@ pub const DYNAMIC_ROUTING_MAX_VOLUME: u8 = 100;

/// Click To Pay
pub const CLICK_TO_PAY: &str = "click_to_pay";

/// Merchant eligible for authentication service config
pub const AUTHENTICATION_SERVICE_ELIGIBLE_CONFIG: &str =
"merchants_eligible_for_authentication_service";
49 changes: 33 additions & 16 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod customers;
pub mod flows;
pub mod helpers;
pub mod operations;

#[cfg(feature = "retry")]
pub mod retry;
pub mod routing;
Expand All @@ -30,14 +31,14 @@ pub use common_enums::enums::CallConnectorAction;
use common_utils::{
ext_traits::{AsyncExt, StringExt},
id_type, pii,
types::{MinorUnit, Surcharge},
types::{AmountConvertor, MinorUnit, Surcharge},
};
use diesel_models::{ephemeral_key, fraud_check::FraudCheck};
use error_stack::{report, ResultExt};
use events::EventInfo;
use futures::future::join_all;
use helpers::{decrypt_paze_token, ApplePayData};
use hyperswitch_domain_models::payments::payment_intent::CustomerData;
use hyperswitch_domain_models::payments::{payment_intent::CustomerData, ClickToPayMetaData};
#[cfg(feature = "v2")]
use hyperswitch_domain_models::payments::{
PaymentConfirmData, PaymentIntentData, PaymentStatusData,
Expand Down Expand Up @@ -388,7 +389,26 @@ where
)
.await?;

if let Some(ref authentication_product_ids) = business_profile.authentication_product_ids {
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()) {
let authentication_product_ids = business_profile
.authentication_product_ids
.clone()
.ok_or(errors::ApiErrorResponse::PreconditionFailed {
message: "authentication_product_ids is not configured in business profile"
.to_string(),
})?;
operation
.to_domain()?
.call_unified_authentication_service_if_eligible(
Expand All @@ -398,12 +418,14 @@ where
&connector_details,
&business_profile,
&key_store,
authentication_product_ids,
&authentication_product_ids,
)
.await?
.await?;
} else {
tracing::info!("skipping unified authentication service call since no product authentication id's are present in business profile")
}
logger::info!(
"skipping authentication service call since the merchant is not eligible."
)
};

operation
.to_domain()?
Expand Down Expand Up @@ -3404,17 +3426,12 @@ pub async fn get_session_token_for_click_to_pay(
state: &SessionState,
merchant_id: &id_type::MerchantId,
key_store: &domain::MerchantKeyStore,
authentication_product_ids: common_types::payments::MerchantConnectorAccountMap,
authentication_product_ids: common_types::payments::AuthenticationConnectorAccountMap,
payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,
) -> RouterResult<api_models::payments::SessionToken> {
use common_utils::types::AmountConvertor;
use hyperswitch_domain_models::payments::{payment_intent::CustomerData, ClickToPayMetaData};

use crate::consts::CLICK_TO_PAY;

let click_to_pay_mca_id = authentication_product_ids
.inner()
.get(CLICK_TO_PAY)
.get(&common_enums::AuthenticationProduct::ClickToPay)
.ok_or(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error while getting click_to_pay mca_id from business profile")?;
let key_manager_state = &(state).into();
Expand Down Expand Up @@ -3442,8 +3459,8 @@ pub async fn get_session_token_for_click_to_pay(
let required_amount_type = common_utils::types::StringMajorUnitForConnector;
let transaction_amount = required_amount_type
.convert(payment_intent.amount, transaction_currency)
.change_context(errors::ApiErrorResponse::PreconditionFailed {
message: "Failed to convert amount to string major unit for clickToPay".to_string(),
.change_context(errors::ApiErrorResponse::AmountConversionFailed {
amount_type: "string major unit",
})?;

let customer_details_value = payment_intent
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/payments/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
_connector_call_type: &ConnectorCallType,
_merchant_account: &domain::Profile,
_key_store: &domain::MerchantKeyStore,
_authentication_product_ids: &common_types::payments::MerchantConnectorAccountMap,
_authentication_product_ids: &common_types::payments::AuthenticationConnectorAccountMap,
) -> CustomResult<(), errors::ApiErrorResponse> {
Ok(())
}
Expand Down
Loading

0 comments on commit 55029ed

Please sign in to comment.