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(storage_impl): Move Conversion impl for merchant_account to storage_impl crate (#11808)
Anurag Thakuraa58b428f0d2
diff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rsindex d3e6559a81..56d0c6e5ce 100644--- a/crates/hyperswitch_domain_models/src/merchant_account.rs+++ b/crates/hyperswitch_domain_models/src/merchant_account.rs@@ -1,24 +1,14 @@use common_utils::{crypto::{OptionalEncryptableName, OptionalEncryptableValue},- date_time,- encryption::Encryption,- errors::{CustomResult, ValidationError},+ errors::CustomResult,ext_traits::ValueExt,- pii, type_name,- types::keymanager::{self},+ pii,};-use diesel_models::{- enums::MerchantStorageScheme, merchant_account::MerchantAccountUpdateInternal,-};-use error_stack::ResultExt;+use diesel_models::enums::MerchantStorageScheme;use hyperswitch_masking::{PeekInterface, Secret};use router_env::logger;-use crate::{- behaviour::Conversion,- merchant_key_store,- type_encryption::{crypto_operation, AsyncLift, CryptoOperation},-};+use crate::merchant_key_store;#[cfg(feature = "v1")]#[derive(Clone, Debug, serde::Serialize)]@@ -335,584 +325,6 @@ pub enum MerchantAccountUpdate {ModifiedAtUpdate,}-#[cfg(feature = "v1")]-impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {- fn from(merchant_account_update: MerchantAccountUpdate) -> Self {- let now = date_time::now();-- match merchant_account_update {- MerchantAccountUpdate::Update {- merchant_name,- merchant_details,- webhook_details,- return_url,- routing_algorithm,- sub_merchants_enabled,- parent_merchant_id,- enable_payment_response_hash,- payment_response_hash_key,- redirect_to_merchant_with_http_post,- publishable_key,- locker_id,- metadata,- primary_business_details,- intent_fulfillment_time,- frm_routing_algorithm,- payout_routing_algorithm,- default_profile,- payment_link_config,- pm_collect_link_config,- network_tokenization_credentials,- offer_engine_config,- } => Self {- merchant_name: merchant_name.map(Encryption::from),- merchant_details: merchant_details.map(Encryption::from),- frm_routing_algorithm,- webhook_details,- routing_algorithm,- sub_merchants_enabled,- parent_merchant_id,- return_url,- enable_payment_response_hash,- payment_response_hash_key,- redirect_to_merchant_with_http_post,- publishable_key,- locker_id,- metadata,- primary_business_details,- modified_at: now,- intent_fulfillment_time,- payout_routing_algorithm,- default_profile,- payment_link_config,- pm_collect_link_config,- storage_scheme: None,- organization_id: None,- is_recon_enabled: None,- recon_status: None,- is_platform_account: None,- product_type: None,- network_tokenization_credentials: network_tokenization_credentials- .map(Encryption::from),- offer_engine_config: offer_engine_config.map(Encryption::from),- },- MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self {- storage_scheme: Some(storage_scheme),- modified_at: now,- merchant_name: None,- merchant_details: None,- return_url: None,- webhook_details: None,- sub_merchants_enabled: None,- parent_merchant_id: None,- enable_payment_response_hash: None,- payment_response_hash_key: None,- redirect_to_merchant_with_http_post: None,- publishable_key: None,- locker_id: None,- metadata: None,- routing_algorithm: None,- primary_business_details: None,- intent_fulfillment_time: None,- frm_routing_algorithm: None,- payout_routing_algorithm: None,- organization_id: None,- is_recon_enabled: None,- default_profile: None,- recon_status: None,- payment_link_config: None,- pm_collect_link_config: None,- is_platform_account: None,- product_type: None,- network_tokenization_credentials: None,- offer_engine_config: None,- },- MerchantAccountUpdate::ReconUpdate { recon_status } => Self {- recon_status: Some(recon_status),- modified_at: now,- merchant_name: None,- merchant_details: None,- return_url: None,- webhook_details: None,- sub_merchants_enabled: None,- parent_merchant_id: None,- enable_payment_response_hash: None,- payment_response_hash_key: None,- redirect_to_merchant_with_http_post: None,- publishable_key: None,- storage_scheme: None,- locker_id: None,- metadata: None,- routing_algorithm: None,- primary_business_details: None,- intent_fulfillment_time: None,- frm_routing_algorithm: None,- payout_routing_algorithm: None,- organization_id: None,- is_recon_enabled: None,- default_profile: None,- payment_link_config: None,- pm_collect_link_config: None,- is_platform_account: None,- product_type: None,- network_tokenization_credentials: None,- offer_engine_config: None,- },- MerchantAccountUpdate::UnsetDefaultProfile => Self {- default_profile: Some(None),- modified_at: now,- merchant_name: None,- merchant_details: None,- return_url: None,- webhook_details: None,- sub_merchants_enabled: None,- parent_merchant_id: None,- enable_payment_response_hash: None,- payment_response_hash_key: None,- redirect_to_merchant_with_http_post: None,- publishable_key: None,- storage_scheme: None,- locker_id: None,- metadata: None,- routing_algorithm: None,- primary_business_details: None,- intent_fulfillment_time: None,- frm_routing_algorithm: None,- payout_routing_algorithm: None,- organization_id: None,- is_recon_enabled: None,- recon_status: None,- payment_link_config: None,- pm_collect_link_config: None,- is_platform_account: None,- product_type: None,- network_tokenization_credentials: None,- offer_engine_config: None,- },- MerchantAccountUpdate::ModifiedAtUpdate => Self {- modified_at: now,- merchant_name: None,- merchant_details: None,- return_url: None,- webhook_details: None,- sub_merchants_enabled: None,- parent_merchant_id: None,- enable_payment_response_hash: None,- payment_response_hash_key: None,- redirect_to_merchant_with_http_post: None,- publishable_key: None,- storage_scheme: None,- locker_id: None,- metadata: None,- routing_algorithm: None,- primary_business_details: None,- intent_fulfillment_time: None,- frm_routing_algorithm: None,- payout_routing_algorithm: None,- organization_id: None,- is_recon_enabled: None,- default_profile: None,- recon_status: None,- payment_link_config: None,- pm_collect_link_config: None,- is_platform_account: None,- product_type: None,- network_tokenization_credentials: None,- offer_engine_config: None,- },- }- }-}--#[cfg(feature = "v2")]-impl From<MerchantAccountUpdate> for MerchantAccountUpdateInternal {- fn from(merchant_account_update: MerchantAccountUpdate) -> Self {- let now = date_time::now();-- match merchant_account_update {- MerchantAccountUpdate::Update {- merchant_name,- merchant_details,- publishable_key,- metadata,- } => Self {- merchant_name: merchant_name.map(Encryption::from),- merchant_details: merchant_details.map(Encryption::from),- publishable_key,- metadata: metadata.map(|metadata| *metadata),- modified_at: now,- storage_scheme: None,- organization_id: None,- recon_status: None,- is_platform_account: None,- product_type: None,- },- MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self {- storage_scheme: Some(storage_scheme),- modified_at: now,- merchant_name: None,- merchant_details: None,- publishable_key: None,- metadata: None,- organization_id: None,- recon_status: None,- is_platform_account: None,- product_type: None,- },- MerchantAccountUpdate::ReconUpdate { recon_status } => Self {- recon_status: Some(recon_status),- modified_at: now,- merchant_name: None,- merchant_details: None,- publishable_key: None,- storage_scheme: None,- metadata: None,- organization_id: None,- is_platform_account: None,- product_type: None,- },- MerchantAccountUpdate::ModifiedAtUpdate => Self {- modified_at: now,- merchant_name: None,- merchant_details: None,- publishable_key: None,- storage_scheme: None,- metadata: None,- organization_id: None,- recon_status: None,- is_platform_account: None,- product_type: None,- },- }- }-}--#[cfg(feature = "v2")]-#[async_trait::async_trait]-impl Conversion for MerchantAccount {- type DstType = diesel_models::merchant_account::MerchantAccount;- type NewDstType = diesel_models::merchant_account::MerchantAccountNew;- async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {- let id = self.get_id().to_owned();-- let setter = diesel_models::merchant_account::MerchantAccountSetter {- id,- merchant_name: self.merchant_name.map(|name| name.into()),- merchant_details: self.merchant_details.map(|details| details.into()),- publishable_key: Some(self.publishable_key),- storage_scheme: self.storage_scheme,- metadata: self.metadata,- created_at: self.created_at,- modified_at: self.modified_at,- organization_id: self.organization_id,- recon_status: self.recon_status,- version: common_types::consts::API_VERSION,- is_platform_account: self.is_platform_account,- product_type: self.product_type,- merchant_account_type: self.merchant_account_type,- fingerprint_secret: self.fingerprint_secret,- };-- Ok(diesel_models::MerchantAccount::from(setter))- }-- async fn convert_back(- state: &keymanager::KeyManagerState,- item: Self::DstType,- key: &Secret<Vec<u8>>,- key_manager_identifier: keymanager::Identifier,- ) -> CustomResult<Self, ValidationError>- where- Self: Sized,- {- let id = item.get_id().to_owned();- let publishable_key =- item.publishable_key- .ok_or(ValidationError::MissingRequiredField {- field_name: "publishable_key".into(),- })?;-- async {- Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {- id,- merchant_name: item- .merchant_name- .async_lift(|inner| async {- crypto_operation(- state,- type_name!(Self::DstType),- CryptoOperation::DecryptOptional(inner),- key_manager_identifier.clone(),- key.peek(),- )- .await- .and_then(|val| val.try_into_optionaloperation())- })- .await?,- merchant_details: item- .merchant_details- .async_lift(|inner| async {- crypto_operation(- state,- type_name!(Self::DstType),- CryptoOperation::DecryptOptional(inner),- key_manager_identifier.clone(),- key.peek(),- )- .await- .and_then(|val| val.try_into_optionaloperation())- })- .await?,- publishable_key,- storage_scheme: item.storage_scheme,- metadata: item.metadata,- created_at: item.created_at,- modified_at: item.modified_at,- organization_id: item.organization_id,- recon_status: item.recon_status,- is_platform_account: item.is_platform_account,- version: item.version,- product_type: item.product_type,- merchant_account_type: item.merchant_account_type.unwrap_or_default(),- fingerprint_secret: item.fingerprint_secret,- })- }- .await- .change_context(ValidationError::InvalidValue {- message: "Failed while decrypting merchant data".to_string(),- })- }-- async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {- let now = date_time::now();- Ok(diesel_models::merchant_account::MerchantAccountNew {- id: self.id,- merchant_name: self.merchant_name.map(Encryption::from),- merchant_details: self.merchant_details.map(Encryption::from),- publishable_key: Some(self.publishable_key),- storage_scheme: self.storage_scheme,- metadata: self.metadata,- created_at: now,- modified_at: now,- organization_id: self.organization_id,- recon_status: self.recon_status,- version: common_types::consts::API_VERSION,- is_platform_account: self.is_platform_account,- product_type: self- .product_type- .or(Some(common_enums::MerchantProductType::Orchestration)),- merchant_account_type: self.merchant_account_type,- fingerprint_secret: self.fingerprint_secret,- })- }-}--#[cfg(feature = "v1")]-#[async_trait::async_trait]-impl Conversion for MerchantAccount {- type DstType = diesel_models::merchant_account::MerchantAccount;- type NewDstType = diesel_models::merchant_account::MerchantAccountNew;- async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {- let setter = diesel_models::merchant_account::MerchantAccountSetter {- merchant_id: self.merchant_id,- return_url: self.return_url,- enable_payment_response_hash: self.enable_payment_response_hash,- payment_response_hash_key: self.payment_response_hash_key,- redirect_to_merchant_with_http_post: self.redirect_to_merchant_with_http_post,- merchant_name: self.merchant_name.map(|name| name.into()),- merchant_details: self.merchant_details.map(|details| details.into()),- webhook_details: self.webhook_details,- sub_merchants_enabled: self.sub_merchants_enabled,- parent_merchant_id: self.parent_merchant_id,- publishable_key: Some(self.publishable_key),- storage_scheme: self.storage_scheme,- locker_id: self.locker_id,- metadata: self.metadata,- routing_algorithm: self.routing_algorithm,- primary_business_details: self.primary_business_details,- created_at: self.created_at,- modified_at: self.modified_at,- intent_fulfillment_time: self.intent_fulfillment_time,- frm_routing_algorithm: self.frm_routing_algorithm,- payout_routing_algorithm: self.payout_routing_algorithm,- organization_id: self.organization_id,- is_recon_enabled: self.is_recon_enabled,- default_profile: self.default_profile,- recon_status: self.recon_status,- payment_link_config: self.payment_link_config,- pm_collect_link_config: self.pm_collect_link_config,- version: self.version,- is_platform_account: self.is_platform_account,- product_type: self.product_type,- merchant_account_type: self.merchant_account_type,- network_tokenization_credentials: self- .network_tokenization_credentials- .map(|credentials| credentials.into()),- fingerprint_secret: self.fingerprint_secret,- offer_engine_config: self.offer_engine_config.map(|config| config.into()),- };-- Ok(diesel_models::MerchantAccount::from(setter))- }-- async fn convert_back(- state: &keymanager::KeyManagerState,- item: Self::DstType,- key: &Secret<Vec<u8>>,- key_manager_identifier: keymanager::Identifier,- ) -> CustomResult<Self, ValidationError>- where- Self: Sized,- {- let merchant_id = item.get_id().to_owned();- let publishable_key =- item.publishable_key- .ok_or(ValidationError::MissingRequiredField {- field_name: "publishable_key".into(),- })?;-- async {- Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {- merchant_id,- return_url: item.return_url,- enable_payment_response_hash: item.enable_payment_response_hash,- payment_response_hash_key: item.payment_response_hash_key,- redirect_to_merchant_with_http_post: item.redirect_to_merchant_with_http_post,- merchant_name: item- .merchant_name- .async_lift(|inner| async {- crypto_operation(- state,- type_name!(Self::DstType),- CryptoOperation::DecryptOptional(inner),- key_manager_identifier.clone(),- key.peek(),- )- .await- .and_then(|val| val.try_into_optionaloperation())- })- .await?,- merchant_details: item- .merchant_details- .async_lift(|inner| async {- crypto_operation(- state,- type_name!(Self::DstType),- CryptoOperation::DecryptOptional(inner),- key_manager_identifier.clone(),- key.peek(),- )- .await- .and_then(|val| val.try_into_optionaloperation())- })- .await?,- webhook_details: item.webhook_details,- sub_merchants_enabled: item.sub_merchants_enabled,- parent_merchant_id: item.parent_merchant_id,- publishable_key,- storage_scheme: item.storage_scheme,- locker_id: item.locker_id,- metadata: item.metadata,- routing_algorithm: item.routing_algorithm,- frm_routing_algorithm: item.frm_routing_algorithm,- primary_business_details: item.primary_business_details,- created_at: item.created_at,- modified_at: item.modified_at,- intent_fulfillment_time: item.intent_fulfillment_time,- payout_routing_algorithm: item.payout_routing_algorithm,- organization_id: item.organization_id,- is_recon_enabled: item.is_recon_enabled,- default_profile: item.default_profile,- recon_status: item.recon_status,- payment_link_config: item.payment_link_config,- pm_collect_link_config: item.pm_collect_link_config,- version: item.version,- is_platform_account: item.is_platform_account,- product_type: item.product_type,- merchant_account_type: item.merchant_account_type.unwrap_or_default(),- network_tokenization_credentials: item- .network_tokenization_credentials- .async_lift(|inner| async {- crypto_operation(- state,- type_name!(Self::DstType),- CryptoOperation::DecryptOptional(inner),- key_manager_identifier.clone(),- key.peek(),- )- .await- .and_then(|val| val.try_into_optionaloperation())- })- .await?,- fingerprint_secret: item.fingerprint_secret,- offer_engine_config: item- .offer_engine_config- .async_lift(|inner| async {- crypto_operation(- state,- type_name!(Self::DstType),- CryptoOperation::DecryptOptional(inner),- key_manager_identifier.clone(),- key.peek(),- )- .await- .and_then(|val| val.try_into_optionaloperation())- })- .await?,- })- }- .await- .change_context(ValidationError::InvalidValue {- message: "Failed while decrypting merchant data".to_string(),- })- }-- async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {- let now = date_time::now();- Ok(diesel_models::merchant_account::MerchantAccountNew {- id: Some(self.merchant_id.clone()),- merchant_id: self.merchant_id,- merchant_name: self.merchant_name.map(Encryption::from),- merchant_details: self.merchant_details.map(Encryption::from),- return_url: self.return_url,- webhook_details: self.webhook_details,- sub_merchants_enabled: self.sub_merchants_enabled,- parent_merchant_id: self.parent_merchant_id,- enable_payment_response_hash: Some(self.enable_payment_response_hash),- payment_response_hash_key: self.payment_response_hash_key,- redirect_to_merchant_with_http_post: Some(self.redirect_to_merchant_with_http_post),- publishable_key: Some(self.publishable_key),- storage_scheme: self.storage_scheme,- locker_id: self.locker_id,- metadata: self.metadata,- routing_algorithm: self.routing_algorithm,- primary_business_details: self.primary_business_details,- created_at: now,- modified_at: now,- intent_fulfillment_time: self.intent_fulfillment_time,- frm_routing_algorithm: self.frm_routing_algorithm,- payout_routing_algorithm: self.payout_routing_algorithm,- organization_id: self.organization_id,- is_recon_enabled: self.is_recon_enabled,- default_profile: self.default_profile,- recon_status: self.recon_status,- payment_link_config: self.payment_link_config,- pm_collect_link_config: self.pm_collect_link_config,- version: common_types::consts::API_VERSION,- is_platform_account: self.is_platform_account,- product_type: self- .product_type- .or(Some(common_enums::MerchantProductType::Orchestration)),- merchant_account_type: self.merchant_account_type,- network_tokenization_credentials: self- .network_tokenization_credentials- .map(|credentials| credentials.into()),- fingerprint_secret: self.fingerprint_secret,- offer_engine_config: self.offer_engine_config.map(|config| config.into()),- })- }-}-impl MerchantAccount {pub fn get_compatible_connector(&self) -> Option<api_models::enums::Connector> {let metadata: Option<api_models::admin::MerchantAccountMetadata> =@@ -927,13 +339,7 @@ impl MerchantAccount {}#[async_trait::async_trait]-pub trait MerchantAccountInterface-where- MerchantAccount: Conversion<- DstType = diesel_models::merchant_account::MerchantAccount,- NewDstType = diesel_models::merchant_account::MerchantAccountNew,- >,-{+pub trait MerchantAccountInterface {type Error;async fn insert_merchant(&self,diff --git a/crates/storage_impl/src/merchant_account.rs b/crates/storage_impl/src/merchant_account.rsindex 296c2a8a25..602ca00869 100644--- a/crates/storage_impl/src/merchant_account.rs+++ b/crates/storage_impl/src/merchant_account.rs@@ -5,7 +5,6 @@ use common_utils::ext_traits::AsyncExt;use diesel_models::merchant_account as storage;use error_stack::{report, ResultExt};use hyperswitch_domain_models::{- behaviour::{Conversion, ReverseConversion},master_key::MasterKeyInterface,merchant_account::{self as domain, MerchantAccountInterface},merchant_key_store::{MerchantKeyStore, MerchantKeyStoreInterface},@@ -21,6 +20,7 @@ use crate::redis::{#[cfg(feature = "accounts_cache")]use crate::RedisConnInterface;use crate::{+ behaviour::{Conversion, ForeignFrom, ForeignInto, ReverseConversion},kv_router_store,store::MerchantAccountUpdateInternal,utils::{pg_accounts_connection_read, pg_accounts_connection_write},@@ -233,7 +233,7 @@ impl<T: DatabaseStore> MerchantAccountInterface for RouterStore<T> {let updated_merchant_account = Conversion::convert(this).await.change_context(StorageError::EncryptionError)?- .update(&conn, merchant_account.into())+ .update(&conn, merchant_account.foreign_into()).await.map_err(|error| report!(StorageError::from(error)))?;@@ -263,7 +263,7 @@ impl<T: DatabaseStore> MerchantAccountInterface for RouterStore<T> {let updated_merchant_account = storage::MerchantAccount::update_with_specific_fields(&conn,merchant_id,- merchant_account.into(),+ merchant_account.foreign_into(),).await.map_err(|error| report!(StorageError::from(error)))?;@@ -505,7 +505,7 @@ impl<T: DatabaseStore> MerchantAccountInterface for RouterStore<T> {let db_func = || async {storage::MerchantAccount::update_all_merchant_accounts(&conn,- MerchantAccountUpdateInternal::from(merchant_account),+ MerchantAccountUpdateInternal::foreign_from(merchant_account),).await.map_err(|error| report!(StorageError::from(error)))@@ -591,7 +591,7 @@ impl MerchantAccountInterface for MockDb {.iter_mut().find(|account| account.get_id() == merchant_account.get_id()).async_map(|account| async {- let update = MerchantAccountUpdateInternal::from(merchant_account_update)+ let update = MerchantAccountUpdateInternal::foreign_from(merchant_account_update).apply_changeset(Conversion::convert(merchant_account).await@@ -627,7 +627,7 @@ impl MerchantAccountInterface for MockDb {.iter_mut().find(|account| account.get_id() == merchant_id).async_map(|account| async {- let update = MerchantAccountUpdateInternal::from(merchant_account_update)+ let update = MerchantAccountUpdateInternal::foreign_from(merchant_account_update).apply_changeset(account.clone());*account = update.clone();update@@ -689,8 +689,9 @@ impl MerchantAccountInterface for MockDb {) -> CustomResult<usize, StorageError> {let mut accounts = self.merchant_accounts.lock().await;Ok(accounts.iter_mut().fold(0, |acc, account| {- let update = MerchantAccountUpdateInternal::from(merchant_account_update.clone())- .apply_changeset(account.clone());+ let update =+ MerchantAccountUpdateInternal::foreign_from(merchant_account_update.clone())+ .apply_changeset(account.clone());*account = update;acc + 1}))@@ -861,3 +862,597 @@ async fn publish_and_redact_all_merchant_account_cache(cache::redact_from_redis_and_publish(cache, cache_keys).await?;Ok(())}++use common_utils::{+ date_time,+ encryption::Encryption,+ errors::ValidationError,+ type_name,+ types::keymanager::{self},+};+use hyperswitch_domain_models::type_encryption::{crypto_operation, AsyncLift, CryptoOperation};+use hyperswitch_masking::Secret;++#[cfg(feature = "v1")]+impl ForeignFrom<domain::MerchantAccountUpdate> for MerchantAccountUpdateInternal {+ fn foreign_from(merchant_account_update: domain::MerchantAccountUpdate) -> Self {+ let now = date_time::now();++ match merchant_account_update {+ domain::MerchantAccountUpdate::Update {+ merchant_name,+ merchant_details,+ webhook_details,+ return_url,+ routing_algorithm,+ sub_merchants_enabled,+ parent_merchant_id,+ enable_payment_response_hash,+ payment_response_hash_key,+ redirect_to_merchant_with_http_post,+ publishable_key,+ locker_id,+ metadata,+ primary_business_details,+ intent_fulfillment_time,+ frm_routing_algorithm,+ payout_routing_algorithm,+ default_profile,+ payment_link_config,+ pm_collect_link_config,+ network_tokenization_credentials,+ offer_engine_config,+ } => Self {+ merchant_name: merchant_name.map(Encryption::from),+ merchant_details: merchant_details.map(Encryption::from),+ frm_routing_algorithm,+ webhook_details,+ routing_algorithm,+ sub_merchants_enabled,+ parent_merchant_id,+ return_url,+ enable_payment_response_hash,+ payment_response_hash_key,+ redirect_to_merchant_with_http_post,+ publishable_key,+ locker_id,+ metadata,+ primary_business_details,+ modified_at: now,+ intent_fulfillment_time,+ payout_routing_algorithm,+ default_profile,+ payment_link_config,+ pm_collect_link_config,+ storage_scheme: None,+ organization_id: None,+ is_recon_enabled: None,+ recon_status: None,+ is_platform_account: None,+ product_type: None,+ network_tokenization_credentials: network_tokenization_credentials+ .map(Encryption::from),+ offer_engine_config: offer_engine_config.map(Encryption::from),+ },+ domain::MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self {+ storage_scheme: Some(storage_scheme),+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ return_url: None,+ webhook_details: None,+ sub_merchants_enabled: None,+ parent_merchant_id: None,+ enable_payment_response_hash: None,+ payment_response_hash_key: None,+ redirect_to_merchant_with_http_post: None,+ publishable_key: None,+ locker_id: None,+ metadata: None,+ routing_algorithm: None,+ primary_business_details: None,+ intent_fulfillment_time: None,+ frm_routing_algorithm: None,+ payout_routing_algorithm: None,+ organization_id: None,+ is_recon_enabled: None,+ default_profile: None,+ recon_status: None,+ payment_link_config: None,+ pm_collect_link_config: None,+ is_platform_account: None,+ product_type: None,+ network_tokenization_credentials: None,+ offer_engine_config: None,+ },+ domain::MerchantAccountUpdate::ReconUpdate { recon_status } => Self {+ recon_status: Some(recon_status),+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ return_url: None,+ webhook_details: None,+ sub_merchants_enabled: None,+ parent_merchant_id: None,+ enable_payment_response_hash: None,+ payment_response_hash_key: None,+ redirect_to_merchant_with_http_post: None,+ publishable_key: None,+ storage_scheme: None,+ locker_id: None,+ metadata: None,+ routing_algorithm: None,+ primary_business_details: None,+ intent_fulfillment_time: None,+ frm_routing_algorithm: None,+ payout_routing_algorithm: None,+ organization_id: None,+ is_recon_enabled: None,+ default_profile: None,+ payment_link_config: None,+ pm_collect_link_config: None,+ is_platform_account: None,+ product_type: None,+ network_tokenization_credentials: None,+ offer_engine_config: None,+ },+ domain::MerchantAccountUpdate::UnsetDefaultProfile => Self {+ default_profile: Some(None),+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ return_url: None,+ webhook_details: None,+ sub_merchants_enabled: None,+ parent_merchant_id: None,+ enable_payment_response_hash: None,+ payment_response_hash_key: None,+ redirect_to_merchant_with_http_post: None,+ publishable_key: None,+ storage_scheme: None,+ locker_id: None,+ metadata: None,+ routing_algorithm: None,+ primary_business_details: None,+ intent_fulfillment_time: None,+ frm_routing_algorithm: None,+ payout_routing_algorithm: None,+ organization_id: None,+ is_recon_enabled: None,+ recon_status: None,+ payment_link_config: None,+ pm_collect_link_config: None,+ is_platform_account: None,+ product_type: None,+ network_tokenization_credentials: None,+ offer_engine_config: None,+ },+ domain::MerchantAccountUpdate::ModifiedAtUpdate => Self {+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ return_url: None,+ webhook_details: None,+ sub_merchants_enabled: None,+ parent_merchant_id: None,+ enable_payment_response_hash: None,+ payment_response_hash_key: None,+ redirect_to_merchant_with_http_post: None,+ publishable_key: None,+ storage_scheme: None,+ locker_id: None,+ metadata: None,+ routing_algorithm: None,+ primary_business_details: None,+ intent_fulfillment_time: None,+ frm_routing_algorithm: None,+ payout_routing_algorithm: None,+ organization_id: None,+ is_recon_enabled: None,+ default_profile: None,+ recon_status: None,+ payment_link_config: None,+ pm_collect_link_config: None,+ is_platform_account: None,+ product_type: None,+ network_tokenization_credentials: None,+ offer_engine_config: None,+ },+ }+ }+}++#[cfg(feature = "v2")]+impl ForeignFrom<domain::MerchantAccountUpdate> for MerchantAccountUpdateInternal {+ fn foreign_from(merchant_account_update: domain::MerchantAccountUpdate) -> Self {+ let now = date_time::now();++ match merchant_account_update {+ domain::MerchantAccountUpdate::Update {+ merchant_name,+ merchant_details,+ publishable_key,+ metadata,+ } => Self {+ merchant_name: merchant_name.map(Encryption::from),+ merchant_details: merchant_details.map(Encryption::from),+ publishable_key,+ metadata: metadata.map(|metadata| *metadata),+ modified_at: now,+ storage_scheme: None,+ organization_id: None,+ recon_status: None,+ is_platform_account: None,+ product_type: None,+ },+ domain::MerchantAccountUpdate::StorageSchemeUpdate { storage_scheme } => Self {+ storage_scheme: Some(storage_scheme),+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ publishable_key: None,+ metadata: None,+ organization_id: None,+ recon_status: None,+ is_platform_account: None,+ product_type: None,+ },+ domain::MerchantAccountUpdate::ReconUpdate { recon_status } => Self {+ recon_status: Some(recon_status),+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ publishable_key: None,+ storage_scheme: None,+ metadata: None,+ organization_id: None,+ is_platform_account: None,+ product_type: None,+ },+ domain::MerchantAccountUpdate::ModifiedAtUpdate => Self {+ modified_at: now,+ merchant_name: None,+ merchant_details: None,+ publishable_key: None,+ storage_scheme: None,+ metadata: None,+ organization_id: None,+ recon_status: None,+ is_platform_account: None,+ product_type: None,+ },+ }+ }+}++#[cfg(feature = "v2")]+#[async_trait::async_trait]+impl Conversion for domain::MerchantAccount {+ type DstType = diesel_models::merchant_account::MerchantAccount;+ type NewDstType = diesel_models::merchant_account::MerchantAccountNew;+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {+ let id = self.get_id().to_owned();++ let setter = diesel_models::merchant_account::MerchantAccountSetter {+ id,+ merchant_name: self.merchant_name.map(|name| name.into()),+ merchant_details: self.merchant_details.map(|details| details.into()),+ publishable_key: Some(self.publishable_key),+ storage_scheme: self.storage_scheme,+ metadata: self.metadata,+ created_at: self.created_at,+ modified_at: self.modified_at,+ organization_id: self.organization_id,+ recon_status: self.recon_status,+ version: self.version, // TODO: Verify this change+ is_platform_account: self.is_platform_account,+ product_type: self.product_type,+ merchant_account_type: self.merchant_account_type,+ fingerprint_secret: self.fingerprint_secret,+ };++ Ok(diesel_models::MerchantAccount::from(setter))+ }++ async fn convert_back(+ state: &keymanager::KeyManagerState,+ item: Self::DstType,+ key: &Secret<Vec<u8>>,+ key_manager_identifier: keymanager::Identifier,+ ) -> CustomResult<Self, ValidationError>+ where+ Self: Sized,+ {+ let id = item.get_id().to_owned();+ let publishable_key =+ item.publishable_key+ .ok_or(ValidationError::MissingRequiredField {+ field_name: "publishable_key".into(),+ })?;++ async {+ Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(+ domain::MerchantAccountSetter {+ id,+ merchant_name: item+ .merchant_name+ .async_lift(|inner| async {+ crypto_operation(+ state,+ type_name!(Self::DstType),+ CryptoOperation::DecryptOptional(inner),+ key_manager_identifier.clone(),+ key.peek(),+ )+ .await+ .and_then(|val| val.try_into_optionaloperation())+ })+ .await?,+ merchant_details: item+ .merchant_details+ .async_lift(|inner| async {+ crypto_operation(+ state,+ type_name!(Self::DstType),+ CryptoOperation::DecryptOptional(inner),+ key_manager_identifier.clone(),+ key.peek(),+ )+ .await+ .and_then(|val| val.try_into_optionaloperation())+ })+ .await?,+ publishable_key,+ storage_scheme: item.storage_scheme,+ metadata: item.metadata,+ created_at: item.created_at,+ modified_at: item.modified_at,+ organization_id: item.organization_id,+ recon_status: item.recon_status,+ is_platform_account: item.is_platform_account,+ version: item.version,+ product_type: item.product_type,+ merchant_account_type: item.merchant_account_type.unwrap_or_default(),+ fingerprint_secret: item.fingerprint_secret,+ }+ .into(),+ )+ }+ .await+ .change_context(ValidationError::InvalidValue {+ message: "Failed while decrypting merchant data".to_string(),+ })+ }++ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {+ let now = date_time::now();+ Ok(diesel_models::merchant_account::MerchantAccountNew {+ id: self.get_id().to_owned(),+ merchant_name: self.merchant_name.map(Encryption::from),+ merchant_details: self.merchant_details.map(Encryption::from),+ publishable_key: Some(self.publishable_key),+ storage_scheme: self.storage_scheme,+ metadata: self.metadata,+ created_at: now,+ modified_at: now,+ organization_id: self.organization_id,+ recon_status: self.recon_status,+ version: self.version, // TODO: Verify this change+ is_platform_account: self.is_platform_account,+ product_type: self+ .product_type+ .or(Some(common_enums::MerchantProductType::Orchestration)),+ merchant_account_type: self.merchant_account_type,+ fingerprint_secret: self.fingerprint_secret,+ })+ }+}++#[cfg(feature = "v1")]+#[async_trait::async_trait]+impl Conversion for domain::MerchantAccount {+ type DstType = diesel_models::merchant_account::MerchantAccount;+ type NewDstType = diesel_models::merchant_account::MerchantAccountNew;+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {+ let setter = diesel_models::merchant_account::MerchantAccountSetter {+ merchant_id: self.get_id().to_owned(),+ return_url: self.return_url,+ enable_payment_response_hash: self.enable_payment_response_hash,+ payment_response_hash_key: self.payment_response_hash_key,+ redirect_to_merchant_with_http_post: self.redirect_to_merchant_with_http_post,+ merchant_name: self.merchant_name.map(|name| name.into()),+ merchant_details: self.merchant_details.map(|details| details.into()),+ webhook_details: self.webhook_details,+ sub_merchants_enabled: self.sub_merchants_enabled,+ parent_merchant_id: self.parent_merchant_id,+ publishable_key: Some(self.publishable_key),+ storage_scheme: self.storage_scheme,+ locker_id: self.locker_id,+ metadata: self.metadata,+ routing_algorithm: self.routing_algorithm,+ primary_business_details: self.primary_business_details,+ created_at: self.created_at,+ modified_at: self.modified_at,+ intent_fulfillment_time: self.intent_fulfillment_time,+ frm_routing_algorithm: self.frm_routing_algorithm,+ payout_routing_algorithm: self.payout_routing_algorithm,+ organization_id: self.organization_id,+ is_recon_enabled: self.is_recon_enabled,+ default_profile: self.default_profile,+ recon_status: self.recon_status,+ payment_link_config: self.payment_link_config,+ pm_collect_link_config: self.pm_collect_link_config,+ version: self.version,+ is_platform_account: self.is_platform_account,+ product_type: self.product_type,+ merchant_account_type: self.merchant_account_type,+ network_tokenization_credentials: self+ .network_tokenization_credentials+ .map(|credentials| credentials.into()),+ fingerprint_secret: self.fingerprint_secret,+ offer_engine_config: self.offer_engine_config.map(|config| config.into()),+ };++ Ok(diesel_models::MerchantAccount::from(setter))+ }++ async fn convert_back(+ state: &keymanager::KeyManagerState,+ item: Self::DstType,+ key: &Secret<Vec<u8>>,+ key_manager_identifier: keymanager::Identifier,+ ) -> CustomResult<Self, ValidationError>+ where+ Self: Sized,+ {+ let merchant_id = item.get_id().to_owned();+ let publishable_key =+ item.publishable_key+ .ok_or(ValidationError::MissingRequiredField {+ field_name: "publishable_key".into(),+ })?;++ async {+ Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(+ domain::MerchantAccountSetter {+ merchant_id,+ return_url: item.return_url,+ enable_payment_response_hash: item.enable_payment_response_hash,+ payment_response_hash_key: item.payment_response_hash_key,+ redirect_to_merchant_with_http_post: item.redirect_to_merchant_with_http_post,+ merchant_name: item+ .merchant_name+ .async_lift(|inner| async {+ crypto_operation(+ state,+ type_name!(Self::DstType),+ CryptoOperation::DecryptOptional(inner),+ key_manager_identifier.clone(),+ key.peek(),+ )+ .await+ .and_then(|val| val.try_into_optionaloperation())+ })+ .await?,+ merchant_details: item+ .merchant_details+ .async_lift(|inner| async {+ crypto_operation(+ state,+ type_name!(Self::DstType),+ CryptoOperation::DecryptOptional(inner),+ key_manager_identifier.clone(),+ key.peek(),+ )+ .await+ .and_then(|val| val.try_into_optionaloperation())+ })+ .await?,+ webhook_details: item.webhook_details,+ sub_merchants_enabled: item.sub_merchants_enabled,+ parent_merchant_id: item.parent_merchant_id,+ publishable_key,+ storage_scheme: item.storage_scheme,+ locker_id: item.locker_id,+ metadata: item.metadata,+ routing_algorithm: item.routing_algorithm,+ frm_routing_algorithm: item.frm_routing_algorithm,+ primary_business_details: item.primary_business_details,+ created_at: item.created_at,+ modified_at: item.modified_at,+ intent_fulfillment_time: item.intent_fulfillment_time,+ payout_routing_algorithm: item.payout_routing_algorithm,+ organization_id: item.organization_id,+ is_recon_enabled: item.is_recon_enabled,+ default_profile: item.default_profile,+ recon_status: item.recon_status,+ payment_link_config: item.payment_link_config,+ pm_collect_link_config: item.pm_collect_link_config,+ version: item.version,+ is_platform_account: item.is_platform_account,+ product_type: item.product_type,+ merchant_account_type: item.merchant_account_type.unwrap_or_default(),+ network_tokenization_credentials: item+ .network_tokenization_credentials+ .async_lift(|inner| async {+ crypto_operation(+ state,+ type_name!(Self::DstType),+ CryptoOperation::DecryptOptional(inner),+ key_manager_identifier.clone(),+ key.peek(),+ )+ .await+ .and_then(|val| val.try_into_optionaloperation())+ })+ .await?,+ fingerprint_secret: item.fingerprint_secret,+ offer_engine_config: item+ .offer_engine_config+ .async_lift(|inner| async {+ crypto_operation(+ state,+ type_name!(Self::DstType),+ CryptoOperation::DecryptOptional(inner),+ key_manager_identifier.clone(),+ key.peek(),+ )+ .await+ .and_then(|val| val.try_into_optionaloperation())+ })+ .await?,+ }+ .into(),+ )+ }+ .await+ .change_context(ValidationError::InvalidValue {+ message: "Failed while decrypting merchant data".to_string(),+ })+ }++ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {+ let now = date_time::now();+ Ok(diesel_models::merchant_account::MerchantAccountNew {+ id: Some(self.get_id().to_owned()),+ merchant_id: self.get_id().to_owned(),+ merchant_name: self.merchant_name.map(Encryption::from),+ merchant_details: self.merchant_details.map(Encryption::from),+ return_url: self.return_url,+ webhook_details: self.webhook_details,+ sub_merchants_enabled: self.sub_merchants_enabled,+ parent_merchant_id: self.parent_merchant_id,+ enable_payment_response_hash: Some(self.enable_payment_response_hash),+ payment_response_hash_key: self.payment_response_hash_key,+ redirect_to_merchant_with_http_post: Some(self.redirect_to_merchant_with_http_post),+ publishable_key: Some(self.publishable_key),+ locker_id: self.locker_id,+ metadata: self.metadata,+ routing_algorithm: self.routing_algorithm,+ primary_business_details: self.primary_business_details,+ created_at: now,+ modified_at: now,+ intent_fulfillment_time: self.intent_fulfillment_time,+ frm_routing_algorithm: self.frm_routing_algorithm,+ payout_routing_algorithm: self.payout_routing_algorithm,+ organization_id: self.organization_id,+ is_recon_enabled: self.is_recon_enabled,+ default_profile: self.default_profile,+ recon_status: self.recon_status,+ payment_link_config: self.payment_link_config,+ pm_collect_link_config: self.pm_collect_link_config,+ version: self.version,+ is_platform_account: self.is_platform_account,+ product_type: self+ .product_type+ .or(Some(common_enums::MerchantProductType::Orchestration)),+ merchant_account_type: self.merchant_account_type,+ network_tokenization_credentials: self+ .network_tokenization_credentials+ .map(|credentials| credentials.into()),+ storage_scheme: self.storage_scheme,+ fingerprint_secret: self.fingerprint_secret,+ offer_engine_config: self.offer_engine_config.map(|config| config.into()),+ })+ }+}