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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(router): add feature_metadata for merchant_connector_account create v2 flow (#7144)
chikke srujan647e163117a5
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex 7cdd6fe9d3..f7f1ca34a3 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -10908,6 +10908,20 @@},"additionalProperties": false},+ "MerchantConnectorAccountFeatureMetadata": {+ "type": "object",+ "description": "Feature metadata for merchant connector account",+ "properties": {+ "revenue_recovery": {+ "allOf": [+ {+ "$ref": "#/components/schemas/RevenueRecoveryMetadata"+ }+ ],+ "nullable": true+ }+ }+ },"MerchantConnectorCreate": {"type": "object","description": "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.\"",@@ -11003,6 +11017,14 @@}],"nullable": true+ },+ "feature_metadata": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantConnectorAccountFeatureMetadata"+ }+ ],+ "nullable": true}},"additionalProperties": false@@ -11263,6 +11285,14 @@}],"nullable": true+ },+ "feature_metadata": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantConnectorAccountFeatureMetadata"+ }+ ],+ "nullable": true}},"additionalProperties": false@@ -11360,6 +11390,14 @@}],"nullable": true+ },+ "feature_metadata": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MerchantConnectorAccountFeatureMetadata"+ }+ ],+ "nullable": true}},"additionalProperties": false@@ -18725,6 +18763,38 @@"requeue"]},+ "RevenueRecoveryMetadata": {+ "type": "object",+ "description": "Revenue recovery metadata for merchant connector account",+ "required": [+ "max_retry_count",+ "billing_connector_retry_threshold",+ "billing_account_reference"+ ],+ "properties": {+ "max_retry_count": {+ "type": "integer",+ "format": "int32",+ "description": "The maximum number of retries allowed for an invoice. This limit is set by the merchant for each `billing connector`. Once this limit is reached, no further retries will be attempted.",+ "example": "15",+ "minimum": 0+ },+ "billing_connector_retry_threshold": {+ "type": "integer",+ "format": "int32",+ "description": "Maximum number of `billing connector` retries before revenue recovery can start executing retries.",+ "example": "10",+ "minimum": 0+ },+ "billing_account_reference": {+ "type": "integer",+ "format": "int32",+ "description": "Billing account reference id is payment gateway id at billing connector end.\nMerchants need to provide a mapping between these merchant connector account and the corresponding account reference IDs for each `billing connector`.",+ "example": "{ \"mca_vDSg5z6AxnisHq5dbJ6g\": \"stripe_123\", \"mca_vDSg5z6AumisHqh4x5m1\": \"adyen_123\" }",+ "minimum": 0+ }+ }+ },"RevokeApiKeyResponse": {"type": "object","description": "The response body for revoking an API Key.",diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex e47f7826d5..c131243394 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -732,6 +732,10 @@ pub struct MerchantConnectorCreate {/// The connector_wallets_details is used to store wallet details such as certificates and wallet credentials#[schema(value_type = Option<ConnectorWalletDetails>)]pub connector_wallets_details: Option<ConnectorWalletDetails>,++ /// Additional data that might be required by hyperswitch, to enable some specific features.+ #[schema(value_type = Option<MerchantConnectorAccountFeatureMetadata>)]+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v2")]@@ -906,6 +910,28 @@ pub enum AdditionalMerchantData {OpenBankingRecipientData(MerchantRecipientData),}+#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]+/// Feature metadata for merchant connector account+pub struct MerchantConnectorAccountFeatureMetadata {+ /// Revenue recovery metadata for merchant connector account+ pub revenue_recovery: Option<RevenueRecoveryMetadata>,+}++#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]+/// Revenue recovery metadata for merchant connector account+pub struct RevenueRecoveryMetadata {+ /// The maximum number of retries allowed for an invoice. This limit is set by the merchant for each `billing connector`. Once this limit is reached, no further retries will be attempted.+ #[schema(value_type = u16, example = "15")]+ pub max_retry_count: u16,+ /// Maximum number of `billing connector` retries before revenue recovery can start executing retries.+ #[schema(value_type = u16, example = "10")]+ pub billing_connector_retry_threshold: u16,+ /// Billing account reference id is payment gateway id at billing connector end.+ /// Merchants need to provide a mapping between these merchant connector account and the corresponding account reference IDs for each `billing connector`.+ #[schema(value_type = u16, example = r#"{ "mca_vDSg5z6AxnisHq5dbJ6g": "stripe_123", "mca_vDSg5z6AumisHqh4x5m1": "adyen_123" }"#)]+ pub billing_account_reference: HashMap<id_type::MerchantConnectorAccountId, String>,+}+#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]#[serde(rename_all = "snake_case")]pub enum MerchantAccountData {@@ -1070,6 +1096,10 @@ pub struct MerchantConnectorResponse {/// The connector_wallets_details is used to store wallet details such as certificates and wallet credentials#[schema(value_type = Option<ConnectorWalletDetails>)]pub connector_wallets_details: Option<ConnectorWalletDetails>,++ /// Additional data that might be required by hyperswitch, to enable some specific features.+ #[schema(value_type = Option<MerchantConnectorAccountFeatureMetadata>)]+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v2")]@@ -1532,6 +1562,10 @@ pub struct MerchantConnectorUpdate {/// The connector_wallets_details is used to store wallet details such as certificates and wallet credentialspub connector_wallets_details: Option<ConnectorWalletDetails>,++ /// Additional data that might be required by hyperswitch, to enable some specific features.+ #[schema(value_type = Option<MerchantConnectorAccountFeatureMetadata>)]+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v2")]diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rsindex e536648a6d..01853cb7aa 100644--- a/crates/diesel_models/src/merchant_connector_account.rs+++ b/crates/diesel_models/src/merchant_connector_account.rs@@ -1,13 +1,17 @@+#[cfg(feature = "v2")]+use std::collections::HashMap;use std::fmt::Debug;use common_utils::{encryption::Encryption, id_type, pii};+#[cfg(feature = "v2")]+use diesel::{sql_types::Jsonb, AsExpression};use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};use crate::enums as storage_enums;#[cfg(feature = "v1")]use crate::schema::merchant_connector_account;#[cfg(feature = "v2")]-use crate::schema_v2::merchant_connector_account;+use crate::{enums, schema_v2::merchant_connector_account, types};#[cfg(feature = "v1")]#[derive(@@ -95,6 +99,7 @@ pub struct MerchantConnectorAccount {pub connector_wallets_details: Option<Encryption>,pub version: common_enums::ApiVersion,pub id: id_type::MerchantConnectorAccountId,+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v2")]@@ -164,6 +169,7 @@ pub struct MerchantConnectorAccountNew {pub connector_wallets_details: Option<Encryption>,pub id: id_type::MerchantConnectorAccountId,pub version: common_enums::ApiVersion,+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v1")]@@ -213,6 +219,7 @@ pub struct MerchantConnectorAccountUpdateInternal {pub status: Option<storage_enums::ConnectorStatus>,pub connector_wallets_details: Option<Encryption>,pub additional_merchant_data: Option<Encryption>,+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v1")]@@ -260,8 +267,36 @@ impl MerchantConnectorAccountUpdateInternal {modified_at: self.modified_at.unwrap_or(source.modified_at),pm_auth_config: self.pm_auth_config,status: self.status.unwrap_or(source.status),+ feature_metadata: self.feature_metadata,..source}}}++#[cfg(feature = "v2")]+#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, AsExpression)]+#[diesel(sql_type = Jsonb)]+pub struct MerchantConnectorAccountFeatureMetadata {+ pub revenue_recovery: Option<RevenueRecoveryMetadata>,+}++#[cfg(feature = "v2")]+common_utils::impl_to_sql_from_sql_json!(MerchantConnectorAccountFeatureMetadata);++#[cfg(feature = "v2")]+#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]+pub struct RevenueRecoveryMetadata {+ /// The maximum number of retries allowed for an invoice. This limit is set by the merchant for each `billing connector`.Once this limit is reached, no further retries will be attempted.+ pub max_retry_count: u16,+ /// Maximum number of `billing connector` retries before revenue recovery can start executing retries.+ pub billing_connector_retry_threshold: u16,+ /// Billing account reference id is payment gateway id at billing connector end.+ /// Merchants need to provide a mapping between these merchant connector account and the corresponding+ /// account reference IDs for each `billing connector`.+ pub billing_account_reference: BillingAccountReference,+}++#[cfg(feature = "v2")]+#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]+pub struct BillingAccountReference(pub HashMap<id_type::MerchantConnectorAccountId, String>);diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 59a265e25f..d17d4f8478 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -763,6 +763,7 @@ diesel::table! {version -> ApiVersion,#[max_length = 64]id -> Varchar,+ feature_metadata -> Nullable<Jsonb>,}}diff --git a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs b/crates/hyperswitch_domain_models/src/merchant_connector_account.rsindex cd85d56b72..9208bb486f 100644--- a/crates/hyperswitch_domain_models/src/merchant_connector_account.rs+++ b/crates/hyperswitch_domain_models/src/merchant_connector_account.rs@@ -1,3 +1,8 @@+#[cfg(feature = "v2")]+use std::collections::HashMap;++#[cfg(feature = "v2")]+use common_utils::transformers::ForeignTryFrom;use common_utils::{crypto::Encryptable,date_time,@@ -7,6 +12,12 @@ use common_utils::{id_type, pii, type_name,types::keymanager::{Identifier, KeyManagerState, ToEncryptable},};+#[cfg(feature = "v2")]+use diesel_models::merchant_connector_account::{+ BillingAccountReference as DieselBillingAccountReference,+ MerchantConnectorAccountFeatureMetadata as DieselMerchantConnectorAccountFeatureMetadata,+ RevenueRecoveryMetadata as DieselRevenueRecoveryMetadata,+};use diesel_models::{enums, merchant_connector_account::MerchantConnectorAccountUpdateInternal};use error_stack::ResultExt;use masking::{PeekInterface, Secret};@@ -14,6 +25,8 @@ use rustc_hash::FxHashMap;use serde_json::Value;use super::behaviour;+#[cfg(feature = "v2")]+use crate::errors::{self, api_error_response};use crate::{mandates::CommonMandateReference,router_data,@@ -102,6 +115,7 @@ pub struct MerchantConnectorAccount {#[encrypt]pub additional_merchant_data: Option<Encryptable<Secret<Value>>>,pub version: common_enums::ApiVersion,+ pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,}#[cfg(feature = "v2")]@@ -149,6 +163,63 @@ pub struct PaymentMethodsEnabledForConnector {pub connector: common_enums::connector_enums::Connector,}+#[cfg(feature = "v2")]+#[derive(Debug, Clone)]+pub struct MerchantConnectorAccountFeatureMetadata {+ pub revenue_recovery: Option<RevenueRecoveryMetadata>,+}++#[cfg(feature = "v2")]+#[derive(Debug, Clone)]+pub struct RevenueRecoveryMetadata {+ pub max_retry_count: u16,+ pub billing_connector_retry_threshold: u16,+ pub mca_reference: AccountReferenceMap,+}++#[cfg(feature = "v2")]+#[derive(Debug, Clone)]+pub struct AccountReferenceMap {+ pub recovery_to_billing: HashMap<id_type::MerchantConnectorAccountId, String>,+ pub billing_to_recovery: HashMap<String, id_type::MerchantConnectorAccountId>,+}++#[cfg(feature = "v2")]+impl AccountReferenceMap {+ pub fn new(+ hash_map: HashMap<id_type::MerchantConnectorAccountId, String>,+ ) -> Result<Self, api_error_response::ApiErrorResponse> {+ Self::validate(&hash_map)?;++ let recovery_to_billing = hash_map.clone();+ let mut billing_to_recovery = HashMap::new();++ for (key, value) in &hash_map {+ billing_to_recovery.insert(value.clone(), key.clone());+ }++ Ok(Self {+ recovery_to_billing,+ billing_to_recovery,+ })+ }++ fn validate(+ hash_map: &HashMap<id_type::MerchantConnectorAccountId, String>,+ ) -> Result<(), api_error_response::ApiErrorResponse> {+ let mut seen_values = std::collections::HashSet::new(); // To check uniqueness of values++ for value in hash_map.values() {+ if !seen_values.insert(value.clone()) {+ return Err(api_error_response::ApiErrorResponse::InvalidRequestData {+ message: "Duplicate account reference IDs found in Recovery feature metadata. Each account reference ID must be unique.".to_string(),+ });+ }+ }+ Ok(())+ }+}+#[cfg(feature = "v2")]/// Holds the payment methods enabled for a connectorpub struct FlattenedPaymentMethodsEnabled {@@ -234,13 +305,14 @@ pub enum MerchantConnectorAccountUpdate {payment_methods_enabled: Option<Vec<common_types::payment_methods::PaymentMethodsEnabled>>,metadata: Option<pii::SecretSerdeValue>,frm_configs: Option<Vec<pii::SecretSerdeValue>>,- connector_webhook_details: Option<pii::SecretSerdeValue>,+ connector_webhook_details: Box<Option<pii::SecretSerdeValue>>,applepay_verified_domains: Option<Vec<String>>,pm_auth_config: Box<Option<pii::SecretSerdeValue>>,connector_label: Option<String>,status: Option<enums::ConnectorStatus>,connector_wallets_details: Box<Option<Encryptable<pii::SecretSerdeValue>>>,additional_merchant_data: Box<Option<Encryptable<pii::SecretSerdeValue>>>,+ feature_metadata: Box<Option<MerchantConnectorAccountFeatureMetadata>>,},ConnectorWalletDetailsUpdate {connector_wallets_details: Encryptable<pii::SecretSerdeValue>,@@ -410,6 +482,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {connector_wallets_details: self.connector_wallets_details.map(Encryption::from),additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),version: self.version,+ feature_metadata: self.feature_metadata.map(From::from),},)}@@ -468,6 +541,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {connector_wallets_details: decrypted_data.connector_wallets_details,additional_merchant_data: decrypted_data.additional_merchant_data,version: other.version,+ feature_metadata: other.feature_metadata.map(From::from),})}@@ -494,6 +568,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {connector_wallets_details: self.connector_wallets_details.map(Encryption::from),additional_merchant_data: self.additional_merchant_data.map(|data| data.into()),version: self.version,+ feature_metadata: self.feature_metadata.map(From::from),})}}@@ -583,6 +658,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateIntestatus,connector_wallets_details,additional_merchant_data,+ feature_metadata,} => Self {connector_type,connector_account_details: connector_account_details.map(Encryption::from),@@ -591,13 +667,14 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateIntemetadata,frm_config: frm_configs,modified_at: Some(date_time::now()),- connector_webhook_details,+ connector_webhook_details: *connector_webhook_details,applepay_verified_domains,pm_auth_config: *pm_auth_config,connector_label,status,connector_wallets_details: connector_wallets_details.map(Encryption::from),additional_merchant_data: additional_merchant_data.map(Encryption::from),+ feature_metadata: feature_metadata.map(From::from),},MerchantConnectorAccountUpdate::ConnectorWalletDetailsUpdate {connector_wallets_details,@@ -616,6 +693,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateIntepm_auth_config: None,status: None,additional_merchant_data: None,+ feature_metadata: None,},}}@@ -680,3 +758,46 @@ common_utils::create_list_wrapper!(}});++#[cfg(feature = "v2")]+impl From<MerchantConnectorAccountFeatureMetadata>+ for DieselMerchantConnectorAccountFeatureMetadata+{+ fn from(feature_metadata: MerchantConnectorAccountFeatureMetadata) -> Self {+ let revenue_recovery = feature_metadata.revenue_recovery.map(|recovery_metadata| {+ DieselRevenueRecoveryMetadata {+ max_retry_count: recovery_metadata.max_retry_count,+ billing_connector_retry_threshold: recovery_metadata+ .billing_connector_retry_threshold,+ billing_account_reference: DieselBillingAccountReference(+ recovery_metadata.mca_reference.recovery_to_billing,+ ),+ }+ });+ Self { revenue_recovery }+ }+}++#[cfg(feature = "v2")]+impl From<DieselMerchantConnectorAccountFeatureMetadata>+ for MerchantConnectorAccountFeatureMetadata+{+ fn from(feature_metadata: DieselMerchantConnectorAccountFeatureMetadata) -> Self {+ let revenue_recovery = feature_metadata.revenue_recovery.map(|recovery_metadata| {+ let mut billing_to_recovery = HashMap::new();+ for (key, value) in &recovery_metadata.billing_account_reference.0 {+ billing_to_recovery.insert(value.to_string(), key.clone());+ }+ RevenueRecoveryMetadata {+ max_retry_count: recovery_metadata.max_retry_count,+ billing_connector_retry_threshold: recovery_metadata+ .billing_connector_retry_threshold,+ mca_reference: AccountReferenceMap {+ recovery_to_billing: recovery_metadata.billing_account_reference.0,+ billing_to_recovery,+ },+ }+ });+ Self { revenue_recovery }+ }+}diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex 0da00cbfd8..f2b692c27a 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -188,6 +188,8 @@ Never share your secret api keys. Keep them guarded and secure.api_models::admin::BusinessGenericLinkConfig,api_models::admin::BusinessCollectLinkConfig,api_models::admin::BusinessPayoutLinkConfig,+ api_models::admin::MerchantConnectorAccountFeatureMetadata,+ api_models::admin::RevenueRecoveryMetadata,api_models::customers::CustomerRequest,api_models::customers::CustomerUpdateRequest,api_models::customers::CustomerDeleteResponse,diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 7b4cbb282d..a75d16a730 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -2186,6 +2186,12 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnect.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed while decrypting connector account details")?;+ let feature_metadata = self+ .feature_metadata+ .as_ref()+ .map(ForeignTryFrom::foreign_try_from)+ .transpose()?;+Ok(storage::MerchantConnectorAccountUpdate::Update {connector_type: Some(self.connector_type),connector_label: self.connector_label.clone(),@@ -2195,18 +2201,21 @@ impl MerchantConnectorAccountUpdateBridge for api_models::admin::MerchantConnectmetadata: self.metadata,frm_configs,connector_webhook_details: match &self.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,+ Some(connector_webhook_details) => Box::new(+ connector_webhook_details+ .encode_to_value()+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .map(Some)?+ .map(Secret::new),+ ),+ None => Box::new(None),},applepay_verified_domains: None,pm_auth_config: Box::new(self.pm_auth_config),status: Some(connector_status),additional_merchant_data: Box::new(encrypted_data.additional_merchant_data),connector_wallets_details: Box::new(encrypted_data.connector_wallets_details),+ feature_metadata: Box::new(feature_metadata),})}}@@ -2503,6 +2512,11 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed while decrypting connector account details")?;+ let feature_metadata = self+ .feature_metadata+ .as_ref()+ .map(ForeignTryFrom::foreign_try_from)+ .transpose()?;Ok(domain::MerchantConnectorAccount {merchant_id: business_profile.merchant_id.clone(),connector_type: self.connector_type,@@ -2534,6 +2548,7 @@ impl MerchantConnectorAccountCreateBridge for api::MerchantConnectorCreate {connector_wallets_details: encrypted_data.connector_wallets_details,additional_merchant_data: encrypted_data.additional_merchant_data,version: hyperswitch_domain_models::consts::API_VERSION,+ feature_metadata,})}diff --git a/crates/router/src/core/connector_onboarding/paypal.rs b/crates/router/src/core/connector_onboarding/paypal.rsindex 88e1eb8061..98aef1e306 100644--- a/crates/router/src/core/connector_onboarding/paypal.rs+++ b/crates/router/src/core/connector_onboarding/paypal.rs@@ -179,6 +179,7 @@ pub async fn update_mca(merchant_id: merchant_id.clone(),additional_merchant_data: None,connector_wallets_details: None,+ feature_metadata: None,};let mca_response =admin::update_connector(state.clone(), &merchant_id, None, &connector_id, request).await?;diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rsindex a51b6c86a3..4967f08bcb 100644--- a/crates/router/src/core/verification/utils.rs+++ b/crates/router/src/core/verification/utils.rs@@ -91,13 +91,14 @@ pub async fn check_existence_and_add_domain_to_db(payment_methods_enabled: None,metadata: None,frm_configs: None,- connector_webhook_details: None,+ connector_webhook_details: Box::new(None),applepay_verified_domains: Some(already_verified_domains.clone()),pm_auth_config: Box::new(None),connector_label: None,status: None,connector_wallets_details: Box::new(None),additional_merchant_data: Box::new(None),+ feature_metadata: Box::new(None),};state.storediff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rsindex 34b23a833a..1175aa43c5 100644--- a/crates/router/src/db/merchant_connector_account.rs+++ b/crates/router/src/db/merchant_connector_account.rs@@ -1293,6 +1293,7 @@ impl MerchantConnectorAccountInterface for MockDb {connector_wallets_details: t.connector_wallets_details.map(Encryption::from),additional_merchant_data: t.additional_merchant_data.map(|data| data.into()),version: t.version,+ feature_metadata: t.feature_metadata.map(From::from),};accounts.push(account.clone());account@@ -1850,6 +1851,7 @@ mod merchant_connector_account_cache_tests {),additional_merchant_data: None,version: hyperswitch_domain_models::consts::API_VERSION,+ feature_metadata: None,};db.insert_merchant_connector_account(key_manager_state, mca.clone(), &merchant_key)diff --git a/crates/router/src/types.rs b/crates/router/src/types.rsindex 4ad2bd4998..a5bdef9572 100644--- a/crates/router/src/types.rs+++ b/crates/router/src/types.rs@@ -21,7 +21,11 @@ use std::marker::PhantomData;pub use api_models::{enums::Connector, mandates};#[cfg(feature = "payouts")]pub use api_models::{enums::PayoutConnectors, payouts as payout_types};+#[cfg(feature = "v2")]+use common_utils::errors::CustomResult;pub use common_utils::{pii, pii::Email, request::RequestContent, types::MinorUnit};+#[cfg(feature = "v2")]+use error_stack::ResultExt;#[cfg(feature = "frm")]pub use hyperswitch_domain_models::router_data_v2::FrmFlowData;use hyperswitch_domain_models::router_flow_types::{@@ -1031,3 +1035,54 @@ impl<F1, F2>}}}++#[cfg(feature = "v2")]+impl ForeignFrom<&domain::MerchantConnectorAccountFeatureMetadata>+ for api_models::admin::MerchantConnectorAccountFeatureMetadata+{+ fn foreign_from(item: &domain::MerchantConnectorAccountFeatureMetadata) -> Self {+ let revenue_recovery = item+ .revenue_recovery+ .as_ref()+ .map(+ |revenue_recovery_metadata| api_models::admin::RevenueRecoveryMetadata {+ max_retry_count: revenue_recovery_metadata.max_retry_count,+ billing_connector_retry_threshold: revenue_recovery_metadata+ .billing_connector_retry_threshold,+ billing_account_reference: revenue_recovery_metadata+ .mca_reference+ .recovery_to_billing+ .clone(),+ },+ );+ Self { revenue_recovery }+ }+}++#[cfg(feature = "v2")]+impl ForeignTryFrom<&api_models::admin::MerchantConnectorAccountFeatureMetadata>+ for domain::MerchantConnectorAccountFeatureMetadata+{+ type Error = errors::ApiErrorResponse;+ fn foreign_try_from(+ feature_metadata: &api_models::admin::MerchantConnectorAccountFeatureMetadata,+ ) -> Result<Self, Self::Error> {+ let revenue_recovery = feature_metadata+ .revenue_recovery+ .as_ref()+ .map(|revenue_recovery_metadata| {+ domain::AccountReferenceMap::new(+ revenue_recovery_metadata.billing_account_reference.clone(),+ )+ .map(|mca_reference| domain::RevenueRecoveryMetadata {+ max_retry_count: revenue_recovery_metadata.max_retry_count,+ billing_connector_retry_threshold: revenue_recovery_metadata+ .billing_connector_retry_threshold,+ mca_reference,+ })+ })+ .transpose()?;++ Ok(Self { revenue_recovery })+ }+}diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rsindex 3e81d939c1..a945f8ebfb 100644--- a/crates/router/src/types/transformers.rs+++ b/crates/router/src/types/transformers.rs@@ -1293,6 +1293,10 @@ impl ForeignTryFrom<domain::MerchantConnectorAccount>.attach_printable("Failed to encode ConnectorAuthType")?,);+ let feature_metadata = item.feature_metadata.as_ref().map(|metadata| {+ api_models::admin::MerchantConnectorAccountFeatureMetadata::foreign_from(metadata)+ });+let response = Self {id: item.get_id(),connector_type: item.connector_type,@@ -1343,6 +1347,7 @@ impl ForeignTryFrom<domain::MerchantConnectorAccount>.change_context(errors::ApiErrorResponse::InternalServerError)}).transpose()?,+ feature_metadata,};Ok(response)}diff --git a/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/down.sql b/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/down.sqlnew file mode 100644index 0000000000..2e343c15ad--- /dev/null+++ b/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/down.sql@@ -0,0 +1,2 @@+ALTER TABLE merchant_connector_account+DROP COLUMN IF EXISTS feature_metadata;\ No newline at end of filediff --git a/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/up.sql b/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/up.sqlnew file mode 100644index 0000000000..24ceb8bd42--- /dev/null+++ b/v2_migrations/2025-01-29-103844_add_feature_metadata_in_merchant_connector_account/up.sql@@ -0,0 +1,2 @@+ALTER TABLE merchant_connector_account+ADD COLUMN feature_metadata JSONB;\ No newline at end of file