Allow servers to be unprovisioned without issuing a refund (#3534)

* Allow servers to be unprovisioned without issuing a refund

for very specific weird circumstances where a server gets stuck/etc; useful for support

* still create a charge

* Fix compile
This commit is contained in:
Emma Alexia 2025-04-19 00:39:18 -04:00 committed by GitHub
parent d0aef27f7b
commit 84a28e045b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 40 deletions

View File

@ -277,7 +277,7 @@ const refunding = ref(false);
const refundModal = ref();
const selectedCharge = ref(null);
const refundType = ref("full");
const refundTypes = ref(["full", "partial"]);
const refundTypes = ref(["full", "partial", "none"]);
const refundAmount = ref(0);
const unprovision = ref(false);

View File

@ -135,6 +135,7 @@ pub async fn subscriptions(
pub enum ChargeRefundAmount {
Full,
Partial { amount: u64 },
None,
}
#[derive(Deserialize)]
@ -189,6 +190,7 @@ pub async fn refund_charge(
let refund_amount = match body.0.amount {
ChargeRefundAmount::Full => refundable,
ChargeRefundAmount::Partial { amount } => amount as i64,
ChargeRefundAmount::None => 0,
};
if charge.status != ChargeStatus::Succeeded {
@ -197,18 +199,22 @@ pub async fn refund_charge(
));
}
if (refundable - refund_amount) < 0 || refund_amount == 0 {
if (refundable - refund_amount) < 0 {
return Err(ApiError::InvalidInput(
"You cannot refund more than the amount of the charge!"
.to_string(),
));
}
let (id, net) = match charge.payment_platform {
let (id, net) = if refund_amount != 0 {
(None, None)
} else {
match charge.payment_platform {
PaymentPlatform::Stripe => {
if let Some(payment_platform_id) = charge
.payment_platform_id
.and_then(|x| stripe::PaymentIntentId::from_str(&x).ok())
if let Some(payment_platform_id) =
charge.payment_platform_id.and_then(|x| {
stripe::PaymentIntentId::from_str(&x).ok()
})
{
let mut metadata = HashMap::new();
@ -236,7 +242,7 @@ pub async fn refund_charge(
.await?;
(
refund.id.to_string(),
Some(refund.id.to_string()),
refund
.balance_transaction
.and_then(|x| x.into_object())
@ -244,10 +250,12 @@ pub async fn refund_charge(
)
} else {
return Err(ApiError::InvalidInput(
"Charge does not have attached payment id!".to_string(),
"Charge does not have attached payment id!"
.to_string(),
));
}
}
}
};
let mut transaction = pool.begin().await?;
@ -266,7 +274,7 @@ pub async fn refund_charge(
subscription_id: charge.subscription_id,
subscription_interval: charge.subscription_interval,
payment_platform: charge.payment_platform,
payment_platform_id: Some(id),
payment_platform_id: id,
parent_charge_id: Some(charge.id),
net,
}