Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(router): refactor ctp flow to fetch mca_id and get the connector creds instead of connector_name #6859

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5f694cf
refactor(router): fixed mca logic fetch
sahkal Dec 17, 2024
5d0d9d1
dummy commit
sahkal Dec 18, 2024
6e4bc87
chore: run formatter
hyperswitch-bot[bot] Dec 18, 2024
c7a0b06
Merge branch 'main' of https://github.com/juspay/hyperswitch into 786…
sahkal Dec 18, 2024
3c2e034
addressed pr comments
sahkal Dec 18, 2024
60a60e1
fixed path url for uas
sahkal Dec 18, 2024
a97f01e
resolved conflicts
sahkal Dec 20, 2024
55029ed
addressed pr comments
sahkal Dec 20, 2024
0e7922b
Merge branch 'main' into 7862-refactor-refactor-ctp-flow-to-fetch-mca…
sahkal Dec 20, 2024
98b5af4
moved external 3ds under else condition
sahkal Dec 20, 2024
edae612
Merge branch '7862-refactor-refactor-ctp-flow-to-fetch-mca_id-and-get…
sahkal Dec 20, 2024
be0ffa9
addressed pr comments
sahkal Dec 20, 2024
5b4178b
resolved pr comments
sahkal Dec 23, 2024
2e791d5
addressed pr comments
sahkal Dec 23, 2024
389ae52
Merge branch 'main' into 7862-refactor-refactor-ctp-flow-to-fetch-mca…
sahkal Dec 23, 2024
5b1cd69
resolved merge conflicts
sahkal Jan 6, 2025
249e82b
Merge branch 'main' into 7862-refactor-refactor-ctp-flow-to-fetch-mca…
sahkal Jan 6, 2025
a0ea8e7
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jan 6, 2025
c6bc417
resolved merge conflicts
sahkal Jan 13, 2025
4f82382
Merge branch 'main' into 7862-refactor-refactor-ctp-flow-to-fetch-mca…
sahkal Jan 15, 2025
392c044
fixed open-api specs
sahkal Jan 15, 2025
5128445
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jan 15, 2025
ecbee61
addressed pr commnets added example for apen_api specs
sahkal Jan 15, 2025
3cfac70
removed if condition for logging db error
sahkal Jan 15, 2025
f448f68
Merge branch 'main' into 7862-refactor-refactor-ctp-flow-to-fetch-mca…
sai-harsha-vardhan Jan 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,8 @@ pub struct ProfileCreate {

/// Product authentication ids
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved
pub authentication_product_ids: Option<HashMap<String, id_type::MerchantConnectorAccountId>>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[nutype::nutype(
Expand Down Expand Up @@ -1980,7 +1981,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<HashMap<String, id_type::MerchantConnectorAccountId>>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2116,7 +2118,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<serde_json::Value>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2239,7 +2242,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<serde_json::Value>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2369,7 +2373,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<HashMap<String, id_type::MerchantConnectorAccountId>>,
pub authentication_product_ids:
Option<common_types::payments::AuthenticationConnectorAccountMap>,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -2480,7 +2485,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<HashMap<String, id_type::MerchantConnectorAccountId>>,
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 @@ -3574,3 +3574,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,
}
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 @@ -62,7 +62,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 @@ -72,6 +71,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 @@ -130,6 +134,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 @@ -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";
36 changes: 4 additions & 32 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3625,13 +3625,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 @@ -3702,7 +3695,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 @@ -3754,13 +3747,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 @@ -3818,7 +3804,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 @@ -4026,13 +4012,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 @@ -4076,7 +4055,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 @@ -4139,13 +4118,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 @@ -4181,7 +4153,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
Loading