Skip to content

Commit bbd2102

Browse files
feat(users): refactor ProdIntent to support product-type context and merchant-scope (#7638)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 203ae3e commit bbd2102

File tree

10 files changed

+51
-19
lines changed

10 files changed

+51
-19
lines changed

crates/api_models/src/user/dashboard_metadata.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use common_enums::CountryAlpha2;
1+
use common_enums::{CountryAlpha2, MerchantProductType};
22
use common_utils::{id_type, pii};
33
use masking::Secret;
44
use strum::EnumString;
@@ -103,6 +103,8 @@ pub struct ProdIntent {
103103
pub poc_contact: Option<String>,
104104
pub comments: Option<String>,
105105
pub is_completed: bool,
106+
#[serde(default)]
107+
pub product_type: MerchantProductType,
106108
}
107109

108110
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]

crates/common_enums/src/enums/accounts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use serde;
22
use utoipa::ToSchema;
33
#[derive(
4+
Copy,
45
Default,
56
Clone,
67
Debug,

crates/router/src/core/user.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,7 @@ pub async fn list_merchants_for_user_in_org(
29742974
.map(|merchant_account| user_api::UserMerchantAccountResponse {
29752975
merchant_name: merchant_account.merchant_name.clone(),
29762976
merchant_id: merchant_account.get_id().to_owned(),
2977-
product_type: merchant_account.product_type.clone(),
2977+
product_type: merchant_account.product_type,
29782978
version: merchant_account.version,
29792979
})
29802980
.collect::<Vec<_>>(),

crates/router/src/core/user/dashboard_metadata.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub async fn set_metadata(
3838
Ok(ApplicationResponse::StatusOk)
3939
}
4040

41-
#[cfg(feature = "v1")]
4241
pub async fn get_multiple_metadata(
4342
state: SessionState,
4443
user: UserFromToken,
@@ -462,7 +461,7 @@ async fn insert_metadata(
462461
pii::Email::from_str(inner_poc_email)
463462
.change_context(UserErrors::EmailParsingError)?;
464463
}
465-
let mut metadata = utils::insert_user_scoped_metadata_to_db(
464+
let mut metadata = utils::insert_merchant_scoped_metadata_to_db(
466465
state,
467466
user.user_id.clone(),
468467
user.merchant_id.clone(),
@@ -473,7 +472,7 @@ async fn insert_metadata(
473472
.await;
474473

475474
if utils::is_update_required(&metadata) {
476-
metadata = utils::update_user_scoped_metadata(
475+
metadata = utils::update_merchant_scoped_metadata(
477476
state,
478477
user.user_id.clone(),
479478
user.merchant_id.clone(),
@@ -500,7 +499,6 @@ async fn insert_metadata(
500499
EntityType::Merchant,
501500
)
502501
.await?;
503-
504502
let email_contents = email_types::BizEmailProd::new(
505503
state,
506504
data,
@@ -662,7 +660,6 @@ async fn fetch_metadata(
662660
Ok(dashboard_metadata)
663661
}
664662

665-
#[cfg(feature = "v1")]
666663
pub async fn backfill_metadata(
667664
state: &SessionState,
668665
user: &UserFromToken,
@@ -705,20 +702,26 @@ pub async fn backfill_metadata(
705702
return Ok(None);
706703
};
707704

705+
#[cfg(feature = "v1")]
706+
let processor_name = mca.connector_name.clone();
707+
708+
#[cfg(feature = "v2")]
709+
let processor_name = mca.connector_name.to_string().clone();
708710
Some(
709711
insert_metadata(
710712
state,
711713
user.to_owned(),
712714
DBEnum::StripeConnected,
713715
types::MetaData::StripeConnected(api::ProcessorConnected {
714716
processor_id: mca.get_id(),
715-
processor_name: mca.connector_name,
717+
processor_name,
716718
}),
717719
)
718720
.await,
719721
)
720722
.transpose()
721723
}
724+
722725
DBEnum::PaypalConnected => {
723726
let mca = if let Some(paypal_connected) = get_merchant_connector_account_by_name(
724727
state,
@@ -745,14 +748,19 @@ pub async fn backfill_metadata(
745748
return Ok(None);
746749
};
747750

751+
#[cfg(feature = "v1")]
752+
let processor_name = mca.connector_name.clone();
753+
754+
#[cfg(feature = "v2")]
755+
let processor_name = mca.connector_name.to_string().clone();
748756
Some(
749757
insert_metadata(
750758
state,
751759
user.to_owned(),
752760
DBEnum::PaypalConnected,
753761
types::MetaData::PaypalConnected(api::ProcessorConnected {
754762
processor_id: mca.get_id(),
755-
processor_name: mca.connector_name,
763+
processor_name,
756764
}),
757765
)
758766
.await,

crates/router/src/routes/app.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,12 @@ impl User {
21362136
),
21372137
);
21382138

2139+
route = route.service(
2140+
web::resource("/data")
2141+
.route(web::get().to(user::get_multiple_dashboard_metadata))
2142+
.route(web::post().to(user::set_dashboard_metadata)),
2143+
);
2144+
21392145
route
21402146
}
21412147
}

crates/router/src/routes/user.rs

-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ pub async fn set_dashboard_metadata(
197197
.await
198198
}
199199

200-
#[cfg(feature = "v1")]
201200
pub async fn get_multiple_dashboard_metadata(
202201
state: web::Data<AppState>,
203202
req: HttpRequest,

crates/router/src/services/email/assets/bizemailprod.html

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
<strong>Business Website:</strong>
105105
{business_website}
106106
</li>
107+
<li>
108+
<strong>Product Type:</strong>
109+
{product_type}
110+
</li>
107111
</ol>
108112
</td>
109113
</tr>

crates/router/src/services/email/types.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use api_models::user::dashboard_metadata::ProdIntent;
2-
use common_enums::EntityType;
2+
use common_enums::{EntityType, MerchantProductType};
33
use common_utils::{errors::CustomResult, pii, types::theme::EmailThemeConfig};
44
use error_stack::ResultExt;
55
use external_services::email::{EmailContents, EmailData, EmailError};
@@ -64,6 +64,7 @@ pub enum EmailBody {
6464
legal_business_name: String,
6565
business_location: String,
6666
business_website: String,
67+
product_type: MerchantProductType,
6768
},
6869
ReconActivation {
6970
user_name: String,
@@ -199,6 +200,7 @@ pub mod html {
199200
legal_business_name,
200201
business_location,
201202
business_website,
203+
product_type,
202204
} => {
203205
format!(
204206
include_str!("assets/bizemailprod.html"),
@@ -207,6 +209,7 @@ pub mod html {
207209
business_location = business_location,
208210
business_website = business_website,
209211
username = user_name,
212+
product_type = product_type
210213
)
211214
}
212215
EmailBody::ProFeatureRequest {
@@ -558,6 +561,7 @@ pub struct BizEmailProd {
558561
pub settings: std::sync::Arc<configs::Settings>,
559562
pub theme_id: Option<String>,
560563
pub theme_config: EmailThemeConfig,
564+
pub product_type: MerchantProductType,
561565
}
562566

563567
impl BizEmailProd {
@@ -582,6 +586,7 @@ impl BizEmailProd {
582586
business_website: data.business_website.unwrap_or_default(),
583587
theme_id,
584588
theme_config,
589+
product_type: data.product_type,
585590
})
586591
}
587592
}
@@ -595,6 +600,7 @@ impl EmailData for BizEmailProd {
595600
legal_business_name: self.legal_business_name.clone(),
596601
business_location: self.business_location.clone(),
597602
business_website: self.business_website.clone(),
603+
product_type: self.product_type,
598604
});
599605

600606
Ok(EmailContents {

crates/router/src/types/domain/user.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl NewUserMerchant {
417417
}
418418

419419
pub fn get_product_type(&self) -> Option<common_enums::MerchantProductType> {
420-
self.product_type.clone()
420+
self.product_type
421421
}
422422

423423
pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> {
@@ -703,11 +703,18 @@ impl TryFrom<UserMerchantCreateRequestWithToken> for NewUserMerchant {
703703
} else {
704704
id_type::MerchantId::new_from_unix_timestamp()
705705
};
706+
let (user_from_storage, user_merchant_create, user_from_token) = value;
706707
Ok(Self {
707708
merchant_id,
708-
company_name: Some(UserCompanyName::new(value.1.company_name.clone())?),
709-
product_type: value.1.product_type.clone(),
710-
new_organization: NewUserOrganization::from(value),
709+
company_name: Some(UserCompanyName::new(
710+
user_merchant_create.company_name.clone(),
711+
)?),
712+
product_type: user_merchant_create.product_type,
713+
new_organization: NewUserOrganization::from((
714+
user_from_storage,
715+
user_merchant_create,
716+
user_from_token,
717+
)),
711718
})
712719
}
713720
}

crates/router/src/utils/user/dashboard_metadata.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,9 @@ pub fn separate_metadata_type_based_on_scope(
218218
| DBEnum::SetupWoocomWebhook
219219
| DBEnum::OnboardingSurvey
220220
| DBEnum::IsMultipleConfiguration
221-
| DBEnum::ReconStatus => merchant_scoped.push(key),
222-
DBEnum::Feedback | DBEnum::ProdIntent | DBEnum::IsChangePasswordRequired => {
223-
user_scoped.push(key)
224-
}
221+
| DBEnum::ReconStatus
222+
| DBEnum::ProdIntent => merchant_scoped.push(key),
223+
DBEnum::Feedback | DBEnum::IsChangePasswordRequired => user_scoped.push(key),
225224
}
226225
}
227226
(merchant_scoped, user_scoped)

0 commit comments

Comments
 (0)