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
chore: make v1 merchant account forward compatible (#7426)
Hrithikeshb63439a0936c
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex de85d8c2c0..61bb7c009e 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -111,6 +111,10 @@ pub struct MerchantAccountCreate {/// Default payment method collect link config#[schema(value_type = Option<BusinessCollectLinkConfig>)]pub pm_collect_link_config: Option<BusinessCollectLinkConfig>,++ /// Product Type of this merchant account+ #[schema(value_type = Option<api_enums::MerchantProductType>)]+ pub product_type: Option<api_enums::MerchantProductType>,}#[cfg(feature = "v1")]@@ -193,6 +197,8 @@ pub struct MerchantAccountCreateWithoutOrgId {/// Metadata is useful for storing additional, unstructured information about the merchant account.#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]pub metadata: Option<pii::SecretSerdeValue>,++ pub product_type: Option<api_enums::MerchantProductType>,}// In v2 the struct used in the API is MerchantAccountCreateWithoutOrgId@@ -205,6 +211,8 @@ pub struct MerchantAccountCreate {pub merchant_details: Option<MerchantDetails>,pub metadata: Option<pii::SecretSerdeValue>,pub organization_id: id_type::OrganizationId,+ /// Product Type of this merchant account+ pub product_type: Option<api_enums::MerchantProductType>,}#[cfg(feature = "v2")]@@ -550,6 +558,10 @@ pub struct MerchantAccountResponse {/// Default payment method collect link config#[schema(value_type = Option<BusinessCollectLinkConfig>)]pub pm_collect_link_config: Option<BusinessCollectLinkConfig>,++ /// Product Type of this merchant account+ #[schema(value_type = Option<api_enums::MerchantProductType>)]+ pub product_type: Option<api_enums::MerchantProductType>,}#[cfg(feature = "v2")]@@ -582,6 +594,10 @@ pub struct MerchantAccountResponse {/// Used to indicate the status of the recon module for a merchant account#[schema(value_type = ReconStatus, example = "not_requested")]pub recon_status: api_enums::ReconStatus,++ /// Product Type of this merchant account+ #[schema(value_type = Option<api_enums::MerchantProductType>)]+ pub product_type: Option<api_enums::MerchantProductType>,}#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]diff --git a/crates/diesel_models/src/query/merchant_account.rs b/crates/diesel_models/src/query/merchant_account.rsindex 0394564601..c40af7f653 100644--- a/crates/diesel_models/src/query/merchant_account.rs+++ b/crates/diesel_models/src/query/merchant_account.rs@@ -2,9 +2,9 @@ use diesel::{associations::HasTable, ExpressionMethods, Table};use super::generics;#[cfg(feature = "v1")]-use crate::schema::merchant_account::dsl::{self, merchant_id as dsl_identifier};+use crate::schema::merchant_account::dsl;#[cfg(feature = "v2")]-use crate::schema_v2::merchant_account::dsl::{self, id as dsl_identifier};+use crate::schema_v2::merchant_account::dsl;use crate::{errors,merchant_account::{MerchantAccount, MerchantAccountNew, MerchantAccountUpdateInternal},@@ -17,6 +17,7 @@ impl MerchantAccountNew {}}+#[cfg(feature = "v1")]impl MerchantAccount {pub async fn update(self,@@ -50,7 +51,7 @@ impl MerchantAccount {_,>(conn,- dsl_identifier.eq(identifier.to_owned()),+ dsl::merchant_id.eq(identifier.to_owned()),merchant_account,).await@@ -62,7 +63,147 @@ impl MerchantAccount {) -> StorageResult<bool> {generics::generic_delete::<<Self as HasTable>::Table, _>(conn,- dsl_identifier.eq(identifier.to_owned()),+ dsl::merchant_id.eq(identifier.to_owned()),+ )+ .await+ }++ pub async fn find_by_merchant_id(+ conn: &PgPooledConn,+ identifier: &common_utils::id_type::MerchantId,+ ) -> StorageResult<Self> {+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(+ conn,+ dsl::merchant_id.eq(identifier.to_owned()),+ )+ .await+ }++ pub async fn find_by_publishable_key(+ conn: &PgPooledConn,+ publishable_key: &str,+ ) -> StorageResult<Self> {+ generics::generic_find_one::<<Self as HasTable>::Table, _, _>(+ conn,+ dsl::publishable_key.eq(publishable_key.to_owned()),+ )+ .await+ }++ pub async fn list_by_organization_id(+ conn: &PgPooledConn,+ organization_id: &common_utils::id_type::OrganizationId,+ ) -> StorageResult<Vec<Self>> {+ generics::generic_filter::<+ <Self as HasTable>::Table,+ _,+ <<Self as HasTable>::Table as Table>::PrimaryKey,+ _,+ >(+ conn,+ dsl::organization_id.eq(organization_id.to_owned()),+ None,+ None,+ None,+ )+ .await+ }++ pub async fn list_multiple_merchant_accounts(+ conn: &PgPooledConn,+ merchant_ids: Vec<common_utils::id_type::MerchantId>,+ ) -> StorageResult<Vec<Self>> {+ generics::generic_filter::<+ <Self as HasTable>::Table,+ _,+ <<Self as HasTable>::Table as Table>::PrimaryKey,+ _,+ >(+ conn,+ dsl::merchant_id.eq_any(merchant_ids.clone()),+ None,+ None,+ None,+ )+ .await+ }++ pub async fn list_all_merchant_accounts(+ conn: &PgPooledConn,+ limit: u32,+ offset: Option<u32>,+ ) -> StorageResult<Vec<Self>> {+ generics::generic_filter::<+ <Self as HasTable>::Table,+ _,+ <<Self as HasTable>::Table as Table>::PrimaryKey,+ _,+ >(+ conn,+ dsl::merchant_id.ne_all(vec![""]),+ Some(i64::from(limit)),+ offset.map(i64::from),+ None,+ )+ .await+ }++ pub async fn update_all_merchant_accounts(+ conn: &PgPooledConn,+ merchant_account: MerchantAccountUpdateInternal,+ ) -> StorageResult<Vec<Self>> {+ generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(+ conn,+ dsl::merchant_id.ne_all(vec![""]),+ merchant_account,+ )+ .await+ }+}++#[cfg(feature = "v2")]+impl MerchantAccount {+ pub async fn update(+ self,+ conn: &PgPooledConn,+ merchant_account: MerchantAccountUpdateInternal,+ ) -> StorageResult<Self> {+ match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(+ conn,+ self.get_id().to_owned(),+ merchant_account,+ )+ .await+ {+ Err(error) => match error.current_context() {+ errors::DatabaseError::NoFieldsToUpdate => Ok(self),+ _ => Err(error),+ },+ result => result,+ }+ }++ pub async fn update_with_specific_fields(+ conn: &PgPooledConn,+ identifier: &common_utils::id_type::MerchantId,+ merchant_account: MerchantAccountUpdateInternal,+ ) -> StorageResult<Self> {+ generics::generic_update_with_unique_predicate_get_result::<+ <Self as HasTable>::Table,+ _,+ _,+ _,+ >(conn, dsl::id.eq(identifier.to_owned()), merchant_account)+ .await+ }++ pub async fn delete_by_merchant_id(+ conn: &PgPooledConn,+ identifier: &common_utils::id_type::MerchantId,+ ) -> StorageResult<bool> {+ generics::generic_delete::<<Self as HasTable>::Table, _>(+ conn,+ dsl::id.eq(identifier.to_owned()),).await}@@ -73,7 +214,7 @@ impl MerchantAccount {) -> StorageResult<Self> {generics::generic_find_one::<<Self as HasTable>::Table, _, _>(conn,- dsl_identifier.eq(identifier.to_owned()),+ dsl::id.eq(identifier.to_owned()),).await}@@ -117,7 +258,7 @@ impl MerchantAccount {_,<<Self as HasTable>::Table as Table>::PrimaryKey,_,- >(conn, dsl_identifier.eq_any(merchant_ids), None, None, None)+ >(conn, dsl::id.eq_any(merchant_ids), None, None, None).await}@@ -133,7 +274,7 @@ impl MerchantAccount {_,>(conn,- dsl_identifier.ne_all(vec![""]),+ dsl::id.ne_all(vec![""]),Some(i64::from(limit)),offset.map(i64::from),None,@@ -147,7 +288,7 @@ impl MerchantAccount {) -> StorageResult<Vec<Self>> {generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(conn,- dsl_identifier.ne_all(vec![""]),+ dsl::id.ne_all(vec![""]),merchant_account,).awaitdiff --git a/crates/hyperswitch_domain_models/src/merchant_account.rs b/crates/hyperswitch_domain_models/src/merchant_account.rsindex e3617b7910..b6b7571d32 100644--- a/crates/hyperswitch_domain_models/src/merchant_account.rs+++ b/crates/hyperswitch_domain_models/src/merchant_account.rs@@ -654,7 +654,9 @@ impl super::behaviour::Conversion for MerchantAccount {recon_status: self.recon_status,version: crate::consts::API_VERSION,is_platform_account: self.is_platform_account,- product_type: self.product_type,+ product_type: self+ .product_type+ .or(Some(common_enums::MerchantProductType::Orchestration)),})}}@@ -786,7 +788,7 @@ impl super::behaviour::Conversion for MerchantAccount {async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {let now = date_time::now();Ok(diesel_models::merchant_account::MerchantAccountNew {- id: None,+ 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),@@ -815,7 +817,9 @@ impl super::behaviour::Conversion for MerchantAccount {pm_collect_link_config: self.pm_collect_link_config,version: crate::consts::API_VERSION,is_platform_account: self.is_platform_account,- product_type: self.product_type,+ product_type: self+ .product_type+ .or(Some(common_enums::MerchantProductType::Orchestration)),})}}diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 46b6930667..c5fb803ef9 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -404,7 +404,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {pm_collect_link_config,version: hyperswitch_domain_models::consts::API_VERSION,is_platform_account: false,- product_type: None,+ product_type: self.product_type,},)}@@ -673,7 +673,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {organization_id: organization.get_organization_id(),recon_status: diesel_models::enums::ReconStatus::NotRequested,is_platform_account: false,- product_type: None,+ product_type: self.product_type,}),)}diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rsindex a112be4618..876fa0bf25 100644--- a/crates/router/src/routes/admin.rs+++ b/crates/router/src/routes/admin.rs@@ -135,6 +135,7 @@ pub async fn merchant_account_create(merchant_details: json_payload.merchant_details,metadata: json_payload.metadata,organization_id: org_id,+ product_type: json_payload.product_type,};Box::pin(api::server_wrap(diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rsindex 80d5e300be..27136cc3ea 100644--- a/crates/router/src/types/api/admin.rs+++ b/crates/router/src/types/api/admin.rs@@ -91,6 +91,7 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {default_profile: item.default_profile,recon_status: item.recon_status,pm_collect_link_config,+ product_type: item.product_type,})}}@@ -116,6 +117,7 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {metadata: item.metadata,organization_id: item.organization_id,recon_status: item.recon_status,+ product_type: item.product_type,})}}diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rsindex 1eb2305058..a51ccfdc71 100644--- a/crates/router/src/types/domain/user.rs+++ b/crates/router/src/types/domain/user.rs@@ -450,6 +450,7 @@ impl NewUserMerchant {organization_id: self.new_organization.get_organization_id(),metadata: None,merchant_details: None,+ product_type: None,})}@@ -476,6 +477,7 @@ impl NewUserMerchant {enable_payment_response_hash: None,redirect_to_merchant_with_http_post: None,pm_collect_link_config: None,+ product_type: None,})}diff --git a/crates/router/src/utils/user.rs b/crates/router/src/utils/user.rsindex 721b0052bd..b386185eec 100644--- a/crates/router/src/utils/user.rs+++ b/crates/router/src/utils/user.rs@@ -315,6 +315,7 @@ pub fn create_merchant_account_request_for_org(enable_payment_response_hash: None,redirect_to_merchant_with_http_post: None,pm_collect_link_config: None,+ product_type: None,})}