Skip to content

Commit 3c044ba

Browse files
committed
Add paymentfailed.service variable to PaymentFailed notification variant
1 parent dc907ae commit 3c044ba

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

apps/labrinth/src/models/v3/billing.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ pub enum ProductMetadata {
3333
},
3434
}
3535

36+
impl ProductMetadata {
37+
pub fn is_pyro(&self) -> bool {
38+
matches!(self, ProductMetadata::Pyro { .. })
39+
}
40+
41+
pub fn is_medal(&self) -> bool {
42+
matches!(self, ProductMetadata::Medal { .. })
43+
}
44+
45+
pub fn is_midas(&self) -> bool {
46+
matches!(self, ProductMetadata::Midas)
47+
}
48+
}
49+
3650
#[derive(Serialize, Deserialize)]
3751
pub struct ProductPrice {
3852
pub id: ProductPriceId,

apps/labrinth/src/models/v3/notifications.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub enum NotificationBody {
155155
},
156156
PaymentFailed {
157157
amount: String,
158+
service: String,
158159
},
159160
Unknown,
160161
}

apps/labrinth/src/queue/email/templates.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const VERIFYEMAIL_URL: &str = "verifyemail.url";
2323
const AUTHPROVIDER_NAME: &str = "authprovider.name";
2424
const EMAILCHANGED_NEW_EMAIL: &str = "emailchanged.new_email";
2525
const BILLING_URL: &str = "billing.url";
26+
2627
const PAYMENTFAILED_AMOUNT: &str = "paymentfailed.amount";
28+
const PAYMENTFAILED_SERVICE: &str = "paymentfailed.service";
2729

2830
const TEAMINVITE_INVITER_NAME: &str = "teaminvite.inviter.name";
2931
const TEAMINVITE_PROJECT_NAME: &str = "teaminvite.project.name";
@@ -373,7 +375,7 @@ async fn collect_template_variables(
373375
Ok(TemplateVariables::with_email(map, Some(to_email.clone())))
374376
}
375377

376-
NotificationBody::PaymentFailed { amount } => {
378+
NotificationBody::PaymentFailed { amount, service } => {
377379
let user =
378380
DBUser::get_id(n.user_id, exec, redis).await?.ok_or_else(
379381
|| DatabaseError::Database(sqlx::Error::RowNotFound),
@@ -388,6 +390,7 @@ async fn collect_template_variables(
388390
let mut map = HashMap::new();
389391
map.insert(USER_NAME, user.username);
390392
map.insert(PAYMENTFAILED_AMOUNT, amount.clone());
393+
map.insert(PAYMENTFAILED_SERVICE, service.clone());
391394
map.insert(BILLING_URL, url);
392395

393396
Ok(TemplateVariables::with_email(map, user.email))

apps/labrinth/src/routes/internal/billing.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,22 @@ pub async fn stripe_webhook(
24722472
NotificationBuilder {
24732473
body: NotificationBody::PaymentFailed {
24742474
amount: money.to_string(),
2475+
service: if metadata
2476+
.product_item
2477+
.metadata
2478+
.is_midas()
2479+
{
2480+
"Modrinth+"
2481+
} else if metadata
2482+
.product_item
2483+
.metadata
2484+
.is_pyro()
2485+
{
2486+
"Modrinth Servers"
2487+
} else {
2488+
"a Modrinth product"
2489+
}
2490+
.to_owned(),
24752491
},
24762492
}
24772493
.insert(metadata.user_item.id, &mut transaction, &redis)

0 commit comments

Comments
 (0)