Skip to content

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

refactor(user): move internal user merchant id to config (#15337)

Mani Chandra93a54cac7125
diff --git a/config/config.example.toml b/config/config.example.toml
index 46fa021cec..d441628f7d 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -683,6 +683,7 @@ totp_issuer_name = "Hyperswitch" # Name of the issuer for TOTP
base_url = "" # Base url used for user specific redirects and emails
force_two_factor_auth = false # Whether to force two factor authentication for all users
force_cookies = false # Whether to use only cookies for JWT extraction and authentication
+internal_merchant_id = "juspay000" # Merchant id of the internal merchant that internal users are created under
# idle_session_timeout_in_secs = 900 # When set, signs Dashboard users out after this many seconds without a request
email_token_expiry_in_secs = 86400 # Number of seconds for which email links (verify, reset password, invite, etc.) stay valid
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index cb1d8b063b..a9c9136605 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -251,6 +251,7 @@ totp_issuer_name = "Hyperswitch Integ"
base_url = "https://integ.hyperswitch.io"
force_two_factor_auth = false
force_cookies = false
+internal_merchant_id = "juspay000"
[frm]
enabled = true
diff --git a/config/deployments/production.toml b/config/deployments/production.toml
index 300dfb0f7d..4b04121dab 100644
--- a/config/deployments/production.toml
+++ b/config/deployments/production.toml
@@ -264,6 +264,7 @@ totp_issuer_name = "Hyperswitch Production"
base_url = "https://live.hyperswitch.io"
force_two_factor_auth = true
force_cookies = false
+internal_merchant_id = "juspay000"
[frm]
enabled = false
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index 6c4528dc62..717b5a5a10 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -260,6 +260,7 @@ totp_issuer_name = "Hyperswitch Sandbox"
base_url = "https://app.hyperswitch.io"
force_two_factor_auth = false
force_cookies = false
+internal_merchant_id = "juspay000"
[debit_routing_config]
supported_currencies = "USD"
diff --git a/config/development.toml b/config/development.toml
index 88ecbb7db7..8dd6c4427a 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -583,6 +583,7 @@ totp_issuer_name = "Hyperswitch Dev"
base_url = "http://localhost:8080"
force_two_factor_auth = false
force_cookies = false
+internal_merchant_id = "juspay000"
[oidc.key.k1]
kid = "" # Key ID used to identify the signing key in JWKS and JWT headers (Generate using: openssl rand -hex 16)
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 7b4707b3d1..6f25ea7299 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -128,6 +128,7 @@ totp_issuer_name = "Hyperswitch"
base_url = "http://localhost:9000"
force_two_factor_auth = false
force_cookies = false
+internal_merchant_id = "juspay000"
[oidc.key.k1]
kid = "" # Key ID used to identify the signing key in JWKS and JWT headers (Generate using: openssl rand -hex 16)
diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs
index 1b9a9735d8..adf5ecdf0d 100644
--- a/crates/common_utils/src/id_type/merchant.rs
+++ b/crates/common_utils/src/id_type/merchant.rs
@@ -59,13 +59,6 @@ impl MerchantId {
Self(length_id)
}
- /// Get a merchant id for internal use only
- pub fn get_internal_user_merchant_id(merchant_id: &str) -> Self {
- let alphanumeric_id = AlphaNumericId::new_unchecked(merchant_id.to_string());
- let length_id = LengthId::new_unchecked(alphanumeric_id);
- Self(length_id)
- }
-
/// Create a new merchant_id from unix timestamp, of the format `merchant_{timestamp}`
pub fn new_from_unix_timestamp() -> Self {
let merchant_id = format!("merchant_{}", date_time::now_unix_timestamp());
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index fe7b81730b..8299e9d33a 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -1021,6 +1021,7 @@ pub struct UserSettings {
pub force_two_factor_auth: bool,
pub force_cookies: bool,
pub idle_session_timeout_in_secs: Option<u32>,
+ pub internal_merchant_id: common_utils::id_type::MerchantId,
pub email_token_expiry_in_secs: u64,
}
diff --git a/crates/router/src/consts/user_role.rs b/crates/router/src/consts/user_role.rs
index 1ddb80226d..b0c173b651 100644
--- a/crates/router/src/consts/user_role.rs
+++ b/crates/router/src/consts/user_role.rs
@@ -13,7 +13,6 @@ pub const ROLE_ID_PROFILE_DEVELOPER: &str = "profile_developer";
pub const ROLE_ID_PROFILE_OPERATOR: &str = "profile_operator";
pub const ROLE_ID_PROFILE_CUSTOMER_SUPPORT: &str = "profile_customer_support";
-pub const INTERNAL_USER_MERCHANT_ID: &str = "juspay000";
pub const MAX_ROLE_NAME_LENGTH: usize = 64;
pub const ROLE_ID_RECON_MERCHANT_ADMIN: &str = "recon_merchant_admin";
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs
index 9273d4a428..09dd49c628 100644
--- a/crates/router/src/core/user.rs
+++ b/crates/router/src/core/user.rs
@@ -1648,9 +1648,7 @@ pub async fn create_internal_user(
|| Err(UserErrors::InvalidRoleId),
)?;
- let internal_merchant_id = common_utils::id_type::MerchantId::get_internal_user_merchant_id(
- consts::user_role::INTERNAL_USER_MERCHANT_ID,
- );
+ let internal_merchant_id = state.conf.user.internal_merchant_id.clone();
let key_store_master_key = state.store.get_master_key().to_vec().into();
let key_store = state
.accounts_store
@@ -1687,7 +1685,11 @@ pub async fn create_internal_user(
}
})?;
- let new_user = domain::NewUser::try_from((request, internal_merchant.organization_id.clone()))?;
+ let new_user = domain::NewUser::try_from((
+ request,
+ internal_merchant.organization_id.clone(),
+ internal_merchant_id.clone(),
+ ))?;
let mut store_user: storage_user::UserNew = new_user.clone().try_into()?;
store_user.set_is_verified(true);
diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rs
index eff5fafbe8..acbae53af2 100644
--- a/crates/router/src/types/domain/user.rs
+++ b/crates/router/src/types/domain/user.rs
@@ -693,16 +693,23 @@ impl TryFrom<user_api::SignUpWithMerchantIdRequest> for NewUserMerchant {
}
}
-impl TryFrom<(user_api::CreateInternalUserRequest, id_type::OrganizationId)> for NewUserMerchant {
+impl
+ TryFrom<(
+ user_api::CreateInternalUserRequest,
+ id_type::OrganizationId,
+ id_type::MerchantId,
+ )> for NewUserMerchant
+{
type Error = error_stack::Report<UserErrors>;
fn try_from(
- value: (user_api::CreateInternalUserRequest, id_type::OrganizationId),
+ (request, org_id, merchant_id): (
+ user_api::CreateInternalUserRequest,
+ id_type::OrganizationId,
+ id_type::MerchantId,
+ ),
) -> UserResult<Self> {
- let merchant_id = id_type::MerchantId::get_internal_user_merchant_id(
- consts::user_role::INTERNAL_USER_MERCHANT_ID,
- );
- let new_organization = NewUserOrganization::from(value);
+ let new_organization = NewUserOrganization::from((request, org_id));
Ok(Self {
company_name: None,
@@ -1093,11 +1100,21 @@ impl TryFrom<user_api::ConnectAccountRequest> for NewUser {
}
}
-impl TryFrom<(user_api::CreateInternalUserRequest, id_type::OrganizationId)> for NewUser {
+impl
+ TryFrom<(
+ user_api::CreateInternalUserRequest,
+ id_type::OrganizationId,
+ id_type::MerchantId,
+ )> for NewUser
+{
type Error = error_stack::Report<UserErrors>;
fn try_from(
- (value, org_id): (user_api::CreateInternalUserRequest, id_type::OrganizationId),
+ (value, org_id, merchant_id): (
+ user_api::CreateInternalUserRequest,
+ id_type::OrganizationId,
+ id_type::MerchantId,
+ ),
) -> UserResult<Self> {
let email = value.email.clone().try_into()?;
let name = UserName::new(value.name.clone())?;
@@ -1105,7 +1122,7 @@ impl TryFrom<(user_api::CreateInternalUserRequest, id_type::OrganizationId)> for
password: UserPassword::new(value.password.clone())?,
is_temporary: false,
};
- let new_merchant = NewUserMerchant::try_from((value, org_id))?;
+ let new_merchant = NewUserMerchant::try_from((value, org_id, merchant_id))?;
Ok(Self {
name,