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

fix(users): Added merchant name is list merchants (#3289)

Rachit Naithani8a354f42295a
diff --git a/crates/api_models/src/user.rs b/crates/api_models/src/user.rs
index d666dfc3bf..07909a3578 100644
--- a/crates/api_models/src/user.rs
+++ b/crates/api_models/src/user.rs
@@ -1,4 +1,4 @@
-use common_utils::pii;
+use common_utils::{crypto::OptionalEncryptableName, pii};
use masking::Secret;
use crate::user_role::UserStatus;
@@ -133,3 +133,9 @@ pub type VerifyEmailResponse = DashboardEntryResponse;
pub struct SendVerifyEmailRequest {
pub email: pii::Email,
}
+
+#[derive(Debug, serde::Serialize)]
+pub struct UserMerchantAccount {
+ pub merchant_id: String,
+ pub merchant_name: OptionalEncryptableName,
+}
diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs
index 6fb76bd75b..532f8208ec 100644
--- a/crates/router/src/core/user.rs
+++ b/crates/router/src/core/user.rs
@@ -640,9 +640,23 @@ pub async fn create_merchant_account(
pub async fn list_merchant_ids_for_user(
state: AppState,
user: auth::UserFromToken,
-) -> UserResponse<Vec<String>> {
+) -> UserResponse<Vec<user_api::UserMerchantAccount>> {
+ let merchant_ids = utils::user_role::get_merchant_ids_for_user(&state, &user.user_id).await?;
+
+ let merchant_accounts = state
+ .store
+ .list_multiple_merchant_accounts(merchant_ids)
+ .await
+ .change_context(UserErrors::InternalServerError)?;
+
Ok(ApplicationResponse::Json(
- utils::user_role::get_merchant_ids_for_user(state, &user.user_id).await?,
+ merchant_accounts
+ .into_iter()
+ .map(|acc| user_api::UserMerchantAccount {
+ merchant_id: acc.merchant_id,
+ merchant_name: acc.merchant_name,
+ })
+ .collect(),
))
}
diff --git a/crates/router/src/utils/user_role.rs b/crates/router/src/utils/user_role.rs
index 4449338402..c474a82981 100644
--- a/crates/router/src/utils/user_role.rs
+++ b/crates/router/src/utils/user_role.rs
@@ -18,7 +18,7 @@ pub fn is_internal_role(role_id: &str) -> bool {
|| role_id == consts::user_role::ROLE_ID_INTERNAL_VIEW_ONLY_USER
}
-pub async fn get_merchant_ids_for_user(state: AppState, user_id: &str) -> UserResult<Vec<String>> {
+pub async fn get_merchant_ids_for_user(state: &AppState, user_id: &str) -> UserResult<Vec<String>> {
Ok(state
.store
.list_user_roles_by_user_id(user_id)