Skip to content

Fix resubscription of servers with failed payments #3696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions apps/frontend/src/pages/settings/billing/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,14 @@
"
color="green"
>
<button @click="resubscribePyro(subscription.id)">
<button
@click="
resubscribePyro(
subscription.id,
$dayjs(getPyroCharge(subscription).due).isBefore($dayjs()),
)
"
>
Resubscribe <RightArrowIcon />
</button>
</ButtonStyled>
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down
14 changes: 10 additions & 4 deletions apps/labrinth/src/routes/internal/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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;
}
Expand Down
Loading