refactor(router): add feature_metadata for merchant_connector_account create v2 flow (#7144)

Co-authored-by: Chikke Srujan <chikke.srujan@Chikke-Srujan-N7WRTY72X7.local>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
chikke srujan
2025-02-10 16:51:07 +05:30
committed by GitHub
parent 7b015c5de0
commit 647e163117
14 changed files with 356 additions and 10 deletions

View File

@ -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::MerchantConnect
metadata: 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,
})
}

View File

@ -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?;

View File

@ -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
.store

View File

@ -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)

View File

@ -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 })
}
}

View File

@ -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)
}