Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(router): domain and diesel model changes for merchant_connector_account create v2 flow (#5462)

Sai Harsha Vardhan85209d12ae34
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index e7c1058b5b..e5da875455 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -951,7 +951,7 @@ pub struct MerchantConnectorResponse {
/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
- pub connector_id: String,
+ pub id: String,
/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64)]
@@ -1032,7 +1032,7 @@ impl MerchantConnectorResponse {
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
MerchantConnectorInfo {
connector_label: connector_label.to_string(),
- merchant_connector_id: self.connector_id.clone(),
+ merchant_connector_id: self.id.clone(),
}
}
}
@@ -1162,6 +1162,10 @@ impl MerchantConnectorResponse {
}
}
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MerchantConnectorListResponse {
@@ -1257,6 +1261,10 @@ pub struct MerchantConnectorListResponse {
pub additional_merchant_data: Option<AdditionalMerchantData>,
}
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
impl MerchantConnectorListResponse {
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
MerchantConnectorInfo {
@@ -1266,6 +1274,96 @@ impl MerchantConnectorListResponse {
}
}
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
+#[serde(deny_unknown_fields)]
+pub struct MerchantConnectorListResponse {
+ /// Type of the Connector for the financial use case. Could range from Payments to Accounting to Banking.
+ #[schema(value_type = ConnectorType, example = "payment_processor")]
+ pub connector_type: api_enums::ConnectorType,
+ /// Name of the Connector
+ #[schema(value_type = Connector, example = "stripe")]
+ pub connector_name: String,
+
+ /// A unique label to identify the connector account created under a business profile
+ #[schema(example = "stripe_US_travel")]
+ pub connector_label: Option<String>,
+
+ /// Unique ID of the merchant connector account
+ #[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
+ pub id: String,
+
+ /// Identifier for the business profile, if not provided default will be chosen from merchant account
+ #[schema(max_length = 64)]
+ pub profile_id: Option<String>,
+
+ /// An object containing the details about the payment methods that need to be enabled under this merchant connector account
+ #[schema(example = json!([
+ {
+ "payment_method": "wallet",
+ "payment_method_types": [
+ "upi_collect",
+ "upi_intent"
+ ],
+ "payment_method_issuers": [
+ "labore magna ipsum",
+ "aute"
+ ],
+ "payment_schemes": [
+ "Discover",
+ "Discover"
+ ],
+ "accepted_currencies": {
+ "type": "enable_only",
+ "list": ["USD", "EUR"]
+ },
+ "accepted_countries": {
+ "type": "disable_only",
+ "list": ["FR", "DE","IN"]
+ },
+ "minimum_amount": 1,
+ "maximum_amount": 68607706,
+ "recurring_enabled": true,
+ "installment_payment_enabled": true
+ }
+ ]))]
+ pub payment_methods_enabled: Option<Vec<PaymentMethodsEnabled>>,
+
+ /// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
+ #[schema(value_type = Option<Object>,max_length = 255,example = json!({ "city": "NY", "unit": "245" }))]
+ pub metadata: Option<pii::SecretSerdeValue>,
+
+ /// A boolean value to indicate if the connector is disabled. By default, its value is false.
+ #[schema(default = false, example = false)]
+ pub disabled: Option<bool>,
+
+ /// Contains the frm configs for the merchant connector
+ #[schema(example = json!(consts::FRM_CONFIGS_EG))]
+ pub frm_configs: Option<Vec<FrmConfigs>>,
+
+ /// identifier for the verified domains of a particular connector account
+ pub applepay_verified_domains: Option<Vec<String>>,
+
+ #[schema(value_type = Option<Object>)]
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+
+ #[schema(value_type = ConnectorStatus, example = "inactive")]
+ pub status: api_enums::ConnectorStatus,
+
+ #[schema(value_type = Option<AdditionalMerchantData>)]
+ pub additional_merchant_data: Option<AdditionalMerchantData>,
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+impl MerchantConnectorListResponse {
+ pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
+ MerchantConnectorInfo {
+ connector_label: connector_label.to_string(),
+ merchant_connector_id: self.id.clone(),
+ }
+ }
+}
+
/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
diff --git a/crates/diesel_models/Cargo.toml b/crates/diesel_models/Cargo.toml
index c596cb2e2e..d021ccfff3 100644
--- a/crates/diesel_models/Cargo.toml
+++ b/crates/diesel_models/Cargo.toml
@@ -14,6 +14,7 @@ v1 =[]
v2 = []
customer_v2 = []
merchant_account_v2 = []
+merchant_connector_account_v2 = []
payment_v2 = []
[dependencies]
diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs
index 2d12dc9f25..a057f349ea 100644
--- a/crates/diesel_models/src/merchant_connector_account.rs
+++ b/crates/diesel_models/src/merchant_connector_account.rs
@@ -2,10 +2,20 @@ use std::fmt::Debug;
use common_utils::{encryption::Encryption, id_type, pii};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
-use masking::Secret;
-use crate::{enums as storage_enums, schema::merchant_connector_account};
+use crate::enums as storage_enums;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+use crate::schema::merchant_connector_account;
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+use crate::schema_v2::merchant_connector_account;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
#[derive(
Clone,
Debug,
@@ -24,20 +34,20 @@ pub struct MerchantConnectorAccount {
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: String,
- #[diesel(deserialize_as = super::OptionalDieselArray<serde_json::Value>)]
- pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub connector_type: storage_enums::ConnectorType,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_label: Option<String>,
pub business_country: Option<storage_enums::CountryAlpha2>,
pub business_label: Option<String>,
pub business_sub_label: Option<String>,
- pub frm_configs: Option<Secret<serde_json::Value>>,
+ pub frm_configs: Option<pii::SecretSerdeValue>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
- pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
+ pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
pub profile_id: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
@@ -47,6 +57,64 @@ pub struct MerchantConnectorAccount {
pub connector_wallets_details: Option<Encryption>,
}
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+impl MerchantConnectorAccount {
+ pub fn get_id(&self) -> String {
+ self.merchant_connector_id.clone()
+ }
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[derive(
+ Clone,
+ Debug,
+ serde::Serialize,
+ serde::Deserialize,
+ Identifiable,
+ Queryable,
+ Selectable,
+ router_derive::DebugAsDisplay,
+)]
+#[diesel(table_name = merchant_connector_account, check_for_backend(diesel::pg::Pg))]
+pub struct MerchantConnectorAccount {
+ pub merchant_id: id_type::MerchantId,
+ pub connector_name: String,
+ pub connector_account_details: Encryption,
+ pub disabled: Option<bool>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_type: storage_enums::ConnectorType,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub connector_label: Option<String>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
+ pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
+ pub profile_id: Option<String>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<String>)]
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: storage_enums::ConnectorStatus,
+ pub additional_merchant_data: Option<Encryption>,
+ pub connector_wallets_details: Option<Encryption>,
+ pub id: String,
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+impl MerchantConnectorAccount {
+ pub fn get_id(&self) -> String {
+ self.id.clone()
+ }
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccountNew {
@@ -57,18 +125,44 @@ pub struct MerchantConnectorAccountNew {
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: String,
- pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_label: Option<String>,
pub business_country: Option<storage_enums::CountryAlpha2>,
pub business_label: Option<String>,
pub business_sub_label: Option<String>,
- pub frm_configs: Option<Secret<serde_json::Value>>,
+ pub frm_configs: Option<pii::SecretSerdeValue>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
+ pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
+ pub profile_id: Option<String>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<String>)]
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: storage_enums::ConnectorStatus,
+ pub additional_merchant_data: Option<Encryption>,
+ pub connector_wallets_details: Option<Encryption>,
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
+#[diesel(table_name = merchant_connector_account)]
+pub struct MerchantConnectorAccountNew {
+ pub merchant_id: Option<id_type::MerchantId>,
+ pub connector_type: Option<storage_enums::ConnectorType>,
+ pub connector_name: Option<String>,
+ pub connector_account_details: Option<Encryption>,
+ pub disabled: Option<bool>,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub connector_label: Option<String>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
- pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
+ pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
pub profile_id: Option<String>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
@@ -76,8 +170,13 @@ pub struct MerchantConnectorAccountNew {
pub status: storage_enums::ConnectorStatus,
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
+ pub id: String,
}
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_connector_account)]
pub struct MerchantConnectorAccountUpdateInternal {
@@ -88,13 +187,13 @@ pub struct MerchantConnectorAccountUpdateInternal {
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: Option<String>,
- pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
- pub frm_configs: Option<Secret<serde_json::Value>>,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub frm_configs: Option<pii::SecretSerdeValue>,
pub metadata: Option<pii::SecretSerdeValue>,
pub modified_at: Option<time::PrimitiveDateTime>,
pub connector_webhook_details: Option<pii::SecretSerdeValue>,
#[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
- pub frm_config: Option<Vec<Secret<serde_json::Value>>>,
+ pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
#[diesel(deserialize_as = super::OptionalDieselArray<String>)]
pub applepay_verified_domains: Option<Vec<String>>,
pub pm_auth_config: Option<pii::SecretSerdeValue>,
@@ -102,6 +201,31 @@ pub struct MerchantConnectorAccountUpdateInternal {
pub connector_wallets_details: Option<Encryption>,
}
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
+#[diesel(table_name = merchant_connector_account)]
+pub struct MerchantConnectorAccountUpdateInternal {
+ pub connector_type: Option<storage_enums::ConnectorType>,
+ pub connector_account_details: Option<Encryption>,
+ pub connector_label: Option<String>,
+ pub disabled: Option<bool>,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub modified_at: Option<time::PrimitiveDateTime>,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<pii::SecretSerdeValue>)]
+ pub frm_config: Option<Vec<pii::SecretSerdeValue>>,
+ #[diesel(deserialize_as = super::OptionalDieselArray<String>)]
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: Option<storage_enums::ConnectorStatus>,
+ pub connector_wallets_details: Option<Encryption>,
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
impl MerchantConnectorAccountUpdateInternal {
pub fn create_merchant_connector_account(
self,
@@ -128,3 +252,26 @@ impl MerchantConnectorAccountUpdateInternal {
}
}
}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+impl MerchantConnectorAccountUpdateInternal {
+ pub fn create_merchant_connector_account(
+ self,
+ source: MerchantConnectorAccount,
+ ) -> MerchantConnectorAccount {
+ MerchantConnectorAccount {
+ connector_type: self.connector_type.unwrap_or(source.connector_type),
+ connector_account_details: self
+ .connector_account_details
+ .unwrap_or(source.connector_account_details),
+ disabled: self.disabled,
+ payment_methods_enabled: self.payment_methods_enabled,
+ frm_config: self.frm_config,
+ modified_at: self.modified_at.unwrap_or(source.modified_at),
+ pm_auth_config: self.pm_auth_config,
+ status: self.status.unwrap_or(source.status),
+
+ ..source
+ }
+ }
+}
diff --git a/crates/diesel_models/src/query/merchant_connector_account.rs b/crates/diesel_models/src/query/merchant_connector_account.rs
index ee4cc84346..e4dcdba597 100644
--- a/crates/diesel_models/src/query/merchant_connector_account.rs
+++ b/crates/diesel_models/src/query/merchant_connector_account.rs
@@ -1,13 +1,19 @@
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods, Table};
use super::generics;
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+use crate::schema::merchant_connector_account::dsl;
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+use crate::schema_v2::merchant_connector_account::dsl;
use crate::{
errors,
merchant_connector_account::{
MerchantConnectorAccount, MerchantConnectorAccountNew,
MerchantConnectorAccountUpdateInternal,
},
- schema::merchant_connector_account::dsl,
PgPooledConn, StorageResult,
};
@@ -17,6 +23,10 @@ impl MerchantConnectorAccountNew {
}
}
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
impl MerchantConnectorAccount {
pub async fn update(
self,
@@ -149,3 +159,72 @@ impl MerchantConnectorAccount {
}
}
}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+impl MerchantConnectorAccount {
+ pub async fn update(
+ self,
+ conn: &PgPooledConn,
+ merchant_connector_account: MerchantConnectorAccountUpdateInternal,
+ ) -> StorageResult<Self> {
+ match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
+ conn,
+ self.id.to_owned(),
+ merchant_connector_account,
+ )
+ .await
+ {
+ Err(error) => match error.current_context() {
+ errors::DatabaseError::NoFieldsToUpdate => Ok(self),
+ _ => Err(error),
+ },
+ result => result,
+ }
+ }
+
+ pub async fn delete_by_id(conn: &PgPooledConn, id: &str) -> StorageResult<bool> {
+ generics::generic_delete::<<Self as HasTable>::Table, _>(conn, dsl::id.eq(id.to_owned()))
+ .await
+ }
+
+ pub async fn find_by_id(conn: &PgPooledConn, id: &str) -> StorageResult<Self> {
+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
+ conn,
+ dsl::id.eq(id.to_owned()),
+ )
+ .await
+ }
+
+ pub async fn find_by_merchant_id(
+ conn: &PgPooledConn,
+ merchant_id: &common_utils::id_type::MerchantId,
+ get_disabled: bool,
+ ) -> StorageResult<Vec<Self>> {
+ if get_disabled {
+ generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
+ conn,
+ dsl::merchant_id.eq(merchant_id.to_owned()),
+ None,
+ None,
+ Some(dsl::created_at.asc()),
+ )
+ .await
+ } else {
+ generics::generic_filter::<
+ <Self as HasTable>::Table,
+ _,
+ <<Self as HasTable>::Table as Table>::PrimaryKey,
+ _,
+ >(
+ conn,
+ dsl::merchant_id
+ .eq(merchant_id.to_owned())
+ .and(dsl::disabled.eq(false)),
+ None,
+ None,
+ None,
+ )
+ .await
+ }
+ }
+}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 83a4448616..648e6e4465 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -676,28 +676,18 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
- merchant_connector_account (merchant_connector_id) {
- id -> Int4,
+ merchant_connector_account (id) {
#[max_length = 64]
merchant_id -> Varchar,
#[max_length = 64]
connector_name -> Varchar,
connector_account_details -> Bytea,
- test_mode -> Nullable<Bool>,
disabled -> Nullable<Bool>,
- #[max_length = 128]
- merchant_connector_id -> Varchar,
payment_methods_enabled -> Nullable<Array<Nullable<Json>>>,
connector_type -> ConnectorType,
metadata -> Nullable<Jsonb>,
#[max_length = 255]
connector_label -> Nullable<Varchar>,
- business_country -> Nullable<CountryAlpha2>,
- #[max_length = 255]
- business_label -> Nullable<Varchar>,
- #[max_length = 64]
- business_sub_label -> Nullable<Varchar>,
- frm_configs -> Nullable<Jsonb>,
created_at -> Timestamp,
modified_at -> Timestamp,
connector_webhook_details -> Nullable<Jsonb>,
@@ -709,6 +699,8 @@ diesel::table! {
status -> ConnectorStatus,
additional_merchant_data -> Nullable<Bytea>,
connector_wallets_details -> Nullable<Bytea>,
+ #[max_length = 64]
+ id -> Varchar,
}
}
diff --git a/crates/hyperswitch_domain_models/Cargo.toml b/crates/hyperswitch_domain_models/Cargo.toml
index adbea0effb..662cfcff65 100644
--- a/crates/hyperswitch_domain_models/Cargo.toml
+++ b/crates/hyperswitch_domain_models/Cargo.toml
@@ -17,6 +17,7 @@ v2 = ["api_models/v2", "diesel_models/v2"]
v1 = ["api_models/v1", "diesel_models/v1"]
customer_v2 = ["api_models/customer_v2", "diesel_models/customer_v2"]
merchant_account_v2 = ["api_models/merchant_account_v2", "diesel_models/merchant_account_v2"]
+merchant_connector_account_v2 = ["api_models/merchant_connector_account_v2", "diesel_models/merchant_connector_account_v2"]
payment_v2 = ["api_models/payment_v2", "diesel_models/payment_v2"]
[dependencies]
diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs
index 450fdac8d8..e7ad703f92 100644
--- a/crates/hyperswitch_domain_models/src/lib.rs
+++ b/crates/hyperswitch_domain_models/src/lib.rs
@@ -4,6 +4,7 @@ pub mod customer;
pub mod errors;
pub mod mandates;
pub mod merchant_account;
+pub mod merchant_connector_account;
pub mod merchant_key_store;
pub mod payment_address;
pub mod payment_method_data;
diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs
new file mode 100644
index 0000000000..cea595aed6
--- /dev/null
+++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs
@@ -0,0 +1,501 @@
+use common_utils::{
+ crypto::Encryptable,
+ date_time,
+ encryption::Encryption,
+ errors::{CustomResult, ValidationError},
+ pii,
+ types::keymanager::{Identifier, KeyManagerState},
+};
+use diesel_models::{enums, merchant_connector_account::MerchantConnectorAccountUpdateInternal};
+use error_stack::ResultExt;
+use masking::{PeekInterface, Secret};
+
+use super::behaviour;
+use crate::type_encryption::{decrypt, decrypt_optional, AsyncLift};
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+#[derive(Clone, Debug)]
+pub struct MerchantConnectorAccount {
+ pub merchant_id: common_utils::id_type::MerchantId,
+ pub connector_name: String,
+ pub connector_account_details: Encryptable<pii::SecretSerdeValue>,
+ pub test_mode: Option<bool>,
+ pub disabled: Option<bool>,
+ pub merchant_connector_id: String,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_type: enums::ConnectorType,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub frm_configs: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_label: Option<String>,
+ pub business_country: Option<enums::CountryAlpha2>,
+ pub business_label: Option<String>,
+ pub business_sub_label: Option<String>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ pub profile_id: Option<String>,
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: enums::ConnectorStatus,
+ pub connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,
+ pub additional_merchant_data: Option<Encryptable<pii::SecretSerdeValue>>,
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+impl MerchantConnectorAccount {
+ pub fn get_id(&self) -> String {
+ self.merchant_connector_id.clone()
+ }
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[derive(Clone, Debug)]
+pub struct MerchantConnectorAccount {
+ pub id: String,
+ pub merchant_id: common_utils::id_type::MerchantId,
+ pub connector_name: String,
+ pub connector_account_details: Encryptable<pii::SecretSerdeValue>,
+ pub disabled: Option<bool>,
+ pub payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_type: enums::ConnectorType,
+ pub metadata: Option<pii::SecretSerdeValue>,
+ pub frm_configs: Option<Vec<pii::SecretSerdeValue>>,
+ pub connector_label: Option<String>,
+ pub created_at: time::PrimitiveDateTime,
+ pub modified_at: time::PrimitiveDateTime,
+ pub connector_webhook_details: Option<pii::SecretSerdeValue>,
+ pub profile_id: Option<String>,
+ pub applepay_verified_domains: Option<Vec<String>>,
+ pub pm_auth_config: Option<pii::SecretSerdeValue>,
+ pub status: enums::ConnectorStatus,
+ pub connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,
+ pub additional_merchant_data: Option<Encryptable<pii::SecretSerdeValue>>,
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+impl MerchantConnectorAccount {
+ pub fn get_id(&self) -> String {
+ self.id.clone()
+ }
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+#[derive(Debug)]
+pub enum MerchantConnectorAccountUpdate {
+ Update {
+ connector_type: Option<enums::ConnectorType>,
+ connector_name: Option<String>,
+ connector_account_details: Option<Encryptable<pii::SecretSerdeValue>>,
+ test_mode: Option<bool>,
+ disabled: Option<bool>,
+ merchant_connector_id: Option<String>,
+ payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ metadata: Option<pii::SecretSerdeValue>,
+ frm_configs: Option<Vec<pii::SecretSerdeValue>>,
+ connector_webhook_details: Option<pii::SecretSerdeValue>,
+ applepay_verified_domains: Option<Vec<String>>,
+ pm_auth_config: Option<pii::SecretSerdeValue>,
+ connector_label: Option<String>,
+ status: Option<enums::ConnectorStatus>,
+ connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,
+ },
+ ConnectorWalletDetailsUpdate {
+ connector_wallets_details: Encryptable<pii::SecretSerdeValue>,
+ },
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[derive(Debug)]
+pub enum MerchantConnectorAccountUpdate {
+ Update {
+ connector_type: Option<enums::ConnectorType>,
+ connector_account_details: Option<Encryptable<pii::SecretSerdeValue>>,
+ disabled: Option<bool>,
+ payment_methods_enabled: Option<Vec<pii::SecretSerdeValue>>,
+ metadata: Option<pii::SecretSerdeValue>,
+ frm_configs: Option<Vec<pii::SecretSerdeValue>>,
+ connector_webhook_details: Option<pii::SecretSerdeValue>,
+ applepay_verified_domains: Option<Vec<String>>,
+ pm_auth_config: Option<pii::SecretSerdeValue>,
+ connector_label: Option<String>,
+ status: Option<enums::ConnectorStatus>,
+ connector_wallets_details: Option<Encryptable<pii::SecretSerdeValue>>,
+ },
+ ConnectorWalletDetailsUpdate {
+ connector_wallets_details: Encryptable<pii::SecretSerdeValue>,
+ },
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+#[async_trait::async_trait]
+impl behaviour::Conversion for MerchantConnectorAccount {
+ type DstType = diesel_models::merchant_connector_account::MerchantConnectorAccount;
+ type NewDstType = diesel_models::merchant_connector_account::MerchantConnectorAccountNew;
+
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ Ok(
+ diesel_models::merchant_connector_account::MerchantConnectorAccount {
+ merchant_id: self.merchant_id,
+ connector_name: self.connector_name,
+ connector_account_details: self.connector_account_details.into(),
+ test_mode: self.test_mode,
+ disabled: self.disabled,
+ merchant_connector_id: self.merchant_connector_id,
+ payment_methods_enabled: self.payment_methods_enabled,
+ connector_type: self.connector_type,
+ metadata: self.metadata,
+ frm_configs: None,
+ frm_config: self.frm_configs,
+ business_country: self.business_country,
+ business_label: self.business_label,
+ connector_label: self.connector_label,
+ business_sub_label: self.business_sub_label,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ connector_webhook_details: self.connector_webhook_details,
+ profile_id: self.profile_id,
+ applepay_verified_domains: self.applepay_verified_domains,
+ pm_auth_config: self.pm_auth_config,
+ status: self.status,
+ connector_wallets_details: self.connector_wallets_details.map(Encryption::from),
+ additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),
+ },
+ )
+ }
+
+ async fn convert_back(
+ state: &KeyManagerState,
+ other: Self::DstType,
+ key: &Secret<Vec<u8>>,
+ _key_manager_identifier: Identifier,
+ ) -> CustomResult<Self, ValidationError> {
+ let identifier = Identifier::Merchant(other.merchant_id.clone());
+ Ok(Self {
+ merchant_id: other.merchant_id,
+ connector_name: other.connector_name,
+ connector_account_details: decrypt(
+ state,
+ other.connector_account_details,
+ identifier.clone(),
+ key.peek(),
+ )
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting connector account details".to_string(),
+ })?,
+ test_mode: other.test_mode,
+ disabled: other.disabled,
+ merchant_connector_id: other.merchant_connector_id,
+ payment_methods_enabled: other.payment_methods_enabled,
+ connector_type: other.connector_type,
+ metadata: other.metadata,
+
+ frm_configs: other.frm_config,
+ business_country: other.business_country,
+ business_label: other.business_label,
+ connector_label: other.connector_label,
+ business_sub_label: other.business_sub_label,
+ created_at: other.created_at,
+ modified_at: other.modified_at,
+ connector_webhook_details: other.connector_webhook_details,
+ profile_id: other.profile_id,
+ applepay_verified_domains: other.applepay_verified_domains,
+ pm_auth_config: other.pm_auth_config,
+ status: other.status,
+ connector_wallets_details: other
+ .connector_wallets_details
+ .async_lift(|inner| decrypt_optional(state, inner, identifier.clone(), key.peek()))
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting connector wallets details".to_string(),
+ })?,
+ additional_merchant_data: if let Some(data) = other.additional_merchant_data {
+ Some(
+ decrypt(state, data, identifier, key.peek())
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting additional_merchant_data".to_string(),
+ })?,
+ )
+ } else {
+ None
+ },
+ })
+ }
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ let now = date_time::now();
+ Ok(Self::NewDstType {
+ merchant_id: Some(self.merchant_id),
+ connector_name: Some(self.connector_name),
+ connector_account_details: Some(self.connector_account_details.into()),
+ test_mode: self.test_mode,
+ disabled: self.disabled,
+ merchant_connector_id: self.merchant_connector_id,
+ payment_methods_enabled: self.payment_methods_enabled,
+ connector_type: Some(self.connector_type),
+ metadata: self.metadata,
+ frm_configs: None,
+ frm_config: self.frm_configs,
+ business_country: self.business_country,
+ business_label: self.business_label,
+ connector_label: self.connector_label,
+ business_sub_label: self.business_sub_label,
+ created_at: now,
+ modified_at: now,
+ connector_webhook_details: self.connector_webhook_details,
+ profile_id: self.profile_id,
+ applepay_verified_domains: self.applepay_verified_domains,
+ pm_auth_config: self.pm_auth_config,
+ status: self.status,
+ connector_wallets_details: self.connector_wallets_details.map(Encryption::from),
+ additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),
+ })
+ }
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+#[async_trait::async_trait]
+impl behaviour::Conversion for MerchantConnectorAccount {
+ type DstType = diesel_models::merchant_connector_account::MerchantConnectorAccount;
+ type NewDstType = diesel_models::merchant_connector_account::MerchantConnectorAccountNew;
+
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ Ok(
+ diesel_models::merchant_connector_account::MerchantConnectorAccount {
+ id: self.id,
+ merchant_id: self.merchant_id,
+ connector_name: self.connector_name,
+ connector_account_details: self.connector_account_details.into(),
+ disabled: self.disabled,
+ payment_methods_enabled: self.payment_methods_enabled,
+ connector_type: self.connector_type,
+ metadata: self.metadata,
+ frm_config: self.frm_configs,
+ connector_label: self.connector_label,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ connector_webhook_details: self.connector_webhook_details,
+ profile_id: self.profile_id,
+ applepay_verified_domains: self.applepay_verified_domains,
+ pm_auth_config: self.pm_auth_config,
+ status: self.status,
+ connector_wallets_details: self.connector_wallets_details.map(Encryption::from),
+ additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),
+ },
+ )
+ }
+
+ async fn convert_back(
+ state: &KeyManagerState,
+ other: Self::DstType,
+ key: &Secret<Vec<u8>>,
+ _key_manager_identifier: Identifier,
+ ) -> CustomResult<Self, ValidationError> {
+ let identifier = Identifier::Merchant(other.merchant_id.clone());
+ Ok(Self {
+ id: other.id,
+ merchant_id: other.merchant_id,
+ connector_name: other.connector_name,
+ connector_account_details: decrypt(
+ state,
+ other.connector_account_details,
+ identifier.clone(),
+ key.peek(),
+ )
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting connector account details".to_string(),
+ })?,
+ disabled: other.disabled,
+ payment_methods_enabled: other.payment_methods_enabled,
+ connector_type: other.connector_type,
+ metadata: other.metadata,
+
+ frm_configs: other.frm_config,
+ connector_label: other.connector_label,
+ created_at: other.created_at,
+ modified_at: other.modified_at,
+ connector_webhook_details: other.connector_webhook_details,
+ profile_id: other.profile_id,
+ applepay_verified_domains: other.applepay_verified_domains,
+ pm_auth_config: other.pm_auth_config,
+ status: other.status,
+ connector_wallets_details: other
+ .connector_wallets_details
+ .async_lift(|inner| decrypt_optional(state, inner, identifier.clone(), key.peek()))
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting connector wallets details".to_string(),
+ })?,
+ additional_merchant_data: if let Some(data) = other.additional_merchant_data {
+ Some(
+ decrypt(state, data, identifier, key.peek())
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting additional_merchant_data".to_string(),
+ })?,
+ )
+ } else {
+ None
+ },
+ })
+ }
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ let now = date_time::now();
+ Ok(Self::NewDstType {
+ id: self.id,
+ merchant_id: Some(self.merchant_id),
+ connector_name: Some(self.connector_name),
+ connector_account_details: Some(self.connector_account_details.into()),
+ disabled: self.disabled,
+ payment_methods_enabled: self.payment_methods_enabled,
+ connector_type: Some(self.connector_type),
+ metadata: self.metadata,
+ frm_config: self.frm_configs,
+ connector_label: self.connector_label,
+ created_at: now,
+ modified_at: now,
+ connector_webhook_details: self.connector_webhook_details,
+ profile_id: self.profile_id,
+ applepay_verified_domains: self.applepay_verified_domains,
+ pm_auth_config: self.pm_auth_config,
+ status: self.status,
+ connector_wallets_details: self.connector_wallets_details.map(Encryption::from),
+ additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),
+ })
+ }
+}
+
+#[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+))]
+impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInternal {
+ fn from(merchant_connector_account_update: MerchantConnectorAccountUpdate) -> Self {
+ match merchant_connector_account_update {
+ MerchantConnectorAccountUpdate::Update {
+ connector_type,
+ connector_name,
+ connector_account_details,
+ test_mode,
+ disabled,
+ merchant_connector_id,
+ payment_methods_enabled,
+ metadata,
+ frm_configs,
+ connector_webhook_details,
+ applepay_verified_domains,
+ pm_auth_config,
+ connector_label,
+ status,
+ connector_wallets_details,
+ } => Self {
+ connector_type,
+ connector_name,
+ connector_account_details: connector_account_details.map(Encryption::from),
+ test_mode,
+ disabled,
+ merchant_connector_id,
+ payment_methods_enabled,
+ metadata,
+ frm_configs: None,
+ frm_config: frm_configs,
+ modified_at: Some(date_time::now()),
+ connector_webhook_details,
+ applepay_verified_domains,
+ pm_auth_config,
+ connector_label,
+ status,
+ connector_wallets_details: connector_wallets_details.map(Encryption::from),
+ },
+ MerchantConnectorAccountUpdate::ConnectorWalletDetailsUpdate {
+ connector_wallets_details,
+ } => Self {
+ connector_wallets_details: Some(Encryption::from(connector_wallets_details)),
+ connector_type: None,
+ connector_name: None,
+ connector_account_details: None,
+ connector_label: None,
+ test_mode: None,
+ disabled: None,
+ merchant_connector_id: None,
+ payment_methods_enabled: None,
+ frm_configs: None,
+ metadata: None,
+ modified_at: None,
+ connector_webhook_details: None,
+ frm_config: None,
+ applepay_verified_domains: None,
+ pm_auth_config: None,
+ status: None,
+ },
+ }
+ }
+}
+
+#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInternal {
+ fn from(merchant_connector_account_update: MerchantConnectorAccountUpdate) -> Self {
+ match merchant_connector_account_update {
+ MerchantConnectorAccountUpdate::Update {
+ connector_type,
+ connector_account_details,
+ disabled,
+ payment_methods_enabled,
+ metadata,
+ frm_configs,
+ connector_webhook_details,
+ applepay_verified_domains,
+ pm_auth_config,
+ connector_label,
+ status,
+ connector_wallets_details,
+ } => Self {
+ connector_type,
+ connector_account_details: connector_account_details.map(Encryption::from),
+ disabled,
+ payment_methods_enabled,
+ metadata,
+ frm_config: frm_configs,
+ modified_at: Some(date_time::now()),
+ connector_webhook_details,
+ applepay_verified_domains,
+ pm_auth_config,
+ connector_label,
+ status,
+ connector_wallets_details: connector_wallets_details.map(Encryption::from),
+ },
+ MerchantConnectorAccountUpdate::ConnectorWalletDetailsUpdate {
+ connector_wallets_details,
+ } => Self {
+ connector_wallets_details: Some(Encryption::from(connector_wallets_details)),
+ connector_type: None,
+ connector_account_details: None,
+ connector_label: None,
+ disabled: None,
+ payment_methods_enabled: None,
+ metadata: None,
+ modified_at: None,
+ connector_webhook_details: None,
+ frm_config: None,
+ applepay_verified_domains: None,
+ pm_auth_config: None,
+ status: None,
+ },
+ }
+ }
+}
diff --git a/crates/kgraph_utils/Cargo.toml b/crates/kgraph_utils/Cargo.toml
index 7dfebc3604..09c0ebd3e3 100644
--- a/crates/kgraph_utils/Cargo.toml
+++ b/crates/kgraph_utils/Cargo.toml
@@ -7,7 +7,7 @@ rust-version.workspace = true
license.workspace = true
[features]
-default = ["v1"]
+default = []
dummy_connector = ["api_models/dummy_connector", "euclid/dummy_connector"]
v1 = []
v2 = []
diff --git a/crates/kgraph_utils/benches/evaluation.rs b/crates/kgraph_utils/benches/evaluation.rs
index a48aefe4c9..5fdab57aac 100644
--- a/crates/kgraph_utils/benches/evaluation.rs
+++ b/crates/kgraph_utils/benches/evaluation.rs
@@ -56,7 +56,7 @@ fn build_test_data(
let stripe_account = MerchantConnectorResponse {
connector_type: api_enums::ConnectorType::FizOperations,
connector_name: "stripe".to_string(),
- connector_id: "something".to_string(),
+ id: "something".to_string(),
connector_account_details: masking::Secret::new(serde_json::json!({})),
disabled: None,
metadata: None,
diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs
index 95bcf1a9e0..2c61bdfe19 100644
--- a/crates/kgraph_utils/src/mca.rs
+++ b/crates/kgraph_utils/src/mca.rs
@@ -708,7 +708,7 @@ mod tests {
let stripe_account = MerchantConnectorResponse {
connector_type: api_enums::ConnectorType::FizOperations,
connector_name: "stripe".to_string(),
- connector_id: "something".to_string(),
+ id: "something".to_string(),
connector_label: Some("something".to_string()),
connector_account_details: masking::Secret::new(serde_json::json!({})),
disabled: None,
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index 7f713b889e..398e9143cf 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -32,12 +32,12 @@ payout_retry = ["payouts"]
recon = ["email", "api_models/recon"]
retry = []
v2 = ["api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2"]
-v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1"]
+v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1", "kgraph_utils/v1"]
customer_v2 = ["api_models/customer_v2", "diesel_models/customer_v2", "hyperswitch_domain_models/customer_v2"]
merchant_account_v2 = ["api_models/merchant_account_v2", "diesel_models/merchant_account_v2", "hyperswitch_domain_models/merchant_account_v2"]
payment_v2 = ["api_models/payment_v2", "diesel_models/payment_v2", "hyperswitch_domain_models/payment_v2"]
routing_v2 = ["api_models/routing_v2"]
-merchant_connector_account_v2 = ["api_models/merchant_connector_account_v2", "kgraph_utils/merchant_connector_account_v2"]
+merchant_connector_account_v2 = ["api_models/merchant_connector_account_v2", "kgraph_utils/merchant_connector_account_v2", "hyperswitch_domain_models/merchant_connector_account_v2", "diesel_models/merchant_connector_account_v2"]
# Partial Auth
# The feature reduces the overhead of the router authenticating the merchant for every request, and trusts on `x-merchant-id` header to be present in the request.
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 964c24cc83..26afafd7ad 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -49,7 +49,7 @@ use crate::{
types::{self as domain_types, AsyncLift},
},
storage::{self, enums::MerchantStorageScheme},
- transformers::ForeignTryFrom,
+ transformers::{ForeignTryFrom, ForeignTryInto},
},
utils,
};
@@ -1667,7 +1667,7 @@ struct PaymentMethodsEnabled<'a> {
}
impl<'a> PaymentMethodsEnabled<'a> {
- fn get_payment_methods_enabled(&self) -> RouterResult<Option<Vec<serde_json::Value>>> {
+ fn get_payment_methods_enabled(&self) -> RouterResult<Option<Vec<pii::SecretSerdeValue>>> {
let mut vec = Vec::new();
let payment_methods_enabled = match self.payment_methods_enabled.clone() {
Some(val) => {
@@ -1678,7 +1678,7 @@ impl<'a> PaymentMethodsEnabled<'a> {
.attach_printable(
"Failed while encoding to serde_json::Value, PaymentMethod",
)?;
- vec.push(pm_value)
+ vec.push(Secret::new(pm_value))
}
Some(vec)
}
@@ -1783,7 +1783,7 @@ impl<'a> PMAuthConfigValidation<'a> {
let pm_auth_mca = all_mcas
.clone()
.into_iter()
- .find(|mca| mca.merchant_connector_id == conn_choice.mca_id)
+ .find(|mca| mca.get_id() == conn_choice.mca_id)
.ok_or(errors::ApiErrorResponse::GenericNotFoundError {
message: "payment method auth connector account not found".to_string(),
})?;
@@ -1993,7 +1993,6 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
merchant_id: business_profile.merchant_id.clone(),
connector_type: self.connector_type,
connector_name: self.connector_name.to_string(),
- merchant_connector_id: utils::generate_id(consts::ID_LENGTH, "mca"),
connector_account_details: domain_types::encrypt(
key_manager_state,
self.connector_account_details.ok_or(
@@ -2014,6 +2013,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
connector_label: Some(connector_label.clone()),
created_at: date_time::now(),
modified_at: date_time::now(),
+ id: common_utils::generate_time_ordered_id("mca"),
connector_webhook_details: match self.connector_webhook_details {
Some(connector_webhook_details) => {
connector_webhook_details.encode_to_value(
@@ -2030,10 +2030,6 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {
pm_auth_config: self.pm_auth_config.clone(),
status: connector_status,
connector_wallets_details: helpers::get_encrypted_apple_pay_connector_wallets_details(state, &key_store, &self.metadata).await?,
- test_mode: None,
- business_country: None,
- business_label: None,
- business_sub_label: None,
additional_merchant_data: if let Some(mcd) = merchant_recipient_data {
Some(domain_types::encrypt(
key_manager_state,
@@ -2399,7 +2395,7 @@ pub async fn create_payment_connector(
//update merchant default config
let merchant_default_config_update = MerchantDefaultConfigUpdate {
routable_connector: &routable_connector,
- merchant_connector_id: &mca.merchant_connector_id,
+ merchant_connector_id: &mca.get_id(),
store,
merchant_id,
default_routing_config: &mut default_routing_config,
@@ -2421,7 +2417,7 @@ pub async fn create_payment_connector(
]),
);
- let mca_response = mca.try_into()?;
+ let mca_response = mca.foreign_try_into()?;
Ok(service_api::ApplicationResponse::Json(mca_response))
}
@@ -2456,7 +2452,7 @@ async fn validate_pm_auth(
for conn_choice in config.enabled_payment_methods {
let pm_auth_mca = all_mcas
.iter()
- .find(|mca| mca.merchant_connector_id == conn_choice.mca_id)
+ .find(|mca| mca.get_id() == conn_choice.mca_id)
.ok_or(errors::ApiErrorResponse::GenericNotFoundError {
message: "payment method auth connector account not found".to_string(),
})?;
@@ -2494,6 +2490,10 @@ pub async fn retrieve_payment_connector(
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let mca = store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
@@ -2506,7 +2506,15 @@ pub async fn retrieve_payment_connector(
id: merchant_connector_id.clone(),
})?;
- Ok(service_api::ApplicationResponse::Json(mca.try_into()?))
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let mca: domain::MerchantConnectorAccount = {
+ let _ = &merchant_connector_id;
+ todo!()
+ };
+
+ Ok(service_api::ApplicationResponse::Json(
+ mca.foreign_try_into()?,
+ ))
}
pub async fn list_payment_connectors(
@@ -2543,7 +2551,7 @@ pub async fn list_payment_connectors(
// The can be eliminated once [#79711](https://github.com/rust-lang/rust/issues/79711) is stabilized
for mca in merchant_connector_accounts.into_iter() {
- response.push(mca.try_into()?);
+ response.push(mca.foreign_try_into()?);
}
Ok(service_api::ApplicationResponse::Json(response))
@@ -2571,6 +2579,10 @@ pub async fn update_payment_connector(
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let mca = db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
@@ -2583,11 +2595,19 @@ pub async fn update_payment_connector(
id: merchant_connector_id.to_string(),
})?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let mca: domain::MerchantConnectorAccount = {
+ let _ = &merchant_connector_id;
+ let _ = &req;
+ let _ = &merchant_account;
+ todo!()
+ };
let payment_methods_enabled = req.payment_methods_enabled.map(|pm_enabled| {
pm_enabled
.iter()
.flat_map(Encode::encode_to_value)
- .collect::<Vec<serde_json::Value>>()
+ .map(Secret::new)
+ .collect::<Vec<Secret<serde_json::Value>>>()
});
let frm_configs = get_frm_config_as_secret(req.frm_configs);
@@ -2637,6 +2657,10 @@ pub async fn update_payment_connector(
.await?;
}
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let payment_connector = storage::MerchantConnectorAccountUpdate::Update {
connector_type: Some(req.connector_type),
connector_name: None,
@@ -2676,6 +2700,43 @@ pub async fn update_payment_connector(
)
.await?,
};
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let payment_connector = storage::MerchantConnectorAccountUpdate::Update {
+ connector_type: Some(req.connector_type),
+ connector_label: req.connector_label.clone(),
+ connector_account_details: req
+ .connector_account_details
+ .async_lift(|inner| {
+ domain_types::encrypt_optional(
+ key_manager_state,
+ inner,
+ km_types::Identifier::Merchant(key_store.merchant_id.clone()),
+ key_store.key.get_inner().peek(),
+ )
+ })
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed while encrypting data")?,
+ disabled,
+ payment_methods_enabled,
+ metadata: req.metadata,
+ frm_configs,
+ connector_webhook_details: match &req.connector_webhook_details {
+ Some(connector_webhook_details) => connector_webhook_details
+ .encode_to_value()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .map(Some)?
+ .map(Secret::new),
+ None => None,
+ },
+ applepay_verified_domains: None,
+ pm_auth_config: req.pm_auth_config,
+ status: Some(connector_status),
+ connector_wallets_details: helpers::get_encrypted_apple_pay_connector_wallets_details(
+ &state, &key_store, &metadata,
+ )
+ .await?,
+ };
// Profile id should always be present
let profile_id = mca
@@ -2704,7 +2765,7 @@ pub async fn update_payment_connector(
format!("Failed while updating MerchantConnectorAccount: id: {merchant_connector_id}")
})?;
- let response = updated_mca.try_into()?;
+ let response = updated_mca.foreign_try_into()?;
Ok(service_api::ApplicationResponse::Json(response))
}
@@ -2730,6 +2791,10 @@ pub async fn delete_payment_connector(
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let _mca = db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
@@ -2742,6 +2807,16 @@ pub async fn delete_payment_connector(
id: merchant_connector_id.clone(),
})?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ let _ = merchant_connector_id;
+ todo!()
+ };
+
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let is_deleted = db
.delete_merchant_connector_account_by_merchant_id_merchant_connector_id(
&merchant_id,
@@ -2752,6 +2827,9 @@ pub async fn delete_payment_connector(
id: merchant_connector_id.clone(),
})?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let is_deleted = { todo!() };
+
let response = api::MerchantConnectorDeleteResponse {
merchant_id,
merchant_connector_id,
diff --git a/crates/router/src/core/fraud_check.rs b/crates/router/src/core/fraud_check.rs
index dfd8e085f6..df3a5a2ca2 100644
--- a/crates/router/src/core/fraud_check.rs
+++ b/crates/router/src/core/fraud_check.rs
@@ -156,6 +156,10 @@ where
.await
.attach_printable("Could not find profile id from business details")?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let merchant_connector_account_from_db_option = db
.find_merchant_connector_account_by_profile_id_connector_name(
&state.into(),
@@ -169,6 +173,16 @@ where
})
.ok();
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let merchant_connector_account_from_db_option: Option<
+ domain::MerchantConnectorAccount,
+ > = {
+ let _ = key_store;
+ let _ = frm_routing_algorithm_struct;
+ let _ = profile_id;
+ todo!()
+ };
+
match merchant_connector_account_from_db_option {
Some(merchant_connector_account_from_db) => {
let frm_configs_option = merchant_connector_account_from_db
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index a0b5f7755f..8cb64d1e0d 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -2385,7 +2385,7 @@ pub async fn list_payment_methods(
};
filter_payment_methods(
&graph,
- mca.merchant_connector_id.clone(),
+ mca.get_id(),
payment_methods,
&mut req,
&mut response,
@@ -2401,10 +2401,7 @@ pub async fn list_payment_methods(
// No PM_FILTER_CGRAPH Cache present in MokaCache
let mut builder = cgraph::ConstraintGraphBuilder::new();
for mca in &filtered_mcas {
- let domain_id = builder.make_domain(
- mca.merchant_connector_id.clone(),
- mca.connector_name.as_str(),
- );
+ let domain_id = builder.make_domain(mca.get_id(), mca.connector_name.as_str());
let Ok(domain_id) = domain_id else {
logger::error!("Failed to construct domain for list payment methods");
@@ -2440,7 +2437,7 @@ pub async fn list_payment_methods(
};
filter_payment_methods(
&graph,
- mca.merchant_connector_id.clone(),
+ mca.get_id().clone(),
payment_methods,
&mut req,
&mut response,
@@ -2647,8 +2644,7 @@ pub async fn list_payment_methods(
.ok_or(errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration)?;
let matched_mca = filtered_mcas.iter().find(|m| {
- first_routable_connector.merchant_connector_id.as_ref()
- == Some(&m.merchant_connector_id)
+ first_routable_connector.merchant_connector_id.as_ref() == Some(&m.get_id())
});
if let Some(m) = matched_mca {
@@ -3374,7 +3370,7 @@ pub async fn call_surcharge_decision_management_for_saved_card(
pub async fn filter_payment_methods(
graph: &cgraph::ConstraintGraph<dir::DirValue>,
mca_id: String,
- payment_methods: &[serde_json::Value],
+ payment_methods: &[Secret<serde_json::Value>],
req: &mut api::PaymentMethodListRequest,
resp: &mut Vec<ResponsePaymentMethodIntermediate>,
payment_intent: Option<&storage::PaymentIntent>,
@@ -3384,7 +3380,9 @@ pub async fn filter_payment_methods(
saved_payment_methods: &settings::EligiblePaymentMethods,
) -> errors::CustomResult<(), errors::ApiErrorResponse> {
for payment_method in payment_methods.iter() {
- let parse_result = serde_json::from_value::<PaymentMethodsEnabled>(payment_method.clone());
+ let parse_result = serde_json::from_value::<PaymentMethodsEnabled>(
+ payment_method.clone().expose().clone(),
+ );
if let Ok(payment_methods_enabled) = parse_result {
let payment_method = payment_methods_enabled.payment_method;
@@ -4043,7 +4041,7 @@ pub async fn get_mca_status(
.collect::<Vec<_>>();
for mca in mcas {
- mca_ids.insert(mca.merchant_connector_id);
+ mca_ids.insert(mca.get_id());
}
for mca_id in connector_mandate_details.keys() {
diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs
index 7d90a5cb6b..0aad719089 100644
--- a/crates/router/src/core/payment_methods/utils.rs
+++ b/crates/router/src/core/payment_methods/utils.rs
@@ -9,6 +9,7 @@ use common_enums::enums;
use euclid::frontend::dir;
use hyperswitch_constraint_graph as cgraph;
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue};
+use masking::ExposeInterface;
use storage_impl::redis::cache::{CacheKey, PM_FILTERS_CGRAPH_CACHE};
use crate::{configs::settings, routes::SessionState};
@@ -16,14 +17,15 @@ use crate::{configs::settings, routes::SessionState};
pub fn make_pm_graph(
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
domain_id: cgraph::DomainId,
- payment_methods: &[serde_json::value::Value],
+ payment_methods: &[masking::Secret<serde_json::value::Value>],
connector: String,
pm_config_mapping: &settings::ConnectorFilters,
supported_payment_methods_for_mandate: &settings::SupportedPaymentMethodsForMandate,
supported_payment_methods_for_update_mandate: &settings::SupportedPaymentMethodsForMandate,
) -> Result<(), KgraphError> {
for payment_method in payment_methods.iter() {
- let pm_enabled = serde_json::from_value::<PaymentMethodsEnabled>(payment_method.clone());
+ let pm_enabled =
+ serde_json::from_value::<PaymentMethodsEnabled>(payment_method.clone().expose());
if let Ok(payment_methods_enabled) = pm_enabled {
compile_pm_graph(
builder,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 6c598e67a3..c00d6be21c 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3281,6 +3281,10 @@ impl MerchantConnectorAccountType {
}
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
pub fn is_test_mode_on(&self) -> Option<bool> {
match self {
Self::DbVal(val) => val.test_mode,
@@ -3288,9 +3292,14 @@ impl MerchantConnectorAccountType {
}
}
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ pub fn is_test_mode_on(&self) -> Option<bool> {
+ None
+ }
+
pub fn get_mca_id(&self) -> Option<String> {
match self {
- Self::DbVal(db_val) => Some(db_val.merchant_connector_id.to_string()),
+ Self::DbVal(db_val) => Some(db_val.get_id()),
Self::CacheVal(_) => None,
}
}
@@ -3325,7 +3334,7 @@ pub async fn get_merchant_connector_account(
merchant_connector_id: Option<&String>,
) -> RouterResult<MerchantConnectorAccountType> {
let db = &*state.store;
- let key_manager_state = &state.into();
+ let key_manager_state: &KeyManagerState = &state.into();
match creds_identifier {
Some(creds_identifier) => {
let key = merchant_id.get_creds_identifier_key(&creds_identifier);
@@ -3399,35 +3408,64 @@ pub async fn get_merchant_connector_account(
Ok(MerchantConnectorAccountType::CacheVal(res))
}
None => {
- if let Some(merchant_connector_id) = merchant_connector_id {
- db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
- key_manager_state,
- merchant_id,
- merchant_connector_id,
- key_store,
- )
- .await
- .to_not_found_response(
- errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: merchant_connector_id.to_string(),
- },
- )
- } else {
- db.find_merchant_connector_account_by_profile_id_connector_name(
- key_manager_state,
- profile_id,
- connector_name,
- key_store,
- )
- .await
- .to_not_found_response(
- errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: format!("profile id {profile_id} and connector name {connector_name}"),
- },
- )
- }
+ let mca: RouterResult<domain::MerchantConnectorAccount> =
+ if let Some(merchant_connector_id) = merchant_connector_id {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
+ key_manager_state,
+ merchant_id,
+ merchant_connector_id,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: merchant_connector_id.to_string(),
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ // get mca using id
+ {
+ let _id = merchant_connector_id;
+ let _ = key_store;
+ let _ = profile_id;
+ let _ = connector_name;
+ let _ = key_manager_state;
+ todo!()
+ }
+ } else {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_merchant_connector_account_by_profile_id_connector_name(
+ key_manager_state,
+ profile_id,
+ connector_name,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: format!(
+ "profile id {profile_id} and connector name {connector_name}"
+ ),
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ todo!()
+ }
+ };
+ mca.map(MerchantConnectorAccountType::DbVal)
}
- .map(MerchantConnectorAccountType::DbVal),
}
}
@@ -4261,7 +4299,7 @@ where
for merchant_connector_account in profile_specific_merchant_connector_account_list {
if is_apple_pay_simplified_flow(
- merchant_connector_account.metadata,
+ merchant_connector_account.metadata.clone(),
merchant_connector_account
.connector_wallets_details
.as_deref()
@@ -4272,7 +4310,7 @@ where
&state.conf.connectors,
&merchant_connector_account.connector_name.to_string(),
api::GetToken::Connector,
- Some(merchant_connector_account.merchant_connector_id),
+ Some(merchant_connector_account.get_id()),
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Invalid connector name received")?;
@@ -5135,7 +5173,7 @@ pub async fn validate_merchant_connector_ids_in_connector_mandate_details(
.iter()
.map(|merchant_connector_account| {
(
- merchant_connector_account.merchant_connector_id.clone(),
+ merchant_connector_account.get_id(),
merchant_connector_account.clone(),
)
})
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index e65fcbc390..5e384021e5 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -445,17 +445,30 @@ where
&state.conf.connectors,
&merchant_connector_account.connector_name.to_string(),
connector_type,
- Some(merchant_connector_account.merchant_connector_id.clone()),
+ Some(merchant_connector_account.get_id()),
)
.map_err(|err| {
logger::error!(session_token_error=?err);
err
}) {
- session_connector_data.push(api::SessionConnectorData {
- payment_method_type,
- connector: connector_data,
- business_sub_label: merchant_connector_account.business_sub_label.clone(),
- })
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ let new_session_connector_data = api::SessionConnectorData::new(
+ payment_method_type,
+ connector_data,
+ merchant_connector_account.business_sub_label.clone(),
+ );
+ session_connector_data.push(new_session_connector_data)
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ let new_session_connector_data =
+ api::SessionConnectorData::new(payment_method_type, connector_data, None);
+ session_connector_data.push(new_session_connector_data)
+ }
};
}
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index 151192fb8b..f823f6846f 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -45,7 +45,7 @@ use crate::{
types::{
api::{self, routing as routing_types},
domain, storage as oss_storage,
- transformers::{ForeignFrom, ForeignInto},
+ transformers::{ForeignFrom, ForeignInto, ForeignTryFrom},
},
utils::{OptionExt, ValueExt},
SessionState,
@@ -567,7 +567,7 @@ pub async fn refresh_cgraph_cache<'a>(
let api_mcas = merchant_connector_accounts
.into_iter()
- .map(admin_api::MerchantConnectorResponse::try_from)
+ .map(admin_api::MerchantConnectorResponse::foreign_try_from)
.collect::<Result<Vec<_>, _>>()
.change_context(errors::RoutingError::KgraphCacheRefreshFailed)?;
let connector_configs = state
diff --git a/crates/router/src/core/payout_link.rs b/crates/router/src/core/payout_link.rs
index d4dd01b4dd..77b5c1463f 100644
--- a/crates/router/src/core/payout_link.rs
+++ b/crates/router/src/core/payout_link.rs
@@ -264,6 +264,8 @@ pub async fn filter_payout_methods(
key_store: &domain::MerchantKeyStore,
payout: &hyperswitch_domain_models::payouts::payouts::Payouts,
) -> errors::RouterResult<Vec<link_utils::EnabledPaymentMethod>> {
+ use masking::ExposeInterface;
+
let db = &*state.store;
let key_manager_state = &state.into();
//Fetch all merchant connector accounts
@@ -311,7 +313,7 @@ pub async fn filter_payout_methods(
};
for payout_method in payout_methods.iter() {
let parse_result = serde_json::from_value::<api_models::admin::PaymentMethodsEnabled>(
- payout_method.clone(),
+ payout_method.clone().expose(),
);
if let Ok(payment_methods_enabled) = parse_result {
let payment_method = payment_methods_enabled.payment_method;
diff --git a/crates/router/src/core/pm_auth.rs b/crates/router/src/core/pm_auth.rs
index f2d5d2d7d5..8d237da5ed 100644
--- a/crates/router/src/core/pm_auth.rs
+++ b/crates/router/src/core/pm_auth.rs
@@ -136,6 +136,10 @@ pub async fn create_link_token(
.and_then(|address| address.country)
.map(|country| country.to_string());
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let merchant_connector_account = state
.store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
@@ -149,6 +153,12 @@ pub async fn create_link_token(
id: merchant_account.get_id().get_string_repr().to_owned(),
})?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let merchant_connector_account = {
+ let _ = billing_country;
+ todo!()
+ };
+
let auth_type = helpers::get_connector_auth_type(merchant_connector_account)?;
let router_data = pm_auth_types::LinkTokenRouterData {
@@ -231,6 +241,10 @@ pub async fn exchange_token_core(
let connector = PaymentAuthConnectorData::get_connector_by_name(connector_name)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let merchant_connector_account = state
.store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
@@ -244,6 +258,14 @@ pub async fn exchange_token_core(
id: merchant_account.get_id().get_string_repr().to_owned(),
})?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let merchant_connector_account: domain::MerchantConnectorAccount = {
+ let _ = merchant_account;
+ let _ = connector;
+ let _ = key_store;
+ todo!()
+ };
+
let auth_type = helpers::get_connector_auth_type(merchant_connector_account.clone())?;
let access_token = get_access_token_from_exchange_api(
@@ -273,7 +295,7 @@ pub async fn exchange_token_core(
state,
bank_account_details_resp,
(connector_name, access_token),
- merchant_connector_account.merchant_connector_id,
+ merchant_connector_account.get_id(),
))
.await?;
@@ -716,6 +738,10 @@ pub async fn retrieve_payment_method_from_auth_service(
.await
.to_not_found_response(ApiErrorResponse::MerchantAccountNotFound)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let mca = db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
@@ -731,6 +757,13 @@ pub async fn retrieve_payment_method_from_auth_service(
"error while fetching merchant_connector_account from merchant_id and connector name",
)?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let mca = {
+ let _ = merchant_account;
+ let _ = connector;
+ todo!()
+ };
+
let auth_type = pm_auth_helpers::get_connector_auth_type(mca)?;
let BankAccountAccessCreds::AccessToken(access_token) =
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index f2c230f0b8..a6591c640d 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -993,9 +993,7 @@ pub async fn get_filters_for_refunds(
.connector_label
.clone()
.map(|label| {
- let info = merchant_connector_account
- .clone()
- .to_merchant_connector_info(&label.clone());
+ let info = merchant_connector_account.to_merchant_connector_info(&label);
(merchant_connector_account.connector_name, info)
})
})
diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs
index d4729d1e62..6ef6688395 100644
--- a/crates/router/src/core/routing/helpers.rs
+++ b/crates/router/src/core/routing/helpers.rs
@@ -412,7 +412,7 @@ pub async fn validate_connectors_in_routing_config(
let name_mca_id_set = all_mcas
.iter()
.filter(|mca| mca.profile_id.as_deref() == Some(profile_id))
- .map(|mca| (&mca.connector_name, &mca.merchant_connector_id))
+ .map(|mca| (&mca.connector_name, mca.get_id()))
.collect::<FxHashSet<_>>();
let name_set = all_mcas
@@ -424,7 +424,7 @@ pub async fn validate_connectors_in_routing_config(
let connector_choice = |choice: &routing_types::RoutableConnectorChoice| {
if let Some(ref mca_id) = choice.merchant_connector_id {
error_stack::ensure!(
- name_mca_id_set.contains(&(&choice.connector.to_string(), mca_id)),
+ name_mca_id_set.contains(&(&choice.connector.to_string(), mca_id.clone())),
errors::ApiErrorResponse::InvalidRequestData {
message: format!(
"connector with name '{}' and merchant connector account id '{}' not found for the given profile",
diff --git a/crates/router/src/core/user/dashboard_metadata.rs b/crates/router/src/core/user/dashboard_metadata.rs
index 6eb1dd572d..ee11a38136 100644
--- a/crates/router/src/core/user/dashboard_metadata.rs
+++ b/crates/router/src/core/user/dashboard_metadata.rs
@@ -653,7 +653,7 @@ pub async fn backfill_metadata(
user.to_owned(),
DBEnum::StripeConnected,
types::MetaData::StripeConnected(api::ProcessorConnected {
- processor_id: mca.merchant_connector_id,
+ processor_id: mca.get_id(),
processor_name: mca.connector_name,
}),
)
@@ -693,7 +693,7 @@ pub async fn backfill_metadata(
user.to_owned(),
DBEnum::PaypalConnected,
types::MetaData::PaypalConnected(api::ProcessorConnected {
- processor_id: mca.merchant_connector_id,
+ processor_id: mca.get_id(),
processor_name: mca.connector_name,
}),
)
@@ -711,18 +711,32 @@ pub async fn get_merchant_connector_account_by_name(
connector_name: &str,
key_store: &MerchantKeyStore,
) -> UserResult<Option<domain::MerchantConnectorAccount>> {
- state
- .store
- .find_merchant_connector_account_by_merchant_id_connector_name(
- &state.into(),
- merchant_id,
- connector_name,
- key_store,
- )
- .await
- .map_err(|e| {
- e.change_context(UserErrors::InternalServerError)
- .attach_printable("DB Error Fetching DashboardMetaData")
- })
- .map(|data| data.first().cloned())
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ state
+ .store
+ .find_merchant_connector_account_by_merchant_id_connector_name(
+ &state.into(),
+ merchant_id,
+ connector_name,
+ key_store,
+ )
+ .await
+ .map_err(|e| {
+ e.change_context(UserErrors::InternalServerError)
+ .attach_printable("DB Error Fetching DashboardMetaData")
+ })
+ .map(|data| data.first().cloned())
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ let _ = state;
+ let _ = merchant_id;
+ let _ = connector_name;
+ let _ = key_store;
+ todo!()
+ }
}
diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs
index 724f244d39..c5bb43f12c 100644
--- a/crates/router/src/core/verification.rs
+++ b/crates/router/src/core/verification.rs
@@ -101,6 +101,10 @@ pub async fn get_verified_apple_domains_with_mid_mca_id(
.await
.change_context(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let verified_domains = db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
key_manager_state,
@@ -113,6 +117,13 @@ pub async fn get_verified_apple_domains_with_mid_mca_id(
.applepay_verified_domains
.unwrap_or_default();
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let verified_domains = {
+ let _ = merchant_connector_id;
+ let _ = key_store;
+ todo!()
+ };
+
Ok(services::api::ApplicationResponse::Json(
verifications::ApplepayVerifiedDomainsResponse { verified_domains },
))
diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs
index c286497e5c..43a4bfdc73 100644
--- a/crates/router/src/core/verification/utils.rs
+++ b/crates/router/src/core/verification/utils.rs
@@ -26,6 +26,10 @@ pub async fn check_existence_and_add_domain_to_db(
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let merchant_connector_account = state
.store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
@@ -37,6 +41,14 @@ pub async fn check_existence_and_add_domain_to_db(
.await
.change_context(errors::ApiErrorResponse::InternalServerError)?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let merchant_connector_account: hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccount = {
+ let _ = merchant_connector_id;
+ let _ = key_store;
+ let _ = domain_from_req;
+ todo!()
+ };
+
let mut already_verified_domains = merchant_connector_account
.applepay_verified_domains
.clone()
@@ -48,6 +60,10 @@ pub async fn check_existence_and_add_domain_to_db(
.collect();
already_verified_domains.append(&mut new_verified_domains);
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let updated_mca = storage::MerchantConnectorAccountUpdate::Update {
connector_type: None,
connector_name: None,
@@ -65,6 +81,21 @@ pub async fn check_existence_and_add_domain_to_db(
status: None,
connector_wallets_details: None,
};
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let updated_mca = storage::MerchantConnectorAccountUpdate::Update {
+ connector_type: None,
+ connector_account_details: None,
+ disabled: None,
+ payment_methods_enabled: None,
+ metadata: None,
+ frm_configs: None,
+ connector_webhook_details: None,
+ applepay_verified_domains: Some(already_verified_domains.clone()),
+ pm_auth_config: None,
+ connector_label: None,
+ status: None,
+ connector_wallets_details: None,
+ };
state
.store
.update_merchant_connector_account(
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 61207aebb9..86ac8d49d6 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -1673,6 +1673,10 @@ async fn fetch_optional_mca_and_connector(
> {
let db = &state.store;
if connector_name_or_mca_id.starts_with("mca_") {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let mca = db
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&state.into(),
@@ -1687,11 +1691,16 @@ async fn fetch_optional_mca_and_connector(
.attach_printable(
"error while fetching merchant_connector_account from connector_id",
)?;
- let (connector, connector_name) = get_connector_by_connector_name(
- state,
- &mca.connector_name,
- Some(mca.merchant_connector_id.clone()),
- )?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let mca: domain::MerchantConnectorAccount = {
+ let _ = merchant_account;
+ let _ = key_store;
+ let _ = db;
+ todo!()
+ };
+
+ let (connector, connector_name) =
+ get_connector_by_connector_name(state, &mca.connector_name, Some(mca.get_id()))?;
Ok((Some(mca), connector, connector_name))
} else {
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 02b4344451..63282bddc3 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -1018,6 +1018,10 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.update_multiple_merchant_connector_accounts(merchant_connector_accounts)
.await
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_merchant_id_connector_label(
&self,
state: &KeyManagerState,
@@ -1035,6 +1039,10 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.await
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_merchant_id_connector_name(
&self,
state: &KeyManagerState,
@@ -1052,6 +1060,10 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.await
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_profile_id_connector_name(
&self,
state: &KeyManagerState,
@@ -1080,6 +1092,10 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.await
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&self,
state: &KeyManagerState,
@@ -1097,6 +1113,18 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.await
}
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn find_by_merchant_connector_account_id(
+ &self,
+ state: &KeyManagerState,
+ id: &str,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
+ self.diesel_store
+ .find_by_merchant_connector_account_id(state, id, key_store)
+ .await
+ }
+
async fn find_merchant_connector_account_by_merchant_id_and_disabled_list(
&self,
state: &KeyManagerState,
@@ -1126,6 +1154,10 @@ impl MerchantConnectorAccountInterface for KafkaStore {
.await
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id(
&self,
merchant_id: &id_type::MerchantId,
@@ -1138,6 +1170,16 @@ impl MerchantConnectorAccountInterface for KafkaStore {
)
.await
}
+
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn delete_merchant_connector_account_by_id(
+ &self,
+ id: &str,
+ ) -> CustomResult<bool, errors::StorageError> {
+ self.diesel_store
+ .delete_merchant_connector_account_by_id(id)
+ .await
+ }
}
#[async_trait::async_trait]
diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs
index 31f5e285c4..80019012c0 100644
--- a/crates/router/src/db/merchant_connector_account.rs
+++ b/crates/router/src/db/merchant_connector_account.rs
@@ -122,6 +122,10 @@ where
NewDstType = storage::MerchantConnectorAccountNew,
>,
{
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_merchant_id_connector_label(
&self,
state: &KeyManagerState,
@@ -130,6 +134,10 @@ where
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError>;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_profile_id_connector_name(
&self,
state: &KeyManagerState,
@@ -138,6 +146,10 @@ where
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError>;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_merchant_id_connector_name(
&self,
state: &KeyManagerState,
@@ -153,6 +165,10 @@ where
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError>;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&self,
state: &KeyManagerState,
@@ -161,6 +177,14 @@ where
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError>;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn find_by_merchant_connector_account_id(
+ &self,
+ state: &KeyManagerState,
+ id: &str,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError>;
+
async fn find_merchant_connector_account_by_merchant_id_and_disabled_list(
&self,
state: &KeyManagerState,
@@ -185,15 +209,29 @@ where
)>,
) -> CustomResult<(), errors::StorageError>;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id(
&self,
merchant_id: &common_utils::id_type::MerchantId,
merchant_connector_id: &str,
) -> CustomResult<bool, errors::StorageError>;
+
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn delete_merchant_connector_account_by_id(
+ &self,
+ id: &str,
+ ) -> CustomResult<bool, errors::StorageError>;
}
#[async_trait::async_trait]
impl MerchantConnectorAccountInterface for Store {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
#[instrument(skip_all)]
async fn find_merchant_connector_account_by_merchant_id_connector_label(
&self,
@@ -244,6 +282,10 @@ impl MerchantConnectorAccountInterface for Store {
}
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
#[instrument(skip_all)]
async fn find_merchant_connector_account_by_profile_id_connector_name(
&self,
@@ -298,6 +340,10 @@ impl MerchantConnectorAccountInterface for Store {
}
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
#[instrument(skip_all)]
async fn find_merchant_connector_account_by_merchant_id_connector_name(
&self,
@@ -333,6 +379,10 @@ impl MerchantConnectorAccountInterface for Store {
}
#[instrument(skip_all)]
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&self,
state: &KeyManagerState,
@@ -387,6 +437,50 @@ impl MerchantConnectorAccountInterface for Store {
}
}
+ #[instrument(skip_all)]
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn find_by_merchant_connector_account_id(
+ &self,
+ state: &KeyManagerState,
+ id: &str,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
+ let find_call = || async {
+ let conn = connection::pg_connection_read(self).await?;
+ storage::MerchantConnectorAccount::find_by_id(&conn, id)
+ .await
+ .map_err(|error| report!(errors::StorageError::from(error)))
+ };
+
+ #[cfg(not(feature = "accounts_cache"))]
+ {
+ find_call()
+ .await?
+ .convert(
+ state,
+ key_store.key.get_inner(),
+ key_store.merchant_id.clone(),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ }
+
+ #[cfg(feature = "accounts_cache")]
+ {
+ cache::get_or_populate_in_memory(self, id, find_call, &cache::ACCOUNTS_CACHE)
+ .await?
+ .convert(
+ state,
+ key_store.key.get_inner(),
+ common_utils::types::keymanager::Identifier::Merchant(
+ key_store.merchant_id.clone(),
+ ),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ }
+ }
+
#[instrument(skip_all)]
async fn insert_merchant_connector_account(
&self,
@@ -479,8 +573,7 @@ impl MerchantConnectorAccountInterface for Store {
)?;
let _merchant_id = merchant_connector_account.merchant_id.clone();
- let _merchant_connector_id =
- merchant_connector_account.merchant_connector_id.clone();
+ let _merchant_connector_id = merchant_connector_account.get_id().clone();
let update = update_call(
&connection_pool,
@@ -548,6 +641,10 @@ impl MerchantConnectorAccountInterface for Store {
}
#[instrument(skip_all)]
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn update_merchant_connector_account(
&self,
state: &KeyManagerState,
@@ -626,6 +723,91 @@ impl MerchantConnectorAccountInterface for Store {
}
#[instrument(skip_all)]
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn update_merchant_connector_account(
+ &self,
+ state: &KeyManagerState,
+ this: domain::MerchantConnectorAccount,
+ merchant_connector_account: storage::MerchantConnectorAccountUpdateInternal,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
+ let _connector_name = this.connector_name.clone();
+ let _profile_id = this
+ .profile_id
+ .clone()
+ .ok_or(errors::StorageError::ValueNotFound(
+ "profile_id".to_string(),
+ ))?;
+
+ let _merchant_id = this.merchant_id.clone();
+ let _merchant_connector_id = this.get_id().clone();
+
+ let update_call = || async {
+ let conn = connection::pg_connection_write(self).await?;
+ Conversion::convert(this)
+ .await
+ .change_context(errors::StorageError::EncryptionError)?
+ .update(&conn, merchant_connector_account)
+ .await
+ .map_err(|error| report!(errors::StorageError::from(error)))
+ .async_and_then(|item| async {
+ item.convert(
+ state,
+ key_store.key.get_inner(),
+ common_utils::types::keymanager::Identifier::Merchant(
+ key_store.merchant_id.clone(),
+ ),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ })
+ .await
+ };
+
+ #[cfg(feature = "accounts_cache")]
+ {
+ // Redact all caches as any of might be used because of backwards compatibility
+ cache::publish_and_redact_multiple(
+ self,
+ [
+ cache::CacheKind::Accounts(
+ format!("{}_{}", _profile_id, _connector_name).into(),
+ ),
+ cache::CacheKind::Accounts(
+ format!(
+ "{}_{}",
+ _merchant_id.get_string_repr(),
+ _merchant_connector_id
+ )
+ .into(),
+ ),
+ cache::CacheKind::CGraph(
+ format!("cgraph_{}_{_profile_id}", _merchant_id.get_string_repr()).into(),
+ ),
+ cache::CacheKind::PmFiltersCGraph(
+ format!(
+ "pm_filters_cgraph_{}_{_profile_id}",
+ _merchant_id.get_string_repr()
+ )
+ .into(),
+ ),
+ ],
+ update_call,
+ )
+ .await
+ }
+
+ #[cfg(not(feature = "accounts_cache"))]
+ {
+ update_call().await
+ }
+ }
+
+ #[instrument(skip_all)]
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id(
&self,
merchant_id: &common_utils::id_type::MerchantId,
@@ -689,6 +871,63 @@ impl MerchantConnectorAccountInterface for Store {
delete_call().await
}
}
+
+ #[instrument(skip_all)]
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn delete_merchant_connector_account_by_id(
+ &self,
+ id: &str,
+ ) -> CustomResult<bool, errors::StorageError> {
+ let conn = connection::pg_connection_write(self).await?;
+ let delete_call = || async {
+ storage::MerchantConnectorAccount::delete_by_id(&conn, id)
+ .await
+ .map_err(|error| report!(errors::StorageError::from(error)))
+ };
+
+ #[cfg(feature = "accounts_cache")]
+ {
+ // We need to fetch mca here because the key that's saved in cache in
+ // {merchant_id}_{connector_label}.
+ // Used function from storage model to reuse the connection that made here instead of
+ // creating new.
+
+ let mca = storage::MerchantConnectorAccount::find_by_id(&conn, id)
+ .await
+ .map_err(|error| report!(errors::StorageError::from(error)))?;
+
+ let _profile_id = mca.profile_id.ok_or(errors::StorageError::ValueNotFound(
+ "profile_id".to_string(),
+ ))?;
+
+ cache::publish_and_redact_multiple(
+ self,
+ [
+ cache::CacheKind::Accounts(
+ format!("{}_{}", mca.merchant_id.get_string_repr(), _profile_id).into(),
+ ),
+ cache::CacheKind::CGraph(
+ format!("cgraph_{}_{_profile_id}", mca.merchant_id.get_string_repr())
+ .into(),
+ ),
+ cache::CacheKind::PmFiltersCGraph(
+ format!(
+ "pm_filters_cgraph_{}_{_profile_id}",
+ mca.merchant_id.get_string_repr()
+ )
+ .into(),
+ ),
+ ],
+ delete_call,
+ )
+ .await
+ }
+
+ #[cfg(not(feature = "accounts_cache"))]
+ {
+ delete_call().await
+ }
+ }
}
#[async_trait::async_trait]
@@ -704,6 +943,10 @@ impl MerchantConnectorAccountInterface for MockDb {
// apple pay certificate migration
Err(errors::StorageError::MockDbError)?
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_merchant_id_connector_label(
&self,
state: &KeyManagerState,
@@ -743,6 +986,10 @@ impl MerchantConnectorAccountInterface for MockDb {
}
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_merchant_id_connector_name(
&self,
state: &KeyManagerState,
@@ -776,6 +1023,10 @@ impl MerchantConnectorAccountInterface for MockDb {
Ok(output)
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_merchant_connector_account_by_profile_id_connector_name(
&self,
state: &KeyManagerState,
@@ -811,6 +1062,10 @@ impl MerchantConnectorAccountInterface for MockDb {
}
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id(
&self,
state: &KeyManagerState,
@@ -850,6 +1105,48 @@ impl MerchantConnectorAccountInterface for MockDb {
}
}
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn find_by_merchant_connector_account_id(
+ &self,
+ state: &KeyManagerState,
+ id: &str,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
+ match self
+ .merchant_connector_accounts
+ .lock()
+ .await
+ .iter()
+ .find(|account| account.get_id() == id)
+ .cloned()
+ .async_map(|account| async {
+ account
+ .convert(
+ state,
+ key_store.key.get_inner(),
+ common_utils::types::keymanager::Identifier::Merchant(
+ key_store.merchant_id.clone(),
+ ),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ })
+ .await
+ {
+ Some(result) => result,
+ None => {
+ return Err(errors::StorageError::ValueNotFound(
+ "cannot find merchant connector account".to_string(),
+ )
+ .into())
+ }
+ }
+ }
+
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn insert_merchant_connector_account(
&self,
state: &KeyManagerState,
@@ -894,6 +1191,48 @@ impl MerchantConnectorAccountInterface for MockDb {
.change_context(errors::StorageError::DecryptionError)
}
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn insert_merchant_connector_account(
+ &self,
+ state: &KeyManagerState,
+ t: domain::MerchantConnectorAccount,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
+ let mut accounts = self.merchant_connector_accounts.lock().await;
+ let account = storage::MerchantConnectorAccount {
+ id: t.id,
+ merchant_id: t.merchant_id,
+ connector_name: t.connector_name,
+ connector_account_details: t.connector_account_details.into(),
+ disabled: t.disabled,
+ payment_methods_enabled: t.payment_methods_enabled,
+ metadata: t.metadata,
+ frm_config: t.frm_configs,
+ connector_type: t.connector_type,
+ connector_label: t.connector_label,
+ created_at: common_utils::date_time::now(),
+ modified_at: common_utils::date_time::now(),
+ connector_webhook_details: t.connector_webhook_details,
+ profile_id: t.profile_id,
+ applepay_verified_domains: t.applepay_verified_domains,
+ pm_auth_config: t.pm_auth_config,
+ status: t.status,
+ connector_wallets_details: t.connector_wallets_details.map(Encryption::from),
+ additional_merchant_data: t.additional_merchant_data.map(|data| data.into()),
+ };
+ accounts.push(account.clone());
+ account
+ .convert(
+ state,
+ key_store.key.get_inner(),
+ common_utils::types::keymanager::Identifier::Merchant(
+ key_store.merchant_id.clone(),
+ ),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ }
+
async fn find_merchant_connector_account_by_merchant_id_and_disabled_list(
&self,
state: &KeyManagerState,
@@ -932,6 +1271,10 @@ impl MerchantConnectorAccountInterface for MockDb {
Ok(output)
}
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn update_merchant_connector_account(
&self,
state: &KeyManagerState,
@@ -974,6 +1317,55 @@ impl MerchantConnectorAccountInterface for MockDb {
}
}
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn update_merchant_connector_account(
+ &self,
+ state: &KeyManagerState,
+ this: domain::MerchantConnectorAccount,
+ merchant_connector_account: storage::MerchantConnectorAccountUpdateInternal,
+ key_store: &domain::MerchantKeyStore,
+ ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
+ let mca_update_res = self
+ .merchant_connector_accounts
+ .lock()
+ .await
+ .iter_mut()
+ .find(|account| account.get_id() == this.get_id())
+ .map(|a| {
+ let updated =
+ merchant_connector_account.create_merchant_connector_account(a.clone());
+ *a = updated.clone();
+ updated
+ })
+ .async_map(|account| async {
+ account
+ .convert(
+ state,
+ key_store.key.get_inner(),
+ common_utils::types::keymanager::Identifier::Merchant(
+ key_store.merchant_id.clone(),
+ ),
+ )
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ })
+ .await;
+
+ match mca_update_res {
+ Some(result) => result,
+ None => {
+ return Err(errors::StorageError::ValueNotFound(
+ "cannot find merchant connector account to update".to_string(),
+ )
+ .into())
+ }
+ }
+ }
+
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id(
&self,
merchant_id: &common_utils::id_type::MerchantId,
@@ -996,6 +1388,26 @@ impl MerchantConnectorAccountInterface for MockDb {
}
}
}
+
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn delete_merchant_connector_account_by_id(
+ &self,
+ id: &str,
+ ) -> CustomResult<bool, errors::StorageError> {
+ let mut accounts = self.merchant_connector_accounts.lock().await;
+ match accounts.iter().position(|account| account.get_id() == id) {
+ Some(index) => {
+ accounts.remove(index);
+ return Ok(true);
+ }
+ None => {
+ return Err(errors::StorageError::ValueNotFound(
+ "cannot find merchant connector account to delete".to_string(),
+ )
+ .into())
+ }
+ }
+ }
}
#[cfg(feature = "accounts_cache")]
@@ -1003,6 +1415,10 @@ impl MerchantConnectorAccountInterface for MockDb {
mod merchant_connector_account_cache_tests {
use std::sync::Arc;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
use api_models::enums::CountryAlpha2;
use common_utils::{date_time, types::keymanager::Identifier};
use diesel_models::enums::ConnectorType;
@@ -1035,6 +1451,10 @@ mod merchant_connector_account_cache_tests {
#[allow(clippy::unwrap_used)]
#[tokio::test]
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
async fn test_connector_profile_id_cache() {
let conf = Settings::new().unwrap();
let tx: oneshot::Sender<()> = oneshot::channel().0;
@@ -1192,4 +1612,161 @@ mod merchant_connector_account_cache_tests {
.await
.is_none())
}
+
+ #[allow(clippy::unwrap_used)]
+ #[tokio::test]
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ async fn test_connector_profile_id_cache() {
+ let conf = Settings::new().unwrap();
+ let tx: oneshot::Sender<()> = oneshot::channel().0;
+
+ let app_state = Box::pin(routes::AppState::with_storage(
+ conf,
+ StorageImpl::PostgresqlTest,
+ tx,
+ Box::new(services::MockApiClient),
+ ))
+ .await;
+ let state = &Arc::new(app_state)
+ .get_session_state("public", || {})
+ .unwrap();
+ #[allow(clippy::expect_used)]
+ let db = MockDb::new(&redis_interface::RedisSettings::default())
+ .await
+ .expect("Failed to create Mock store");
+
+ let redis_conn = db.get_redis_conn().unwrap();
+ let master_key = db.get_master_key();
+ redis_conn
+ .subscribe("hyperswitch_invalidate")
+ .await
+ .unwrap();
+
+ let merchant_id =
+ common_utils::id_type::MerchantId::try_from(std::borrow::Cow::from("test_merchant"))
+ .unwrap();
+ let connector_label = "stripe_USA";
+ let id = "simple_id";
+ let profile_id = "pro_max_ultra";
+ let key_manager_state = &state.into();
+ db.insert_merchant_key_store(
+ key_manager_state,
+ domain::MerchantKeyStore {
+ merchant_id: merchant_id.clone(),
+ key: domain::types::encrypt(
+ key_manager_state,
+ services::generate_aes256_key().unwrap().to_vec().into(),
+ Identifier::Merchant(merchant_id.clone()),
+ master_key,
+ )
+ .await
+ .unwrap(),
+ created_at: datetime!(2023-02-01 0:00),
+ },
+ &master_key.to_vec().into(),
+ )
+ .await
+ .unwrap();
+
+ let merchant_key = db
+ .get_merchant_key_store_by_merchant_id(
+ key_manager_state,
+ &merchant_id,
+ &master_key.to_vec().into(),
+ )
+ .await
+ .unwrap();
+
+ let mca = domain::MerchantConnectorAccount {
+ id: id.to_string(),
+ merchant_id: merchant_id.clone(),
+ connector_name: "stripe".to_string(),
+ connector_account_details: domain::types::encrypt(
+ key_manager_state,
+ serde_json::Value::default().into(),
+ Identifier::Merchant(merchant_key.merchant_id.clone()),
+ merchant_key.key.get_inner().peek(),
+ )
+ .await
+ .unwrap(),
+ disabled: None,
+ payment_methods_enabled: None,
+ connector_type: ConnectorType::FinOperations,
+ metadata: None,
+ frm_configs: None,
+ connector_label: Some(connector_label.to_string()),
+ created_at: date_time::now(),
+ modified_at: date_time::now(),
+ connector_webhook_details: None,
+ profile_id: Some(profile_id.to_string()),
+ applepay_verified_domains: None,
+ pm_auth_config: None,
+ status: common_enums::ConnectorStatus::Inactive,
+ connector_wallets_details: Some(
+ domain::types::encrypt(
+ key_manager_state,
+ serde_json::Value::default().into(),
+ Identifier::Merchant(merchant_key.merchant_id.clone()),
+ merchant_key.key.get_inner().peek(),
+ )
+ .await
+ .unwrap(),
+ ),
+ additional_merchant_data: None,
+ };
+
+ db.insert_merchant_connector_account(key_manager_state, mca.clone(), &merchant_key)
+ .await
+ .unwrap();
+
+ let find_call = || async {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ let mca = db
+ .find_merchant_connector_account_by_profile_id_connector_name(
+ key_manager_state,
+ profile_id,
+ &mca.connector_name,
+ &merchant_key,
+ )
+ .await
+ .unwrap();
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let mca: domain::MerchantConnectorAccount = { todo!() };
+ Conversion::convert(mca)
+ .await
+ .change_context(errors::StorageError::DecryptionError)
+ };
+
+ let _: storage::MerchantConnectorAccount = cache::get_or_populate_in_memory(
+ &db,
+ &format!("{}_{}", merchant_id.clone().get_string_repr(), profile_id),
+ find_call,
+ &ACCOUNTS_CACHE,
+ )
+ .await
+ .unwrap();
+
+ let delete_call = || async { db.delete_merchant_connector_account_by_id(id).await };
+
+ cache::publish_and_redact(
+ &db,
+ CacheKind::Accounts(
+ format!("{}_{}", merchant_id.get_string_repr(), connector_label).into(),
+ ),
+ delete_call,
+ )
+ .await
+ .unwrap();
+
+ assert!(ACCOUNTS_CACHE
+ .get_val::<domain::MerchantConnectorAccount>(CacheKey {
+ key: format!("{}_{}", merchant_id.get_string_repr(), connector_label),
+ prefix: String::default(),
+ },)
+ .await
+ .is_none())
+ }
}
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index c85b60d13d..550b1c7af1 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -211,6 +211,20 @@ pub struct SessionConnectorData {
pub business_sub_label: Option<String>,
}
+impl SessionConnectorData {
+ pub fn new(
+ payment_method_type: api_enums::PaymentMethodType,
+ connector: ConnectorData,
+ business_sub_label: Option<String>,
+ ) -> Self {
+ Self {
+ payment_method_type,
+ connector,
+ business_sub_label,
+ }
+ }
+}
+
/// Session Surcharge type
pub enum SessionSurchargeDetails {
/// Surcharge is calculated by hyperswitch
diff --git a/crates/router/src/types/domain/merchant_connector_account.rs b/crates/router/src/types/domain/merchant_connector_account.rs
index 86d367c1f1..8c7cb1ed71 100644
--- a/crates/router/src/types/domain/merchant_connector_account.rs
+++ b/crates/router/src/types/domain/merchant_connector_account.rs
@@ -1,256 +1 @@
-use common_utils::{
- crypto::Encryptable,
- date_time,
- encryption::Encryption,
- errors::{CustomResult, ValidationError},
- pii,
- types::keymanager::{Identifier, KeyManagerState},
-};
-use diesel_models::{enums, merchant_connector_account::MerchantConnectorAccountUpdateInternal};
-use error_stack::ResultExt;
-use masking::{PeekInterface, Secret};
-
-use super::{
- behaviour,
- types::{decrypt, decrypt_optional, AsyncLift},
-};
-#[derive(Clone, Debug)]
-pub struct MerchantConnectorAccount {
- pub merchant_id: common_utils::id_type::MerchantId,
- pub connector_name: String,
- pub connector_account_details: Encryptable<Secret<serde_json::Value>>,
- pub test_mode: Option<bool>,
- pub disabled: Option<bool>,
- pub merchant_connector_id: String,
- pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
- pub connector_type: enums::ConnectorType,
- pub metadata: Option<pii::SecretSerdeValue>,
- pub frm_configs: Option<Vec<Secret<serde_json::Value>>>,
- pub connector_label: Option<String>,
- pub business_country: Option<enums::CountryAlpha2>,
- pub business_label: Option<String>,
- pub business_sub_label: Option<String>,
- pub created_at: time::PrimitiveDateTime,
- pub modified_at: time::PrimitiveDateTime,
- pub connector_webhook_details: Option<pii::SecretSerdeValue>,
- pub profile_id: Option<String>,
- pub applepay_verified_domains: Option<Vec<String>>,
- pub pm_auth_config: Option<pii::SecretSerdeValue>,
- pub status: enums::ConnectorStatus,
- pub connector_wallets_details: Option<Encryptable<Secret<serde_json::Value>>>,
- pub additional_merchant_data: Option<Encryptable<Secret<serde_json::Value>>>,
-}
-
-#[derive(Debug)]
-pub enum MerchantConnectorAccountUpdate {
- Update {
- connector_type: Option<enums::ConnectorType>,
- connector_name: Option<String>,
- connector_account_details: Option<Encryptable<Secret<serde_json::Value>>>,
- test_mode: Option<bool>,
- disabled: Option<bool>,
- merchant_connector_id: Option<String>,
- payment_methods_enabled: Option<Vec<serde_json::Value>>,
- metadata: Option<pii::SecretSerdeValue>,
- frm_configs: Option<Vec<Secret<serde_json::Value>>>,
- connector_webhook_details: Option<pii::SecretSerdeValue>,
- applepay_verified_domains: Option<Vec<String>>,
- pm_auth_config: Option<pii::SecretSerdeValue>,
- connector_label: Option<String>,
- status: Option<enums::ConnectorStatus>,
- connector_wallets_details: Option<Encryptable<Secret<serde_json::Value>>>,
- },
- ConnectorWalletDetailsUpdate {
- connector_wallets_details: Encryptable<Secret<serde_json::Value>>,
- },
-}
-
-#[async_trait::async_trait]
-impl behaviour::Conversion for MerchantConnectorAccount {
- type DstType = diesel_models::merchant_connector_account::MerchantConnectorAccount;
- type NewDstType = diesel_models::merchant_connector_account::MerchantConnectorAccountNew;
-
- async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
- Ok(
- diesel_models::merchant_connector_account::MerchantConnectorAccount {
- merchant_id: self.merchant_id,
- connector_name: self.connector_name,
- connector_account_details: self.connector_account_details.into(),
- test_mode: self.test_mode,
- disabled: self.disabled,
- merchant_connector_id: self.merchant_connector_id,
- payment_methods_enabled: self.payment_methods_enabled,
- connector_type: self.connector_type,
- metadata: self.metadata,
- frm_configs: None,
- frm_config: self.frm_configs,
- business_country: self.business_country,
- business_label: self.business_label,
- connector_label: self.connector_label,
- business_sub_label: self.business_sub_label,
- created_at: self.created_at,
- modified_at: self.modified_at,
- connector_webhook_details: self.connector_webhook_details,
- profile_id: self.profile_id,
- applepay_verified_domains: self.applepay_verified_domains,
- pm_auth_config: self.pm_auth_config,
- status: self.status,
- connector_wallets_details: self.connector_wallets_details.map(Encryption::from),
- additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),
- },
- )
- }
-
- async fn convert_back(
- state: &KeyManagerState,
- other: Self::DstType,
- key: &Secret<Vec<u8>>,
- _key_manager_identifier: Identifier,
- ) -> CustomResult<Self, ValidationError> {
- let identifier = Identifier::Merchant(other.merchant_id.clone());
- Ok(Self {
- merchant_id: other.merchant_id,
- connector_name: other.connector_name,
- connector_account_details: decrypt(
- state,
- other.connector_account_details,
- identifier.clone(),
- key.peek(),
- )
- .await
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting connector account details".to_string(),
- })?,
- test_mode: other.test_mode,
- disabled: other.disabled,
- merchant_connector_id: other.merchant_connector_id,
- payment_methods_enabled: other.payment_methods_enabled,
- connector_type: other.connector_type,
- metadata: other.metadata,
-
- frm_configs: other.frm_config,
- business_country: other.business_country,
- business_label: other.business_label,
- connector_label: other.connector_label,
- business_sub_label: other.business_sub_label,
- created_at: other.created_at,
- modified_at: other.modified_at,
- connector_webhook_details: other.connector_webhook_details,
- profile_id: other.profile_id,
- applepay_verified_domains: other.applepay_verified_domains,
- pm_auth_config: other.pm_auth_config,
- status: other.status,
- connector_wallets_details: other
- .connector_wallets_details
- .async_lift(|inner| decrypt_optional(state, inner, identifier.clone(), key.peek()))
- .await
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting connector wallets details".to_string(),
- })?,
- additional_merchant_data: if let Some(data) = other.additional_merchant_data {
- Some(
- decrypt(state, data, identifier, key.peek())
- .await
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting additional_merchant_data".to_string(),
- })?,
- )
- } else {
- None
- },
- })
- }
-
- async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
- let now = date_time::now();
- Ok(Self::NewDstType {
- merchant_id: Some(self.merchant_id),
- connector_name: Some(self.connector_name),
- connector_account_details: Some(self.connector_account_details.into()),
- test_mode: self.test_mode,
- disabled: self.disabled,
- merchant_connector_id: self.merchant_connector_id,
- payment_methods_enabled: self.payment_methods_enabled,
- connector_type: Some(self.connector_type),
- metadata: self.metadata,
- frm_configs: None,
- frm_config: self.frm_configs,
- business_country: self.business_country,
- business_label: self.business_label,
- connector_label: self.connector_label,
- business_sub_label: self.business_sub_label,
- created_at: now,
- modified_at: now,
- connector_webhook_details: self.connector_webhook_details,
- profile_id: self.profile_id,
- applepay_verified_domains: self.applepay_verified_domains,
- pm_auth_config: self.pm_auth_config,
- status: self.status,
- connector_wallets_details: self.connector_wallets_details.map(Encryption::from),
- additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),
- })
- }
-}
-
-impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInternal {
- fn from(merchant_connector_account_update: MerchantConnectorAccountUpdate) -> Self {
- match merchant_connector_account_update {
- MerchantConnectorAccountUpdate::Update {
- connector_type,
- connector_name,
- connector_account_details,
- test_mode,
- disabled,
- merchant_connector_id,
- payment_methods_enabled,
- metadata,
- frm_configs,
- connector_webhook_details,
- applepay_verified_domains,
- pm_auth_config,
- connector_label,
- status,
- connector_wallets_details,
- } => Self {
- connector_type,
- connector_name,
- connector_account_details: connector_account_details.map(Encryption::from),
- test_mode,
- disabled,
- merchant_connector_id,
- payment_methods_enabled,
- metadata,
- frm_configs: None,
- frm_config: frm_configs,
- modified_at: Some(date_time::now()),
- connector_webhook_details,
- applepay_verified_domains,
- pm_auth_config,
- connector_label,
- status,
- connector_wallets_details: connector_wallets_details.map(Encryption::from),
- },
- MerchantConnectorAccountUpdate::ConnectorWalletDetailsUpdate {
- connector_wallets_details,
- } => Self {
- connector_wallets_details: Some(Encryption::from(connector_wallets_details)),
- connector_type: None,
- connector_name: None,
- connector_account_details: None,
- connector_label: None,
- test_mode: None,
- disabled: None,
- merchant_connector_id: None,
- payment_methods_enabled: None,
- frm_configs: None,
- metadata: None,
- modified_at: None,
- connector_webhook_details: None,
- frm_config: None,
- applepay_verified_domains: None,
- pm_auth_config: None,
- status: None,
- },
- }
- }
-}
+pub use hyperswitch_domain_models::merchant_connector_account::*;
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index ce59a85dc9..d25d9e9c39 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -923,15 +923,21 @@ impl ForeignFrom<diesel_models::cards_info::CardInfo> for api_models::cards_info
}
}
-impl TryFrom<domain::MerchantConnectorAccount>
+impl ForeignTryFrom<domain::MerchantConnectorAccount>
for api_models::admin::MerchantConnectorListResponse
{
type Error = error_stack::Report<errors::ApiErrorResponse>;
- fn try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {
+ fn foreign_try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {
let payment_methods_enabled = match item.payment_methods_enabled {
- Some(val) => serde_json::Value::Array(val)
- .parse_value("PaymentMethods")
- .change_context(errors::ApiErrorResponse::InternalServerError)?,
+ Some(secret_val) => {
+ let val = secret_val
+ .into_iter()
+ .map(|secret| secret.expose())
+ .collect();
+ serde_json::Value::Array(val)
+ .parse_value("PaymentMethods")
+ .change_context(errors::ApiErrorResponse::InternalServerError)?
+ }
None => None,
};
let frm_configs = match item.frm_configs {
@@ -952,6 +958,10 @@ impl TryFrom<domain::MerchantConnectorAccount>
}
None => None,
};
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let response = Self {
connector_type: item.connector_type,
connector_name: item.connector_name,
@@ -983,21 +993,57 @@ impl TryFrom<domain::MerchantConnectorAccount>
.transpose()?
.map(api_models::admin::AdditionalMerchantData::foreign_from),
};
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ let response = Self {
+ id: item.id,
+ connector_type: item.connector_type,
+ connector_name: item.connector_name,
+ connector_label: item.connector_label,
+ disabled: item.disabled,
+ payment_methods_enabled,
+ metadata: item.metadata,
+ frm_configs,
+ profile_id: item.profile_id,
+ applepay_verified_domains: item.applepay_verified_domains,
+ pm_auth_config: item.pm_auth_config,
+ status: item.status,
+ additional_merchant_data: item
+ .additional_merchant_data
+ .map(|data| {
+ let data = data.into_inner();
+ serde_json::Value::parse_value::<router_types::AdditionalMerchantData>(
+ data.expose(),
+ "AdditionalMerchantData",
+ )
+ .attach_printable("Unable to deserialize additional_merchant_data")
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ })
+ .transpose()?
+ .map(api_models::admin::AdditionalMerchantData::foreign_from),
+ };
Ok(response)
}
}
-impl TryFrom<domain::MerchantConnectorAccount> for api_models::admin::MerchantConnectorResponse {
+impl ForeignTryFrom<domain::MerchantConnectorAccount>
+ for api_models::admin::MerchantConnectorResponse
+{
type Error = error_stack::Report<errors::ApiErrorResponse>;
- fn try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {
- let payment_methods_enabled = match item.payment_methods_enabled {
- Some(val) => serde_json::Value::Array(val)
- .parse_value("PaymentMethods")
- .change_context(errors::ApiErrorResponse::InternalServerError)?,
+ fn foreign_try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {
+ let payment_methods_enabled = match item.payment_methods_enabled.clone() {
+ Some(secret_val) => {
+ let val = secret_val
+ .into_iter()
+ .map(|secret| secret.expose())
+ .collect();
+ serde_json::Value::Array(val)
+ .parse_value("PaymentMethods")
+ .change_context(errors::ApiErrorResponse::InternalServerError)?
+ }
None => None,
};
let frm_configs = match item.frm_configs {
- Some(frm_value) => {
+ Some(ref frm_value) => {
let configs_for_frm : Vec<api_models::admin::FrmConfigs> = frm_value
.iter()
.map(|config| { config
@@ -1016,10 +1062,10 @@ impl TryFrom<domain::MerchantConnectorAccount> for api_models::admin::MerchantCo
};
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
let response = Self {
+ id: item.get_id(),
connector_type: item.connector_type,
connector_name: item.connector_name,
connector_label: item.connector_label,
- connector_id: item.merchant_connector_id,
connector_account_details: item.connector_account_details.into_inner(),
disabled: item.disabled,
payment_methods_enabled,
diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs
index 6798cdc3ea..1e8761d137 100644
--- a/crates/router/src/utils.rs
+++ b/crates/router/src/utils.rs
@@ -366,16 +366,31 @@ pub async fn find_mca_from_authentication_id_type(
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?
}
};
- db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
- &state.into(),
- merchant_account.get_id(),
- &authentication.merchant_connector_id,
- key_store,
- )
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: authentication.merchant_connector_id.to_string(),
- })
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
+ &state.into(),
+ merchant_account.get_id(),
+ &authentication.merchant_connector_id,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: authentication.merchant_connector_id.to_string(),
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ //get mca using id
+ {
+ let _ = key_store;
+ let _ = authentication;
+ todo!()
+ }
}
pub async fn get_mca_from_payment_intent(
@@ -394,19 +409,37 @@ pub async fn get_mca_from_payment_intent(
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
- let key_manager_state = &state.into();
+ let key_manager_state: &KeyManagerState = &state.into();
match payment_attempt.merchant_connector_id {
- Some(merchant_connector_id) => db
- .find_by_merchant_connector_account_merchant_id_merchant_connector_id(
- key_manager_state,
- merchant_account.get_id(),
- &merchant_connector_id,
- key_store,
- )
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: merchant_connector_id,
- }),
+ Some(merchant_connector_id) => {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
+ key_manager_state,
+ merchant_account.get_id(),
+ &merchant_connector_id,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: merchant_connector_id,
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ //get mca using id
+ let _id = merchant_connector_id;
+ let _ = key_store;
+ let _ = key_manager_state;
+ let _ = connector_name;
+ todo!()
+ }
+ }
None => {
let profile_id = match payment_intent.profile_id {
Some(profile_id) => profile_id,
@@ -422,19 +455,30 @@ pub async fn get_mca_from_payment_intent(
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("profile_id is not set in payment_intent")?,
};
-
- db.find_merchant_connector_account_by_profile_id_connector_name(
- key_manager_state,
- &profile_id,
- connector_name,
- key_store,
- )
- .await
- .to_not_found_response(
- errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: format!("profile_id {profile_id} and connector_name {connector_name}"),
- },
- )
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_merchant_connector_account_by_profile_id_connector_name(
+ key_manager_state,
+ &profile_id,
+ connector_name,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: format!("profile_id {profile_id} and connector_name {connector_name}"),
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ //get mca using id
+ let _ = profile_id;
+ todo!()
+ }
}
}
}
@@ -466,33 +510,64 @@ pub async fn get_mca_from_payout_attempt(
.await
.to_not_found_response(errors::ApiErrorResponse::PayoutNotFound)?,
};
- let key_manager_state = &state.into();
+ let key_manager_state: &KeyManagerState = &state.into();
match payout.merchant_connector_id {
- Some(merchant_connector_id) => db
- .find_by_merchant_connector_account_merchant_id_merchant_connector_id(
- key_manager_state,
- merchant_account.get_id(),
- &merchant_connector_id,
- key_store,
- )
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: merchant_connector_id,
- }),
- None => db
- .find_merchant_connector_account_by_profile_id_connector_name(
- key_manager_state,
- &payout.profile_id,
- connector_name,
- key_store,
- )
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: format!(
- "profile_id {} and connector_name {}",
- payout.profile_id, connector_name
- ),
- }),
+ Some(merchant_connector_id) => {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
+ key_manager_state,
+ merchant_account.get_id(),
+ &merchant_connector_id,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: merchant_connector_id,
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ //get mca using id
+ let _id = merchant_connector_id;
+ let _ = key_store;
+ let _ = connector_name;
+ let _ = key_manager_state;
+ todo!()
+ }
+ }
+ None => {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_merchant_connector_account_by_profile_id_connector_name(
+ key_manager_state,
+ &payout.profile_id,
+ connector_name,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: format!(
+ "profile_id {} and connector_name {}",
+ payout.profile_id, connector_name
+ ),
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ todo!()
+ }
+ }
}
}
@@ -505,17 +580,32 @@ pub async fn get_mca_from_object_reference_id(
) -> CustomResult<domain::MerchantConnectorAccount, errors::ApiErrorResponse> {
let db = &*state.store;
match merchant_account.default_profile.as_ref() {
- Some(profile_id) => db
- .find_merchant_connector_account_by_profile_id_connector_name(
- &state.into(),
- profile_id,
- connector_name,
- key_store,
- )
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: format!("profile_id {profile_id} and connector_name {connector_name}"),
- }),
+ Some(profile_id) => {
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
+ {
+ db.find_merchant_connector_account_by_profile_id_connector_name(
+ &state.into(),
+ profile_id,
+ connector_name,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: format!("profile_id {profile_id} and connector_name {connector_name}"),
+ },
+ )
+ }
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ let _ = db;
+ let _ = profile_id;
+ todo!()
+ }
+ }
_ => match object_reference_id {
webhooks::ObjectReferenceId::PaymentId(payment_id_type) => {
get_mca_from_payment_intent(
diff --git a/crates/router/src/utils/connector_onboarding.rs b/crates/router/src/utils/connector_onboarding.rs
index b66190f450..7813a7cb31 100644
--- a/crates/router/src/utils/connector_onboarding.rs
+++ b/crates/router/src/utils/connector_onboarding.rs
@@ -56,6 +56,10 @@ pub async fn check_if_connector_exists(
.await
.to_not_found_response(ApiErrorResponse::MerchantAccountNotFound)?;
+ #[cfg(all(
+ any(feature = "v1", feature = "v2"),
+ not(feature = "merchant_connector_account_v2")
+ ))]
let _connector = state
.store
.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
@@ -69,6 +73,13 @@ pub async fn check_if_connector_exists(
id: connector_id.to_string(),
})?;
+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
+ {
+ let _ = connector_id;
+ let _ = key_store;
+ todo!()
+ };
+
Ok(())
}
diff --git a/v2_migrations/2024-07-31-065721_mca_v2/down.sql b/v2_migrations/2024-07-31-065721_mca_v2/down.sql
new file mode 100644
index 0000000000..167cfd8fe5
--- /dev/null
+++ b/v2_migrations/2024-07-31-065721_mca_v2/down.sql
@@ -0,0 +1,21 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS frm_configs jsonb;
+
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
+
+ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey;
+
+DROP INDEX IF EXISTS merchant_connector_account_id_index;
+
+UPDATE merchant_connector_account SET merchant_connector_id = id;
+
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;
+
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS id SERIAL;
+
+ALTER TABLE merchant_connector_account ADD PRIMARY KEY (merchant_connector_id);
+
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS business_country "CountryAlpha2";
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS business_label VARCHAR(255);
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS business_sub_label VARCHAR(64);
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS test_mode BOOLEAN;
diff --git a/v2_migrations/2024-07-31-065721_mca_v2/up.sql b/v2_migrations/2024-07-31-065721_mca_v2/up.sql
new file mode 100644
index 0000000000..ca7859af4e
--- /dev/null
+++ b/v2_migrations/2024-07-31-065721_mca_v2/up.sql
@@ -0,0 +1,26 @@
+-- Your SQL goes here
+-- This migration is to remove the business_country, business_label, business_sub_label, and test_mode columns from the merchant_connector_account table
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_country;
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_label;
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_sub_label;
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS test_mode;
+
+-- This migration is to modify the id column in merchant_connector_account table to be a VARCHAR(64) and to set the id column as primary key
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;
+
+ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS id VARCHAR(64);
+
+-- Backfill the id column with the merchant_connector_id to prevent null values
+UPDATE merchant_connector_account SET id = merchant_connector_id;
+
+CREATE UNIQUE INDEX merchant_connector_account_id_index ON merchant_connector_account (id);
+
+ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey;
+
+ALTER TABLE merchant_connector_account ADD PRIMARY KEY (id);
+
+-- This migration is to remove the merchant_connector_id column from the merchant_connector_account table
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS merchant_connector_id;
+
+-- This migration is to remove the frm_configs column from the merchant_connector_account table
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS frm_configs;
\ No newline at end of file