You've already forked AstralRinth
forked from didirus/AstralRinth
Fix resubscription of servers with failed payments (#3696)
* Fix resubscription of servers with failed payments Resolves MOD-55 * run fix
This commit is contained in:
@@ -361,7 +361,14 @@
|
|||||||
"
|
"
|
||||||
color="green"
|
color="green"
|
||||||
>
|
>
|
||||||
<button @click="resubscribePyro(subscription.id)">
|
<button
|
||||||
|
@click="
|
||||||
|
resubscribePyro(
|
||||||
|
subscription.id,
|
||||||
|
$dayjs(getPyroCharge(subscription).due).isBefore($dayjs()),
|
||||||
|
)
|
||||||
|
"
|
||||||
|
>
|
||||||
Resubscribe <RightArrowIcon />
|
Resubscribe <RightArrowIcon />
|
||||||
</button>
|
</button>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
@@ -1098,7 +1105,7 @@ async function fetchCapacityStatuses(serverId, product) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resubscribePyro = async (subscriptionId) => {
|
const resubscribePyro = async (subscriptionId, wasSuspended) => {
|
||||||
try {
|
try {
|
||||||
await useBaseFetch(`billing/subscription/${subscriptionId}`, {
|
await useBaseFetch(`billing/subscription/${subscriptionId}`, {
|
||||||
internal: true,
|
internal: true,
|
||||||
@@ -1108,6 +1115,21 @@ const resubscribePyro = async (subscriptionId) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
await refresh();
|
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 {
|
} catch {
|
||||||
data.$notify({
|
data.$notify({
|
||||||
group: "main",
|
group: "main",
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use crate::queue::session::AuthQueue;
|
|||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||||
use ariadne::ids::base62_impl::{parse_base62, to_base62};
|
use ariadne::ids::base62_impl::{parse_base62, to_base62};
|
||||||
use chrono::Utc;
|
use chrono::{Duration, Utc};
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use rust_decimal::prelude::ToPrimitive;
|
use rust_decimal::prelude::ToPrimitive;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -366,9 +366,12 @@ pub async fn edit_subscription(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(cancelled) = &edit_subscription.cancelled {
|
if let Some(cancelled) = &edit_subscription.cancelled {
|
||||||
if open_charge.status != ChargeStatus::Open
|
if !matches!(
|
||||||
&& open_charge.status != ChargeStatus::Cancelled
|
open_charge.status,
|
||||||
{
|
ChargeStatus::Open
|
||||||
|
| ChargeStatus::Cancelled
|
||||||
|
| ChargeStatus::Failed
|
||||||
|
) {
|
||||||
return Err(ApiError::InvalidInput(
|
return Err(ApiError::InvalidInput(
|
||||||
"You may not change the status of this subscription!"
|
"You may not change the status of this subscription!"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
@@ -377,6 +380,9 @@ pub async fn edit_subscription(
|
|||||||
|
|
||||||
if *cancelled {
|
if *cancelled {
|
||||||
open_charge.status = ChargeStatus::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 {
|
} else {
|
||||||
open_charge.status = ChargeStatus::Open;
|
open_charge.status = ChargeStatus::Open;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user