From 7223c2b19761e0ff3ab8bf77048d483647c3bc15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Talbot?= <108630700+fetchfern@users.noreply.github.com> Date: Mon, 2 Jun 2025 01:13:06 -0400 Subject: [PATCH] Include region in user subscription metadata (#3733) --- apps/labrinth/src/models/v3/billing.rs | 2 +- apps/labrinth/src/routes/internal/billing.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/labrinth/src/models/v3/billing.rs b/apps/labrinth/src/models/v3/billing.rs index 9c46675ac..2757a7fc9 100644 --- a/apps/labrinth/src/models/v3/billing.rs +++ b/apps/labrinth/src/models/v3/billing.rs @@ -145,7 +145,7 @@ impl SubscriptionStatus { #[derive(Serialize, Deserialize)] #[serde(tag = "type", rename_all = "kebab-case")] pub enum SubscriptionMetadata { - Pyro { id: String }, + Pyro { id: String, region: Option }, } #[derive(Serialize, Deserialize)] diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs index 39b0a4767..05e30224a 100644 --- a/apps/labrinth/src/routes/internal/billing.rs +++ b/apps/labrinth/src/routes/internal/billing.rs @@ -954,17 +954,19 @@ pub async fn active_servers( pub server_id: String, pub price_id: crate::models::ids::ProductPriceId, pub interval: PriceDuration, + pub region: Option, } let server_ids = servers .into_iter() .filter_map(|x| { x.metadata.as_ref().map(|metadata| match metadata { - SubscriptionMetadata::Pyro { id } => ActiveServer { + SubscriptionMetadata::Pyro { id, region } => ActiveServer { user_id: x.user_id.into(), server_id: id.clone(), price_id: x.price_id.into(), interval: x.interval, + region: region.clone(), }, }) }) @@ -1764,8 +1766,10 @@ pub async fn stripe_webhook( { let client = reqwest::Client::new(); - if let Some(SubscriptionMetadata::Pyro { id }) = - &subscription.metadata + if let Some(SubscriptionMetadata::Pyro { + id, + region: _, + }) = &subscription.metadata { client .post(format!( @@ -1880,6 +1884,7 @@ pub async fn stripe_webhook( subscription.metadata = Some(SubscriptionMetadata::Pyro { id: res.uuid, + region: server_region, }); } } @@ -2240,7 +2245,7 @@ pub async fn index_subscriptions(pool: PgPool, redis: RedisPool) { true } ProductMetadata::Pyro { .. } => { - if let Some(SubscriptionMetadata::Pyro { id }) = + if let Some(SubscriptionMetadata::Pyro { id, region: _ }) = &subscription.metadata { let res = reqwest::Client::new()