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:
parent
d0aef27f7b
commit
84a28e045b
@ -277,7 +277,7 @@ const refunding = ref(false);
|
|||||||
const refundModal = ref();
|
const refundModal = ref();
|
||||||
const selectedCharge = ref(null);
|
const selectedCharge = ref(null);
|
||||||
const refundType = ref("full");
|
const refundType = ref("full");
|
||||||
const refundTypes = ref(["full", "partial"]);
|
const refundTypes = ref(["full", "partial", "none"]);
|
||||||
const refundAmount = ref(0);
|
const refundAmount = ref(0);
|
||||||
const unprovision = ref(false);
|
const unprovision = ref(false);
|
||||||
|
|
||||||
|
|||||||
@ -135,6 +135,7 @@ pub async fn subscriptions(
|
|||||||
pub enum ChargeRefundAmount {
|
pub enum ChargeRefundAmount {
|
||||||
Full,
|
Full,
|
||||||
Partial { amount: u64 },
|
Partial { amount: u64 },
|
||||||
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -189,6 +190,7 @@ pub async fn refund_charge(
|
|||||||
let refund_amount = match body.0.amount {
|
let refund_amount = match body.0.amount {
|
||||||
ChargeRefundAmount::Full => refundable,
|
ChargeRefundAmount::Full => refundable,
|
||||||
ChargeRefundAmount::Partial { amount } => amount as i64,
|
ChargeRefundAmount::Partial { amount } => amount as i64,
|
||||||
|
ChargeRefundAmount::None => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if charge.status != ChargeStatus::Succeeded {
|
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(
|
return Err(ApiError::InvalidInput(
|
||||||
"You cannot refund more than the amount of the charge!"
|
"You cannot refund more than the amount of the charge!"
|
||||||
.to_string(),
|
.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 => {
|
PaymentPlatform::Stripe => {
|
||||||
if let Some(payment_platform_id) = charge
|
if let Some(payment_platform_id) =
|
||||||
.payment_platform_id
|
charge.payment_platform_id.and_then(|x| {
|
||||||
.and_then(|x| stripe::PaymentIntentId::from_str(&x).ok())
|
stripe::PaymentIntentId::from_str(&x).ok()
|
||||||
|
})
|
||||||
{
|
{
|
||||||
let mut metadata = HashMap::new();
|
let mut metadata = HashMap::new();
|
||||||
|
|
||||||
@ -236,7 +242,7 @@ pub async fn refund_charge(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
(
|
(
|
||||||
refund.id.to_string(),
|
Some(refund.id.to_string()),
|
||||||
refund
|
refund
|
||||||
.balance_transaction
|
.balance_transaction
|
||||||
.and_then(|x| x.into_object())
|
.and_then(|x| x.into_object())
|
||||||
@ -244,10 +250,12 @@ pub async fn refund_charge(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return Err(ApiError::InvalidInput(
|
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?;
|
let mut transaction = pool.begin().await?;
|
||||||
@ -266,7 +274,7 @@ pub async fn refund_charge(
|
|||||||
subscription_id: charge.subscription_id,
|
subscription_id: charge.subscription_id,
|
||||||
subscription_interval: charge.subscription_interval,
|
subscription_interval: charge.subscription_interval,
|
||||||
payment_platform: charge.payment_platform,
|
payment_platform: charge.payment_platform,
|
||||||
payment_platform_id: Some(id),
|
payment_platform_id: id,
|
||||||
parent_charge_id: Some(charge.id),
|
parent_charge_id: Some(charge.id),
|
||||||
net,
|
net,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user