Skip to content

Commit

Permalink
refactor(router): refactor ctp flow to fetch mca_id and get the conne…
Browse files Browse the repository at this point in the history
…ctor creds instead of connector_name (#7078)

Co-authored-by: Sahkal Poddar <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 20, 2025
1 parent bcbc83e commit 9adb425
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 152 deletions.
30 changes: 18 additions & 12 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,8 +1864,9 @@ pub struct ProfileCreate {
pub is_click_to_pay_enabled: bool,

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,
#[schema(value_type = Option<Object>, example = r#"{ "click_to_pay": "mca_ushduqwhdohwd", "netcetera": "mca_kwqhudqwd" }"#)]
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[nutype::nutype(
Expand Down Expand Up @@ -1981,8 +1982,9 @@ pub struct ProfileCreate {
pub is_click_to_pay_enabled: bool,

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,
#[schema(value_type = Option<Object>, example = r#"{ "click_to_pay": "mca_ushduqwhdohwd", "netcetera": "mca_kwqhudqwd" }"#)]
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2117,8 +2119,9 @@ pub struct ProfileResponse {
pub is_click_to_pay_enabled: bool,

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

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2240,8 +2243,9 @@ pub struct ProfileResponse {
pub is_click_to_pay_enabled: bool,

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

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2370,8 +2374,9 @@ pub struct ProfileUpdate {
pub is_click_to_pay_enabled: Option<bool>,

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,
#[schema(value_type = Option<Object>, example = r#"{ "click_to_pay": "mca_ushduqwhdohwd", "netcetera": "mca_kwqhudqwd" }"#)]
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2481,8 +2486,9 @@ pub struct ProfileUpdate {
pub is_click_to_pay_enabled: Option<bool>,

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,
#[schema(value_type = Option<Object>, example = r#"{ "click_to_pay": "mca_ushduqwhdohwd", "netcetera": "mca_kwqhudqwd" }"#)]
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

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

/// Authentication Products
#[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,
}

/// Connector Access Method
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
Expand Down
29 changes: 28 additions & 1 deletion crates/common_types/src/payments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Payment related types
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 @@ -38,3 +40,28 @@ pub struct StripeSplitPaymentRequest {
pub transfer_account_id: String,
}
impl_to_sql_from_sql_json!(StripeSplitPaymentRequest);

#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
#[diesel(sql_type = Jsonb)]
#[serde(deny_unknown_fields)]
/// Hashmap to store mca_id's with product names
pub struct AuthenticationConnectorAccountMap(
HashMap<enums::AuthenticationProduct, common_utils::id_type::MerchantConnectorAccountId>,
);
impl_to_sql_from_sql_json!(AuthenticationConnectorAccountMap);

impl AuthenticationConnectorAccountMap {
/// 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.0
.get(&enums::AuthenticationProduct::ClickToPay)
.ok_or(errors::ValidationError::MissingRequiredField {
field_name: "authentication_product_id.click_to_pay".to_string(),
})
.cloned()
}
}
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
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<serde_json::Value>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl MerchantConnectorAccount {
pub fn get_id(&self) -> id_type::MerchantConnectorAccountId {
self.merchant_connector_id.clone()
}

pub fn get_connector_account_details(
&self,
) -> error_stack::Result<router_data::ConnectorAuthType, common_utils::errors::ParsingError>
Expand All @@ -66,6 +65,11 @@ impl MerchantConnectorAccount {
.clone()
.parse_value("ConnectorAuthType")
}

pub fn get_connector_wallets_details(&self) -> Option<Secret<Value>> {
self.connector_wallets_details.as_deref().cloned()
}

pub fn get_connector_test_mode(&self) -> Option<bool> {
self.test_mode
}
Expand Down Expand Up @@ -124,6 +128,11 @@ impl MerchantConnectorAccount {
.clone()
.parse_value("ConnectorAuthType")
}

pub fn get_connector_wallets_details(&self) -> Option<Secret<Value>> {
self.connector_wallets_details.as_deref().cloned()
}

pub fn get_connector_test_mode(&self) -> Option<bool> {
todo!()
}
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 @@ -211,5 +211,9 @@ 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";

/// Refund flow identifier used for performing GSM operations
pub const REFUND_FLOW_STR: &str = "refund_flow";
36 changes: 4 additions & 32 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3626,13 +3626,6 @@ impl ProfileCreateBridge for api::ProfileCreate {
})
.transpose()?;

let authentication_product_ids = self
.authentication_product_ids
.map(serde_json::to_value)
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to parse product authentication id's to value")?;

Ok(domain::Profile::from(domain::ProfileSetter {
profile_id,
merchant_id: merchant_account.get_id().clone(),
Expand Down Expand Up @@ -3703,7 +3696,7 @@ impl ProfileCreateBridge for api::ProfileCreate {
is_auto_retries_enabled: self.is_auto_retries_enabled.unwrap_or_default(),
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids,
authentication_product_ids: self.authentication_product_ids,
}))
}

Expand Down Expand Up @@ -3755,13 +3748,6 @@ impl ProfileCreateBridge for api::ProfileCreate {
})
.transpose()?;

let authentication_product_ids = self
.authentication_product_ids
.map(serde_json::to_value)
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to parse product authentication id's to value")?;

Ok(domain::Profile::from(domain::ProfileSetter {
id: profile_id,
merchant_id: merchant_id.clone(),
Expand Down Expand Up @@ -3819,7 +3805,7 @@ impl ProfileCreateBridge for api::ProfileCreate {
is_tax_connector_enabled: self.is_tax_connector_enabled,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids,
authentication_product_ids: self.authentication_product_ids,
}))
}
}
Expand Down Expand Up @@ -4027,13 +4013,6 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
})
.transpose()?;

let authentication_product_ids = self
.authentication_product_ids
.map(serde_json::to_value)
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to parse product authentication id's to value")?;

Ok(domain::ProfileUpdate::Update(Box::new(
domain::ProfileGeneralUpdate {
profile_name: self.profile_name,
Expand Down Expand Up @@ -4077,7 +4056,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
is_auto_retries_enabled: self.is_auto_retries_enabled,
max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from),
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids,
authentication_product_ids: self.authentication_product_ids,
},
)))
}
Expand Down Expand Up @@ -4140,13 +4119,6 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
})
.transpose()?;

let authentication_product_ids = self
.authentication_product_ids
.map(serde_json::to_value)
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("failed to parse product authentication id's to value")?;

Ok(domain::ProfileUpdate::Update(Box::new(
domain::ProfileGeneralUpdate {
profile_name: self.profile_name,
Expand Down Expand Up @@ -4182,7 +4154,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate {
.always_collect_shipping_details_from_wallet_connector,
is_network_tokenization_enabled: self.is_network_tokenization_enabled,
is_click_to_pay_enabled: self.is_click_to_pay_enabled,
authentication_product_ids,
authentication_product_ids: self.authentication_product_ids,
},
)))
}
Expand Down
Loading

0 comments on commit 9adb425

Please sign in to comment.