refactor(merchant_account_v2): recreate id for merchant_account v2 (#5439)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-07-26 12:39:34 +05:30
committed by GitHub
parent 2d235a64e9
commit 93976db30a
18 changed files with 438 additions and 119 deletions

View File

@ -440,7 +440,7 @@ pub struct MerchantAccountResponse {
pub struct MerchantAccountResponse { pub struct MerchantAccountResponse {
/// The identifier for the Merchant Account /// The identifier for the Merchant Account
#[schema(max_length = 64, example = "y3oqhf46pyzuxjbcn2giaqnb44")] #[schema(max_length = 64, example = "y3oqhf46pyzuxjbcn2giaqnb44")]
pub id: String, pub id: id_type::MerchantId,
/// Name of the Merchant Account /// Name of the Merchant Account
#[schema(value_type = String,example = "NewAge Retailer")] #[schema(value_type = String,example = "NewAge Retailer")]

View File

@ -1,4 +1,4 @@
use common_utils::{encryption::Encryption, id_type, pii}; use common_utils::{encryption::Encryption, pii};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable}; use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use crate::enums as storage_enums; use crate::enums as storage_enums;
@ -10,6 +10,9 @@ use crate::schema::merchant_account;
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] #[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
use crate::schema_v2::merchant_account; use crate::schema_v2::merchant_account;
/// Note: The order of fields in the struct is important.
/// This should be in the same order as the fields in the schema.rs file, otherwise the code will not compile
/// If two adjacent columns have the same type, then the compiler will not throw any error, but the fields read / written will be interchanged
#[cfg(all( #[cfg(all(
any(feature = "v1", feature = "v2"), any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2") not(feature = "merchant_account_v2")
@ -26,49 +29,7 @@ use crate::schema_v2::merchant_account;
)] )]
#[diesel(table_name = merchant_account, primary_key(merchant_id), check_for_backend(diesel::pg::Pg))] #[diesel(table_name = merchant_account, primary_key(merchant_id), check_for_backend(diesel::pg::Pg))]
pub struct MerchantAccount { pub struct MerchantAccount {
pub merchant_id: id_type::MerchantId, merchant_id: common_utils::id_type::MerchantId,
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<id_type::MerchantId>,
pub publishable_key: Option<String>,
pub storage_scheme: storage_enums::MerchantStorageScheme,
pub locker_id: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: id_type::OrganizationId,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
}
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(
Clone,
Debug,
serde::Deserialize,
Identifiable,
serde::Serialize,
Queryable,
router_derive::DebugAsDisplay,
Selectable,
)]
#[diesel(table_name = merchant_account, primary_key(merchant_id), check_for_backend(diesel::pg::Pg))]
pub struct MerchantAccount {
pub merchant_id: id_type::MerchantId,
pub return_url: Option<String>, pub return_url: Option<String>,
pub enable_payment_response_hash: bool, pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>, pub payment_response_hash_key: Option<String>,
@ -89,7 +50,190 @@ pub struct MerchantAccount {
pub modified_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>, pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>, pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: id_type::OrganizationId, pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
pub struct MerchantAccountSetter {
pub merchant_id: common_utils::id_type::MerchantId,
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub publishable_key: Option<String>,
pub storage_scheme: storage_enums::MerchantStorageScheme,
pub locker_id: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
impl From<MerchantAccountSetter> for MerchantAccount {
fn from(item: MerchantAccountSetter) -> Self {
Self {
merchant_id: item.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,
merchant_details: item.merchant_details,
webhook_details: item.webhook_details,
sub_merchants_enabled: item.sub_merchants_enabled,
parent_merchant_id: item.parent_merchant_id,
publishable_key: item.publishable_key,
storage_scheme: item.storage_scheme,
locker_id: item.locker_id,
metadata: item.metadata,
routing_algorithm: item.routing_algorithm,
primary_business_details: item.primary_business_details,
intent_fulfillment_time: item.intent_fulfillment_time,
created_at: item.created_at,
modified_at: item.modified_at,
frm_routing_algorithm: item.frm_routing_algorithm,
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,
}
}
}
/// Note: The order of fields in the struct is important.
/// This should be in the same order as the fields in the schema.rs file, otherwise the code will not compile
/// If two adjacent columns have the same type, then the compiler will not throw any error, but the fields read / written will be interchanged
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(
Clone,
Debug,
serde::Deserialize,
Identifiable,
serde::Serialize,
Queryable,
router_derive::DebugAsDisplay,
Selectable,
)]
#[diesel(table_name = merchant_account, primary_key(id), check_for_backend(diesel::pg::Pg))]
pub struct MerchantAccount {
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub publishable_key: Option<String>,
pub storage_scheme: storage_enums::MerchantStorageScheme,
pub locker_id: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
pub id: common_utils::id_type::MerchantId,
}
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
impl From<MerchantAccountSetter> for MerchantAccount {
fn from(item: MerchantAccountSetter) -> Self {
Self {
id: item.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,
merchant_details: item.merchant_details,
webhook_details: item.webhook_details,
sub_merchants_enabled: item.sub_merchants_enabled,
parent_merchant_id: item.parent_merchant_id,
publishable_key: item.publishable_key,
storage_scheme: item.storage_scheme,
locker_id: item.locker_id,
metadata: item.metadata,
routing_algorithm: item.routing_algorithm,
primary_business_details: item.primary_business_details,
intent_fulfillment_time: item.intent_fulfillment_time,
created_at: item.created_at,
modified_at: item.modified_at,
frm_routing_algorithm: item.frm_routing_algorithm,
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,
}
}
}
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
pub struct MerchantAccountSetter {
pub id: common_utils::id_type::MerchantId,
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub publishable_key: Option<String>,
pub storage_scheme: storage_enums::MerchantStorageScheme,
pub locker_id: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool, pub is_recon_enabled: bool,
pub default_profile: Option<String>, pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus, pub recon_status: storage_enums::ReconStatus,
@ -98,21 +242,35 @@ pub struct MerchantAccount {
} }
impl MerchantAccount { impl MerchantAccount {
pub fn get_id(&self) -> &id_type::MerchantId { #[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
/// Get the unique identifier of MerchantAccount
pub fn get_id(&self) -> &common_utils::id_type::MerchantId {
&self.merchant_id &self.merchant_id
} }
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
pub fn get_id(&self) -> &common_utils::id_type::MerchantId {
&self.id
}
} }
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)] #[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_account)] #[diesel(table_name = merchant_account)]
pub struct MerchantAccountNew { pub struct MerchantAccountNew {
pub merchant_id: id_type::MerchantId, pub merchant_id: common_utils::id_type::MerchantId,
pub merchant_name: Option<Encryption>, pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>, pub merchant_details: Option<Encryption>,
pub return_url: Option<String>, pub return_url: Option<String>,
pub webhook_details: Option<serde_json::Value>, pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>, pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<id_type::MerchantId>, pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub enable_payment_response_hash: Option<bool>, pub enable_payment_response_hash: Option<bool>,
pub payment_response_hash_key: Option<String>, pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: Option<bool>, pub redirect_to_merchant_with_http_post: Option<bool>,
@ -126,7 +284,7 @@ pub struct MerchantAccountNew {
pub modified_at: time::PrimitiveDateTime, pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>, pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>, pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: id_type::OrganizationId, pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool, pub is_recon_enabled: bool,
pub default_profile: Option<String>, pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus, pub recon_status: storage_enums::ReconStatus,
@ -134,6 +292,38 @@ pub struct MerchantAccountNew {
pub pm_collect_link_config: Option<serde_json::Value>, pub pm_collect_link_config: Option<serde_json::Value>,
} }
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_account)]
pub struct MerchantAccountNew {
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
pub return_url: Option<String>,
pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub enable_payment_response_hash: Option<bool>,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: Option<bool>,
pub publishable_key: Option<String>,
pub locker_id: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
pub id: common_utils::id_type::MerchantId,
}
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)] #[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_account)] #[diesel(table_name = merchant_account)]
pub struct MerchantAccountUpdateInternal { pub struct MerchantAccountUpdateInternal {
@ -142,7 +332,7 @@ pub struct MerchantAccountUpdateInternal {
pub return_url: Option<String>, pub return_url: Option<String>,
pub webhook_details: Option<serde_json::Value>, pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>, pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<id_type::MerchantId>, pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub enable_payment_response_hash: Option<bool>, pub enable_payment_response_hash: Option<bool>,
pub payment_response_hash_key: Option<String>, pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: Option<bool>, pub redirect_to_merchant_with_http_post: Option<bool>,
@ -156,7 +346,7 @@ pub struct MerchantAccountUpdateInternal {
pub intent_fulfillment_time: Option<i64>, pub intent_fulfillment_time: Option<i64>,
pub frm_routing_algorithm: Option<serde_json::Value>, pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>, pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: Option<id_type::OrganizationId>, pub organization_id: Option<common_utils::id_type::OrganizationId>,
pub is_recon_enabled: bool, pub is_recon_enabled: bool,
pub default_profile: Option<Option<String>>, pub default_profile: Option<Option<String>>,
pub recon_status: Option<storage_enums::ReconStatus>, pub recon_status: Option<storage_enums::ReconStatus>,

View File

@ -5,9 +5,9 @@ use super::generics;
any(feature = "v1", feature = "v2"), any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2") not(feature = "merchant_account_v2")
))] ))]
use crate::schema::merchant_account::dsl; use crate::schema::merchant_account::dsl::{self, merchant_id as dsl_identifier};
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] #[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
use crate::schema_v2::merchant_account::dsl; use crate::schema_v2::merchant_account::dsl::{self, id as dsl_identifier};
use crate::{ use crate::{
errors, errors,
merchant_account::{MerchantAccount, MerchantAccountNew, MerchantAccountUpdateInternal}, merchant_account::{MerchantAccount, MerchantAccountNew, MerchantAccountUpdateInternal},
@ -28,7 +28,7 @@ impl MerchantAccount {
) -> StorageResult<Self> { ) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>( match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn, conn,
self.merchant_id.clone(), self.get_id().to_owned(),
merchant_account, merchant_account,
) )
.await .await
@ -43,7 +43,7 @@ impl MerchantAccount {
pub async fn update_with_specific_fields( pub async fn update_with_specific_fields(
conn: &PgPooledConn, conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId, identifier: &common_utils::id_type::MerchantId,
merchant_account: MerchantAccountUpdateInternal, merchant_account: MerchantAccountUpdateInternal,
) -> StorageResult<Self> { ) -> StorageResult<Self> {
generics::generic_update_with_unique_predicate_get_result::< generics::generic_update_with_unique_predicate_get_result::<
@ -53,7 +53,7 @@ impl MerchantAccount {
_, _,
>( >(
conn, conn,
dsl::merchant_id.eq(merchant_id.to_owned()), dsl_identifier.eq(identifier.to_owned()),
merchant_account, merchant_account,
) )
.await .await
@ -61,22 +61,22 @@ impl MerchantAccount {
pub async fn delete_by_merchant_id( pub async fn delete_by_merchant_id(
conn: &PgPooledConn, conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId, identifier: &common_utils::id_type::MerchantId,
) -> StorageResult<bool> { ) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>( generics::generic_delete::<<Self as HasTable>::Table, _>(
conn, conn,
dsl::merchant_id.eq(merchant_id.to_owned()), dsl_identifier.eq(identifier.to_owned()),
) )
.await .await
} }
pub async fn find_by_merchant_id( pub async fn find_by_merchant_id(
conn: &PgPooledConn, conn: &PgPooledConn,
merchant_id: &common_utils::id_type::MerchantId, identifier: &common_utils::id_type::MerchantId,
) -> StorageResult<Self> { ) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>( generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn, conn,
dsl::merchant_id.eq(merchant_id.to_owned()), dsl_identifier.eq(identifier.to_owned()),
) )
.await .await
} }
@ -120,13 +120,7 @@ impl MerchantAccount {
_, _,
<<Self as HasTable>::Table as Table>::PrimaryKey, <<Self as HasTable>::Table as Table>::PrimaryKey,
_, _,
>( >(conn, dsl_identifier.eq_any(merchant_ids), None, None, None)
conn,
dsl::merchant_id.eq_any(merchant_ids),
None,
None,
None,
)
.await .await
} }
@ -136,7 +130,7 @@ impl MerchantAccount {
) -> StorageResult<Vec<Self>> { ) -> StorageResult<Vec<Self>> {
generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>( generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
conn, conn,
dsl::merchant_id.ne_all(vec![""]), dsl_identifier.ne_all(vec![""]),
merchant_account, merchant_account,
) )
.await .await

View File

@ -633,9 +633,7 @@ diesel::table! {
use diesel::sql_types::*; use diesel::sql_types::*;
use crate::enums::diesel_exports::*; use crate::enums::diesel_exports::*;
merchant_account (merchant_id) { merchant_account (id) {
#[max_length = 64]
merchant_id -> Varchar,
#[max_length = 255] #[max_length = 255]
return_url -> Nullable<Varchar>, return_url -> Nullable<Varchar>,
enable_payment_response_hash -> Bool, enable_payment_response_hash -> Bool,
@ -669,6 +667,8 @@ diesel::table! {
recon_status -> ReconStatus, recon_status -> ReconStatus,
payment_link_config -> Nullable<Jsonb>, payment_link_config -> Nullable<Jsonb>,
pm_collect_link_config -> Nullable<Jsonb>, pm_collect_link_config -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
} }
} }

View File

@ -126,9 +126,10 @@ impl From<MerchantAccountSetter> for MerchantAccount {
} }
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))] #[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(Clone, Debug, serde::Serialize)] #[derive(Clone)]
pub struct MerchantAccount { /// Set the private fields of merchant account
merchant_id: common_utils::id_type::MerchantId, pub struct MerchantAccountSetter {
pub id: common_utils::id_type::MerchantId,
pub return_url: Option<String>, pub return_url: Option<String>,
pub enable_payment_response_hash: bool, pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>, pub payment_response_hash_key: Option<String>,
@ -137,7 +138,74 @@ pub struct MerchantAccount {
pub merchant_details: OptionalEncryptableValue, pub merchant_details: OptionalEncryptableValue,
pub webhook_details: Option<serde_json::Value>, pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>, pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<String>, pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub publishable_key: String,
pub storage_scheme: MerchantStorageScheme,
pub locker_id: Option<String>,
pub metadata: Option<pii::SecretSerdeValue>,
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
pub intent_fulfillment_time: Option<i64>,
pub payout_routing_algorithm: Option<serde_json::Value>,
pub organization_id: common_utils::id_type::OrganizationId,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: diesel_models::enums::ReconStatus,
pub payment_link_config: Option<serde_json::Value>,
pub pm_collect_link_config: Option<serde_json::Value>,
}
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
impl From<MerchantAccountSetter> for MerchantAccount {
fn from(item: MerchantAccountSetter) -> Self {
Self {
id: item.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,
merchant_details: item.merchant_details,
webhook_details: item.webhook_details,
sub_merchants_enabled: item.sub_merchants_enabled,
parent_merchant_id: item.parent_merchant_id,
publishable_key: item.publishable_key,
storage_scheme: item.storage_scheme,
locker_id: item.locker_id,
metadata: item.metadata,
routing_algorithm: item.routing_algorithm,
primary_business_details: item.primary_business_details,
frm_routing_algorithm: item.frm_routing_algorithm,
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,
}
}
}
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
#[derive(Clone, Debug, serde::Serialize)]
pub struct MerchantAccount {
id: common_utils::id_type::MerchantId,
pub return_url: Option<String>,
pub enable_payment_response_hash: bool,
pub payment_response_hash_key: Option<String>,
pub redirect_to_merchant_with_http_post: bool,
pub merchant_name: OptionalEncryptableName,
pub merchant_details: OptionalEncryptableValue,
pub webhook_details: Option<serde_json::Value>,
pub sub_merchants_enabled: Option<bool>,
pub parent_merchant_id: Option<common_utils::id_type::MerchantId>,
pub publishable_key: String, pub publishable_key: String,
pub storage_scheme: MerchantStorageScheme, pub storage_scheme: MerchantStorageScheme,
pub locker_id: Option<String>, pub locker_id: Option<String>,
@ -158,10 +226,20 @@ pub struct MerchantAccount {
} }
impl MerchantAccount { impl MerchantAccount {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
/// Get the unique identifier of MerchantAccount /// Get the unique identifier of MerchantAccount
pub fn get_id(&self) -> &common_utils::id_type::MerchantId { pub fn get_id(&self) -> &common_utils::id_type::MerchantId {
&self.merchant_id &self.merchant_id
} }
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
/// Get the unique identifier of MerchantAccount
pub fn get_id(&self) -> &common_utils::id_type::MerchantId {
&self.id
}
} }
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
@ -278,8 +356,10 @@ impl super::behaviour::Conversion for MerchantAccount {
type DstType = diesel_models::merchant_account::MerchantAccount; type DstType = diesel_models::merchant_account::MerchantAccount;
type NewDstType = diesel_models::merchant_account::MerchantAccountNew; type NewDstType = diesel_models::merchant_account::MerchantAccountNew;
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> { async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::merchant_account::MerchantAccount { let id = self.get_id().to_owned();
merchant_id: self.merchant_id,
let setter = diesel_models::merchant_account::MerchantAccountSetter {
id,
return_url: self.return_url, return_url: self.return_url,
enable_payment_response_hash: self.enable_payment_response_hash, enable_payment_response_hash: self.enable_payment_response_hash,
payment_response_hash_key: self.payment_response_hash_key, payment_response_hash_key: self.payment_response_hash_key,
@ -306,7 +386,9 @@ impl super::behaviour::Conversion for MerchantAccount {
recon_status: self.recon_status, recon_status: self.recon_status,
payment_link_config: self.payment_link_config, payment_link_config: self.payment_link_config,
pm_collect_link_config: self.pm_collect_link_config, pm_collect_link_config: self.pm_collect_link_config,
}) };
Ok(diesel_models::MerchantAccount::from(setter))
} }
async fn convert_back( async fn convert_back(
@ -318,6 +400,7 @@ impl super::behaviour::Conversion for MerchantAccount {
where where
Self: Sized, Self: Sized,
{ {
let id = item.get_id().to_owned();
let publishable_key = let publishable_key =
item.publishable_key item.publishable_key
.ok_or(ValidationError::MissingRequiredField { .ok_or(ValidationError::MissingRequiredField {
@ -326,7 +409,7 @@ impl super::behaviour::Conversion for MerchantAccount {
async { async {
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self { Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
merchant_id: item.merchant_id, id,
return_url: item.return_url, return_url: item.return_url,
enable_payment_response_hash: item.enable_payment_response_hash, enable_payment_response_hash: item.enable_payment_response_hash,
payment_response_hash_key: item.payment_response_hash_key, payment_response_hash_key: item.payment_response_hash_key,
@ -374,7 +457,7 @@ impl super::behaviour::Conversion for MerchantAccount {
async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> { async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
let now = date_time::now(); let now = date_time::now();
Ok(diesel_models::merchant_account::MerchantAccountNew { Ok(diesel_models::merchant_account::MerchantAccountNew {
merchant_id: self.merchant_id, id: self.id,
merchant_name: self.merchant_name.map(Encryption::from), merchant_name: self.merchant_name.map(Encryption::from),
merchant_details: self.merchant_details.map(Encryption::from), merchant_details: self.merchant_details.map(Encryption::from),
return_url: self.return_url, return_url: self.return_url,
@ -413,7 +496,7 @@ impl super::behaviour::Conversion for MerchantAccount {
type DstType = diesel_models::merchant_account::MerchantAccount; type DstType = diesel_models::merchant_account::MerchantAccount;
type NewDstType = diesel_models::merchant_account::MerchantAccountNew; type NewDstType = diesel_models::merchant_account::MerchantAccountNew;
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> { async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::merchant_account::MerchantAccount { let setter = diesel_models::merchant_account::MerchantAccountSetter {
merchant_id: self.merchant_id, merchant_id: self.merchant_id,
return_url: self.return_url, return_url: self.return_url,
enable_payment_response_hash: self.enable_payment_response_hash, enable_payment_response_hash: self.enable_payment_response_hash,
@ -441,7 +524,9 @@ impl super::behaviour::Conversion for MerchantAccount {
recon_status: self.recon_status, recon_status: self.recon_status,
payment_link_config: self.payment_link_config, payment_link_config: self.payment_link_config,
pm_collect_link_config: self.pm_collect_link_config, pm_collect_link_config: self.pm_collect_link_config,
}) };
Ok(diesel_models::MerchantAccount::from(setter))
} }
async fn convert_back( async fn convert_back(
@ -453,14 +538,16 @@ impl super::behaviour::Conversion for MerchantAccount {
where where
Self: Sized, Self: Sized,
{ {
let merchant_id = item.get_id().to_owned();
let publishable_key = let publishable_key =
item.publishable_key item.publishable_key
.ok_or(ValidationError::MissingRequiredField { .ok_or(ValidationError::MissingRequiredField {
field_name: "publishable_key".to_string(), field_name: "publishable_key".to_string(),
})?; })?;
async { async {
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self { Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
merchant_id: item.merchant_id, merchant_id,
return_url: item.return_url, return_url: item.return_url,
enable_payment_response_hash: item.enable_payment_response_hash, enable_payment_response_hash: item.enable_payment_response_hash,
payment_response_hash_key: item.payment_response_hash_key, payment_response_hash_key: item.payment_response_hash_key,

View File

@ -554,7 +554,7 @@ impl behaviour::Conversion for PaymentIntent {
{ {
async { async {
let inner_decrypt = let inner_decrypt =
|inner| decrypt_optional(state, inner, key_manager_identifier, key.peek()); |inner| decrypt_optional(state, inner, key_manager_identifier.clone(), key.peek());
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self { Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
payment_id: storage_model.payment_id, payment_id: storage_model.payment_id,
merchant_id: storage_model.merchant_id, merchant_id: storage_model.merchant_id,

View File

@ -412,7 +412,10 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
#[cfg(feature = "olap")] #[cfg(feature = "olap")]
enum CreateOrValidateOrganization { enum CreateOrValidateOrganization {
/// Creates a new organization /// Creates a new organization
#[cfg(any(feature = "v1", feature = "v2"))] #[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
Create, Create,
/// Validates if this organization exists in the records /// Validates if this organization exists in the records
Validate { Validate {
@ -451,7 +454,10 @@ impl CreateOrValidateOrganization {
db: &dyn StorageInterface, db: &dyn StorageInterface,
) -> RouterResult<diesel_models::organization::Organization> { ) -> RouterResult<diesel_models::organization::Organization> {
match self { match self {
#[cfg(any(feature = "v1", feature = "v2"))] #[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "merchant_account_v2")
))]
Self::Create => { Self::Create => {
let new_organization = api_models::organization::OrganizationNew::new(None); let new_organization = api_models::organization::OrganizationNew::new(None);
let db_organization = ForeignFrom::foreign_from(new_organization); let db_organization = ForeignFrom::foreign_from(new_organization);
@ -637,17 +643,14 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
.await?; .await?;
let key = key_store.key.into_inner(); let key = key_store.key.into_inner();
let merchant_id = self let id = self.get_merchant_reference_id().to_owned();
.get_merchant_reference_id()
.get_string_repr()
.to_owned();
let key_manager_state = state.into(); let key_manager_state = state.into();
let identifier = km_types::Identifier::Merchant(merchant_id.clone()); let identifier = km_types::Identifier::Merchant(id.clone());
async { async {
Ok::<_, error_stack::Report<common_utils::errors::CryptoError>>( Ok::<_, error_stack::Report<common_utils::errors::CryptoError>>(
domain::MerchantAccount { domain::MerchantAccount::from(domain::MerchantAccountSetter {
merchant_id, id,
merchant_name: Some( merchant_name: Some(
domain_types::encrypt( domain_types::encrypt(
&key_manager_state, &key_manager_state,
@ -695,7 +698,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
recon_status: diesel_models::enums::ReconStatus::NotRequested, recon_status: diesel_models::enums::ReconStatus::NotRequested,
payment_link_config: None, payment_link_config: None,
pm_collect_link_config: None, pm_collect_link_config: None,
}, }),
) )
} }
.await .await

View File

@ -206,7 +206,7 @@ impl CustomerCreateBridge for customers::CustomerRequest {
) -> errors::CustomResult<domain::Customer, errors::CustomersErrorResponse> { ) -> errors::CustomResult<domain::Customer, errors::CustomersErrorResponse> {
let _default_customer_billing_address = self.get_default_customer_billing_address(); let _default_customer_billing_address = self.get_default_customer_billing_address();
let _default_customer_shipping_address = self.get_default_customer_shipping_address(); let _default_customer_shipping_address = self.get_default_customer_shipping_address();
let merchant_id = merchant_account.merchant_id.clone(); let merchant_id = merchant_account.get_id().clone();
let key = key_store.key.get_inner().peek(); let key = key_store.key.get_inner().peek();
let encrypted_data = types::batch_encrypt( let encrypted_data = types::batch_encrypt(
@ -230,14 +230,13 @@ impl CustomerCreateBridge for customers::CustomerRequest {
customer_id: merchant_reference_id customer_id: merchant_reference_id
.to_owned() .to_owned()
.ok_or(errors::CustomersErrorResponse::InternalServerError)?, // doing this to make it compile, will remove once we start moving to domain models .ok_or(errors::CustomersErrorResponse::InternalServerError)?, // doing this to make it compile, will remove once we start moving to domain models
merchant_id: merchant_id.to_string(), merchant_id,
name: encryptable_customer.name, name: encryptable_customer.name,
email: encryptable_customer.email, email: encryptable_customer.email,
phone: encryptable_customer.phone, phone: encryptable_customer.phone,
description: self.description.clone(), description: self.description.clone(),
phone_country_code: self.phone_country_code.clone(), phone_country_code: self.phone_country_code.clone(),
metadata: self.metadata.clone(), metadata: self.metadata.clone(),
id: None,
connector_customer: None, connector_customer: None,
address_id: None, address_id: None,
created_at: common_utils::date_time::now(), created_at: common_utils::date_time::now(),

View File

@ -483,7 +483,7 @@ impl MerchantAccountInterface for MockDb {
let accounts = self.merchant_accounts.lock().await; let accounts = self.merchant_accounts.lock().await;
let account: Option<domain::MerchantAccount> = accounts let account: Option<domain::MerchantAccount> = accounts
.iter() .iter()
.find(|account| account.merchant_id == *merchant_id) .find(|account| account.get_id() == merchant_id)
.cloned() .cloned()
.async_map(|a| async { .async_map(|a| async {
a.convert( a.convert(
@ -608,7 +608,7 @@ async fn publish_and_redact_all_merchant_account_cache(
) -> CustomResult<(), errors::StorageError> { ) -> CustomResult<(), errors::StorageError> {
let merchant_ids = merchant_accounts let merchant_ids = merchant_accounts
.iter() .iter()
.map(|m| m.merchant_id.get_string_repr().to_string()); .map(|merchant_account| merchant_account.get_id().get_string_repr().to_string());
let publishable_keys = merchant_accounts let publishable_keys = merchant_accounts
.iter() .iter()
.filter_map(|m| m.publishable_key.clone()); .filter_map(|m| m.publishable_key.clone());

View File

@ -20,8 +20,12 @@ use tokio::sync::oneshot;
use self::settings::Tenant; use self::settings::Tenant;
#[cfg(feature = "olap")] #[cfg(feature = "olap")]
use super::blocklist; use super::blocklist;
#[cfg(any(feature = "olap", feature = "oltp"))]
use super::currency;
#[cfg(feature = "dummy_connector")] #[cfg(feature = "dummy_connector")]
use super::dummy_connector::*; use super::dummy_connector::*;
#[cfg(all(any(feature = "olap", feature = "oltp"), not(feature = "customer_v2")))]
use super::payment_methods::*;
#[cfg(feature = "payouts")] #[cfg(feature = "payouts")]
use super::payout_link::*; use super::payout_link::*;
#[cfg(feature = "payouts")] #[cfg(feature = "payouts")]
@ -46,8 +50,6 @@ use super::{
use super::{cache::*, health::*}; use super::{cache::*, health::*};
#[cfg(any(feature = "olap", feature = "oltp"))] #[cfg(any(feature = "olap", feature = "oltp"))]
use super::{configs::*, customers::*, mandates::*, payments::*, refunds::*}; use super::{configs::*, customers::*, mandates::*, payments::*, refunds::*};
#[cfg(any(feature = "olap", feature = "oltp"))]
use super::{currency, payment_methods::*};
#[cfg(feature = "oltp")] #[cfg(feature = "oltp")]
use super::{ephemeral_key::*, webhooks::*}; use super::{ephemeral_key::*, webhooks::*};
#[cfg(feature = "olap")] #[cfg(feature = "olap")]
@ -58,8 +60,6 @@ use crate::analytics::AnalyticsProvider;
use crate::routes::fraud_check as frm_routes; use crate::routes::fraud_check as frm_routes;
#[cfg(all(feature = "recon", feature = "olap"))] #[cfg(all(feature = "recon", feature = "olap"))]
use crate::routes::recon as recon_routes; use crate::routes::recon as recon_routes;
#[cfg(all(feature = "olap", not(feature = "v2")))]
use crate::routes::verify_connector::payment_connector_verify;
pub use crate::{ pub use crate::{
configs::settings, configs::settings,
core::routing, core::routing,
@ -1116,7 +1116,7 @@ impl MerchantConnectorAccount {
route = route route = route
.service( .service(
web::resource("/connectors/verify") web::resource("/connectors/verify")
.route(web::post().to(payment_connector_verify)), .route(web::post().to(super::verify_connector::payment_connector_verify)),
) )
.service( .service(
web::resource("/{merchant_id}/connectors") web::resource("/{merchant_id}/connectors")

View File

@ -91,13 +91,15 @@ impl ForeignTryFrom<domain::MerchantAccount> for MerchantAccountResponse {
fn foreign_try_from(item: domain::MerchantAccount) -> Result<Self, Self::Error> { fn foreign_try_from(item: domain::MerchantAccount) -> Result<Self, Self::Error> {
use common_utils::ext_traits::OptionExt; use common_utils::ext_traits::OptionExt;
let id = item.get_id().to_owned();
let merchant_name = item let merchant_name = item
.merchant_name .merchant_name
.get_required_value("merchant_name")? .get_required_value("merchant_name")?
.into_inner(); .into_inner();
Ok(Self { Ok(Self {
id: item.merchant_id, id,
merchant_name, merchant_name,
merchant_details: item.merchant_details, merchant_details: item.merchant_details,
publishable_key: item.publishable_key, publishable_key: item.publishable_key,

View File

@ -22,17 +22,14 @@ use api_models::{
}; };
use base64::Engine; use base64::Engine;
use common_utils::types::keymanager::KeyManagerState; use common_utils::types::keymanager::KeyManagerState;
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
use common_utils::types::keymanager::{Identifier, ToEncryptable};
pub use common_utils::{ pub use common_utils::{
crypto, crypto,
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt}, ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when, fp_utils::when,
validation::validate_email, validation::validate_email,
}; };
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
use common_utils::{
id_type,
types::keymanager::{Identifier, ToEncryptable},
};
use error_stack::ResultExt; use error_stack::ResultExt;
use hyperswitch_domain_models::payments::PaymentIntent; use hyperswitch_domain_models::payments::PaymentIntent;
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
@ -677,15 +674,15 @@ pub trait CustomerAddress {
address_details: payments::AddressDetails, address_details: payments::AddressDetails,
key: &[u8], key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme, storage_scheme: storage::enums::MerchantStorageScheme,
merchant_id: id_type::MerchantId, merchant_id: common_utils::id_type::MerchantId,
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError>; ) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError>;
async fn get_domain_address( async fn get_domain_address(
&self, &self,
state: &SessionState, state: &SessionState,
address_details: payments::AddressDetails, address_details: payments::AddressDetails,
merchant_id: &id_type::MerchantId, merchant_id: &common_utils::id_type::MerchantId,
customer_id: &id_type::CustomerId, customer_id: &common_utils::id_type::CustomerId,
key: &[u8], key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme, storage_scheme: storage::enums::MerchantStorageScheme,
) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError>; ) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError>;
@ -700,7 +697,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
address_details: payments::AddressDetails, address_details: payments::AddressDetails,
key: &[u8], key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme, storage_scheme: storage::enums::MerchantStorageScheme,
merchant_id: id_type::MerchantId, merchant_id: common_utils::id_type::MerchantId,
) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError> { ) -> CustomResult<storage::AddressUpdate, common_utils::errors::CryptoError> {
let encrypted_data = batch_encrypt( let encrypted_data = batch_encrypt(
&state.into(), &state.into(),
@ -736,8 +733,8 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
&self, &self,
state: &SessionState, state: &SessionState,
address_details: payments::AddressDetails, address_details: payments::AddressDetails,
merchant_id: &id_type::MerchantId, merchant_id: &common_utils::id_type::MerchantId,
customer_id: &id_type::CustomerId, customer_id: &common_utils::id_type::CustomerId,
key: &[u8], key: &[u8],
storage_scheme: storage::enums::MerchantStorageScheme, storage_scheme: storage::enums::MerchantStorageScheme,
) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError> { ) -> CustomResult<domain::CustomerAddress, common_utils::errors::CryptoError> {
@ -784,7 +781,7 @@ impl CustomerAddress for api_models::customers::CustomerRequest {
pub fn add_apple_pay_flow_metrics( pub fn add_apple_pay_flow_metrics(
apple_pay_flow: &Option<domain::ApplePayFlow>, apple_pay_flow: &Option<domain::ApplePayFlow>,
connector: Option<String>, connector: Option<String>,
merchant_id: id_type::MerchantId, merchant_id: common_utils::id_type::MerchantId,
) { ) {
if let Some(flow) = apple_pay_flow { if let Some(flow) = apple_pay_flow {
match flow { match flow {
@ -818,7 +815,7 @@ pub fn add_apple_pay_payment_status_metrics(
payment_attempt_status: enums::AttemptStatus, payment_attempt_status: enums::AttemptStatus,
apple_pay_flow: Option<domain::ApplePayFlow>, apple_pay_flow: Option<domain::ApplePayFlow>,
connector: Option<String>, connector: Option<String>,
merchant_id: id_type::MerchantId, merchant_id: common_utils::id_type::MerchantId,
) { ) {
if payment_attempt_status == enums::AttemptStatus::Charged { if payment_attempt_status == enums::AttemptStatus::Charged {
if let Some(flow) = apple_pay_flow { if let Some(flow) = apple_pay_flow {

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE merchant_account DROP id;

View File

@ -0,0 +1,5 @@
-- Your SQL goes here
-- Adding a new column called `id` which will be the new primary key for v2
-- Note that even though this will be the new primary key, the v1 application would still fill in null values
ALTER TABLE merchant_account
ADD COLUMN id VARCHAR(64);

View File

@ -0,0 +1,16 @@
-- This file should undo anything in `up.sql`
-- The new primary key for v2 merchant account will be `id`
ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey;
-- In order to run this query, the merchant_id column should be unique and not null
-- We need to backfill the id, a simple strategy will be to copy the values of id to merchant_id
-- Query to update the merchant_id column with values of id
UPDATE merchant_account
SET merchant_id = id;
-- Note: This command might not run successfully for the existing table
-- This is because there will be some rows ( which are created via v2 application ) which will have id as empty
-- A backfill might be required to run this query
-- However if this is being run on a fresh database, this should succeed
ALTER TABLE merchant_account
ADD PRIMARY KEY (merchant_id);

View File

@ -0,0 +1,17 @@
-- Your SQL goes here
-- The new primary key for v2 merchant account will be `id`
ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey;
-- In order to make id as primary key, it should be unique and not null
-- We need to backfill the id, a simple strategy will be to copy the values of merchant_id to id
-- Query to update the id column with values of merchant_id
-- Note: This query will lock the table, so it should be run when there is no traffic
UPDATE merchant_account
SET id = merchant_id;
-- Note: This command might not run successfully for the existing table
-- This is because there will be some rows ( which are created via v1 application ) which will have id as empty
-- A backfill might be required to run this query
-- However if this is being run on a fresh database, this should succeed
ALTER TABLE merchant_account
ADD PRIMARY KEY (id);

View File

@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
ALTER TABLE merchant_account
ADD COLUMN merchant_id VARCHAR(64);

View File

@ -0,0 +1,4 @@
-- Your SQL goes here
-- Note: This query should not be run on higher environments as this leads to data loss
-- The application will work fine even without these queries not being run
ALTER TABLE merchant_account DROP merchant_id;