diff --git a/apps/frontend/src/pages/settings/billing/index.vue b/apps/frontend/src/pages/settings/billing/index.vue index 94852b1c..4b3fc7a8 100644 --- a/apps/frontend/src/pages/settings/billing/index.vue +++ b/apps/frontend/src/pages/settings/billing/index.vue @@ -361,7 +361,14 @@ " color="green" > - @@ -1098,7 +1105,7 @@ async function fetchCapacityStatuses(serverId, product) { } } -const resubscribePyro = async (subscriptionId) => { +const resubscribePyro = async (subscriptionId, wasSuspended) => { try { await useBaseFetch(`billing/subscription/${subscriptionId}`, { internal: true, @@ -1108,6 +1115,21 @@ const resubscribePyro = async (subscriptionId) => { }, }); await refresh(); + if (wasSuspended) { + data.$notify({ + group: "main", + title: "Resubscription request submitted", + text: "If the server is currently suspended, it may take up to 10 minutes for another charge attempt to be made.", + type: "success", + }); + } else { + data.$notify({ + group: "main", + title: "Success", + text: "Server subscription resubscribed successfully", + type: "success", + }); + } } catch { data.$notify({ group: "main", diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs index f2bfe584..b0dc2f58 100644 --- a/apps/labrinth/src/routes/internal/billing.rs +++ b/apps/labrinth/src/routes/internal/billing.rs @@ -16,7 +16,7 @@ use crate::queue::session::AuthQueue; use crate::routes::ApiError; use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web}; use ariadne::ids::base62_impl::{parse_base62, to_base62}; -use chrono::Utc; +use chrono::{Duration, Utc}; use rust_decimal::Decimal; use rust_decimal::prelude::ToPrimitive; use serde::Serialize; @@ -366,9 +366,12 @@ pub async fn edit_subscription( })?; if let Some(cancelled) = &edit_subscription.cancelled { - if open_charge.status != ChargeStatus::Open - && open_charge.status != ChargeStatus::Cancelled - { + if !matches!( + open_charge.status, + ChargeStatus::Open + | ChargeStatus::Cancelled + | ChargeStatus::Failed + ) { return Err(ApiError::InvalidInput( "You may not change the status of this subscription!" .to_string(), @@ -377,6 +380,9 @@ pub async fn edit_subscription( if *cancelled { open_charge.status = ChargeStatus::Cancelled; + } else if open_charge.status == ChargeStatus::Failed { + // Force another resubscription attempt + open_charge.last_attempt = Some(Utc::now() - Duration::days(2)); } else { open_charge.status = ChargeStatus::Open; }