Allow modification of failed charges on admin billing page (#4045)
* Allow modification of failed charges on admin billing page Allows cancelling a failed subscription and forcing another charge attempt * use addNotification
This commit is contained in:
parent
7dffb352d5
commit
ff88724d01
@ -58,6 +58,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</NewModal>
|
</NewModal>
|
||||||
|
<NewModal ref="modifyModal">
|
||||||
|
<template #title>
|
||||||
|
<span class="text-lg font-extrabold text-contrast">Modify charge</span>
|
||||||
|
</template>
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<label for="cancel" class="flex flex-col gap-1">
|
||||||
|
<span class="text-lg font-semibold text-contrast">
|
||||||
|
Cancel server
|
||||||
|
<span class="text-brand-red">*</span>
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
Whether or not the subscription should be cancelled. Submitting this as "true" will
|
||||||
|
cancel the subscription, while submitting it as "false" will force another charge
|
||||||
|
attempt to be made.
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<Toggle id="cancel" v-model="cancel" />
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<ButtonStyled color="brand">
|
||||||
|
<button :disabled="modifying" @click="modifyCharge">
|
||||||
|
<CheckIcon aria-hidden="true" />
|
||||||
|
Modify charge
|
||||||
|
</button>
|
||||||
|
</ButtonStyled>
|
||||||
|
<ButtonStyled>
|
||||||
|
<button @click="modifyModal.hide()">
|
||||||
|
<XIcon aria-hidden="true" />
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</ButtonStyled>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</NewModal>
|
||||||
<div class="page experimental-styles-within">
|
<div class="page experimental-styles-within">
|
||||||
<div
|
<div
|
||||||
class="mb-4 flex items-center justify-between border-0 border-b border-solid border-divider pb-4"
|
class="mb-4 flex items-center justify-between border-0 border-b border-solid border-divider pb-4"
|
||||||
@ -201,6 +236,12 @@
|
|||||||
Refund options
|
Refund options
|
||||||
</button>
|
</button>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
|
<ButtonStyled v-else-if="charge.status === 'failed'" color="red" color-fill="text">
|
||||||
|
<button @click="showModifyModal(subscription)">
|
||||||
|
<CurrencyIcon />
|
||||||
|
Modify charge
|
||||||
|
</button>
|
||||||
|
</ButtonStyled>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -234,7 +275,6 @@ import { products } from "~/generated/state.json";
|
|||||||
import ModrinthServersIcon from "~/components/ui/servers/ModrinthServersIcon.vue";
|
import ModrinthServersIcon from "~/components/ui/servers/ModrinthServersIcon.vue";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const data = useNuxtApp();
|
|
||||||
const vintl = useVIntl();
|
const vintl = useVIntl();
|
||||||
|
|
||||||
const { formatMessage } = vintl;
|
const { formatMessage } = vintl;
|
||||||
@ -304,6 +344,10 @@ const refundTypes = ref(["full", "partial", "none"]);
|
|||||||
const refundAmount = ref(0);
|
const refundAmount = ref(0);
|
||||||
const unprovision = ref(true);
|
const unprovision = ref(true);
|
||||||
|
|
||||||
|
const modifying = ref(false);
|
||||||
|
const modifyModal = ref();
|
||||||
|
const cancel = ref(false);
|
||||||
|
|
||||||
function showRefundModal(charge) {
|
function showRefundModal(charge) {
|
||||||
selectedCharge.value = charge;
|
selectedCharge.value = charge;
|
||||||
refundType.value = "full";
|
refundType.value = "full";
|
||||||
@ -312,6 +356,12 @@ function showRefundModal(charge) {
|
|||||||
refundModal.value.show();
|
refundModal.value.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showModifyModal(charge) {
|
||||||
|
selectedCharge.value = charge;
|
||||||
|
cancel.value = false;
|
||||||
|
modifyModal.value.show();
|
||||||
|
}
|
||||||
|
|
||||||
async function refundCharge() {
|
async function refundCharge() {
|
||||||
refunding.value = true;
|
refunding.value = true;
|
||||||
try {
|
try {
|
||||||
@ -327,8 +377,7 @@ async function refundCharge() {
|
|||||||
await refreshCharges();
|
await refreshCharges();
|
||||||
refundModal.value.hide();
|
refundModal.value.hide();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
data.$notify({
|
addNotification({
|
||||||
group: "main",
|
|
||||||
title: "Error refunding",
|
title: "Error refunding",
|
||||||
text: err.data?.description ?? err,
|
text: err.data?.description ?? err,
|
||||||
type: "error",
|
type: "error",
|
||||||
@ -337,6 +386,32 @@ async function refundCharge() {
|
|||||||
refunding.value = false;
|
refunding.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function modifyCharge() {
|
||||||
|
modifying.value = true;
|
||||||
|
try {
|
||||||
|
await useBaseFetch(`billing/subscription/${selectedCharge.value.id}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify({
|
||||||
|
cancelled: cancel.value,
|
||||||
|
}),
|
||||||
|
internal: true,
|
||||||
|
});
|
||||||
|
addNotification({
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
await refreshCharges();
|
||||||
|
} catch (err) {
|
||||||
|
addNotification({
|
||||||
|
title: "Error reattempting charge",
|
||||||
|
text: err.data?.description ?? err,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
modifying.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
const chargeStatuses = {
|
const chargeStatuses = {
|
||||||
open: {
|
open: {
|
||||||
color: "bg-blue",
|
color: "bg-blue",
|
||||||
|
|||||||
@ -276,7 +276,11 @@ pub async fn refund_charge(
|
|||||||
subscription_interval: charge.subscription_interval,
|
subscription_interval: charge.subscription_interval,
|
||||||
payment_platform: charge.payment_platform,
|
payment_platform: charge.payment_platform,
|
||||||
payment_platform_id: id,
|
payment_platform_id: id,
|
||||||
parent_charge_id: Some(charge.id),
|
parent_charge_id: if refund_amount != 0 {
|
||||||
|
Some(charge.id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
net,
|
net,
|
||||||
}
|
}
|
||||||
.upsert(&mut transaction)
|
.upsert(&mut transaction)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user