Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: fixed the last deletion with cooldown

=f4b23a490648
diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.ts
index daefe58062..acf5a5c728 100644
--- a/backend/src/services/license-client/license-client-types.ts
+++ b/backend/src/services/license-client/license-client-types.ts
@@ -217,11 +217,13 @@ export const sessionResponseSchema = z
})
.passthrough();
-// Checkout either needs the customer to complete a Stripe Checkout (checkout_created) or is applied
-// directly to an existing subscription (subscription_updated).
+// Result of a checkout / add / remove / commitment change. Checkout either needs the customer to
+// complete a Stripe Checkout (checkout_created) or is applied directly to an existing subscription
+// (subscription_updated). Removing the last product cancels the whole subscription
+// (subscription_canceled).
export const checkoutResultSchema = z
.object({
- outcome: z.enum(["checkout_created", "subscription_updated"]),
+ outcome: z.enum(["checkout_created", "subscription_updated", "subscription_canceled"]),
checkoutUrl: z.string().optional(),
subscriptionId: z.string().optional()
})
diff --git a/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx b/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx
index 6a3475344e..58adab277a 100644
--- a/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx
@@ -15,13 +15,19 @@ import {
} from "@app/components/v3";
import {
BillingV2CatalogProduct,
- useCancelBillingV2Subscription,
useGetBillingV2Overview,
usePreviewBillingV2Change,
useRemoveBillingV2Product
} from "@app/hooks/api";
-import { fmtMoney } from "../billing-v2-format";
+import { dimAnnualCommitted, fmtMoney } from "../billing-v2-format";
+
+// Removing the last product cancels the whole subscription (handled by the remove endpoint). The
+// unused-time wording depends on whether the plan carries a minimum (annual) commitment.
+const COMMITMENT_MESSAGE =
+ "This plan includes a minimum commitment, so any unused time isn't credited or refunded. Access ends when your commitment period closes.";
+const CREDIT_MESSAGE =
+ "Any remaining credits will be retained on your account and applied to future charges.";
type Props = {
orgId: string;
@@ -46,11 +52,13 @@ export const RemoveProductModal = ({ orgId, product, onClose, onRemoved }: Props
(entitlement) => entitlement.entitled
).length;
const isOnlyProduct = overviewReady && entitledProductCount === 1;
- const periodEndDate = overview?.entitlements[product.id]?.renewsOn ?? null;
+ // A minimum (annual) commitment means unused time is not credited/refunded on removal.
+ const hasCommitment = (overview?.entitlements[product.id]?.dimensions ?? []).some(
+ dimAnnualCommitted
+ );
const preview = usePreviewBillingV2Change();
const removeProduct = useRemoveBillingV2Product();
- const cancelSubscription = useCancelBillingV2Subscription();
// Preview the prorated credit once when the dialog opens, so the user confirms against real numbers.
// The last-product case can't be removed (it cancels instead), and previewing it would also 409, so
@@ -69,7 +77,9 @@ export const RemoveProductModal = ({ orgId, product, onClose, onRemoved }: Props
await removeProduct.mutateAsync({ orgId, productId: product.id });
createNotification({
type: "success",
- text: `${product.name} will be removed. It may take a moment to update here.`
+ text: isOnlyProduct
+ ? "Your subscription will be canceled. It may take a moment to update here."
+ : `${product.name} will be removed. It may take a moment to update here.`
});
onRemoved();
} catch (err) {
@@ -80,28 +90,7 @@ export const RemoveProductModal = ({ orgId, product, onClose, onRemoved }: Props
}
};
- const handleCancel = async () => {
- try {
- await cancelSubscription.mutateAsync({ orgId });
- createNotification({
- type: "success",
- text: "Your subscription will be canceled at the end of the current billing period."
- });
- onRemoved();
- } catch (err) {
- createNotification({
- type: "error",
- text: getServerMessage(err) ?? "Failed to cancel your subscription."
- });
- }
- };
-
if (isOnlyProduct) {
- let periodClause = "at the end of your current billing period";
- if (periodEndDate) {
- periodClause = `on ${periodEndDate}`;
- }
-
return (
<AlertDialog
open
@@ -118,17 +107,17 @@ export const RemoveProductModal = ({ orgId, product, onClose, onRemoved }: Props
</AlertDialogMedia>
<AlertDialogTitle>Cancel your subscription?</AlertDialogTitle>
<AlertDialogDescription>
- {product.name} is the only product on your subscription, so it cannot be removed on
- its own. Canceling ends your whole subscription {periodClause}. You keep access until
- then.
+ {product.name} is the only product on your subscription, so removing it ends your
+ subscription. {hasCommitment ? COMMITMENT_MESSAGE : CREDIT_MESSAGE}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Keep subscription</AlertDialogCancel>
<AlertDialogAction
variant="danger"
- isDisabled={cancelSubscription.isPending}
- onClick={handleCancel}
+ isDisabled={removeProduct.isPending}
+ onClick={handleRemove}
+ isPending={removeProduct.isPending}
>
Cancel subscription
</AlertDialogAction>