Skip to content

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

feat: addressed review comments

=5b331d994ff9
diff --git a/frontend/src/layouts/OrganizationLayout/components/TrialPaymentFailedBanner/TrialPaymentFailedBanner.tsx b/frontend/src/layouts/OrganizationLayout/components/TrialPaymentFailedBanner/TrialPaymentFailedBanner.tsx
index bc07464cb8..3d05028bf2 100644
--- a/frontend/src/layouts/OrganizationLayout/components/TrialPaymentFailedBanner/TrialPaymentFailedBanner.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/TrialPaymentFailedBanner/TrialPaymentFailedBanner.tsx
@@ -32,19 +32,44 @@ const productLabel = (notice: SubscriptionPlanNotice) => {
return notice.trialPlanKey ? `${product} ${humanizeKey(notice.trialPlanKey)}` : product;
};
+enum NoticeCause {
+ PaymentActionRequired = "payment_action_required",
+ NoPaymentMethod = "no_payment_method",
+ PaymentProcessing = "payment_processing"
+}
+
const listFormatter = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
-const buildMessage = (notices: SubscriptionPlanNotice[]) => {
- const products = listFormatter.format(notices.map(productLabel));
+const listProducts = (notices: SubscriptionPlanNotice[]) =>
+ listFormatter.format(notices.map(productLabel));
+
+const buildFailureMessage = (notices: SubscriptionPlanNotice[]) => {
+ const products = listProducts(notices);
const accessEndsAt = format(
Math.min(...notices.map((notice) => new Date(notice.accessEndsAt).getTime())),
"MMM d"
);
const isUpgradeOnly = notices.every((notice) => notice.trialPlanKey);
+ const sharedCause = notices.every((notice) => notice.cause === notices[0].cause)
+ ? notices[0].cause
+ : undefined;
- return isUpgradeOnly
- ? `Your ${products} upgrade will end on ${accessEndsAt} due to a failed payment.`
- : `${products} access will be suspended on ${accessEndsAt} due to a failed payment.`;
+ const deadline = isUpgradeOnly
+ ? `Complete payment before ${accessEndsAt}, or you'll return to your current plan.`
+ : `Complete payment before ${accessEndsAt} to keep access.`;
+
+ if (sharedCause === NoticeCause.PaymentActionRequired) {
+ return `We couldn't charge your card for ${products}. ${deadline}`;
+ }
+ if (sharedCause === NoticeCause.NoPaymentMethod) {
+ return isUpgradeOnly
+ ? `There's no card on file for ${products}. Add one or complete payment before ${accessEndsAt}, or you'll return to your current plan.`
+ : `There's no card on file for ${products}. Add one or complete payment before ${accessEndsAt} to keep access.`;
+ }
+ if (sharedCause === null && isUpgradeOnly) {
+ return `We couldn't charge for your ${products} upgrade. ${deadline}`;
+ }
+ return `We're having trouble completing your ${products} subscription. ${deadline}`;
};
export const TrialPaymentFailedBanner = () => {
@@ -60,23 +85,39 @@ export const TrialPaymentFailedBanner = () => {
);
if (!notices.length) return null;
+ const processingNotices = notices.filter(
+ (notice) => notice.cause === NoticeCause.PaymentProcessing
+ );
+ const failedNotices = notices.filter((notice) => notice.cause !== NoticeCause.PaymentProcessing);
+ const processingMessage = processingNotices.length
+ ? `Your payment for ${listProducts(processingNotices)} is processing. Access continues meanwhile.`
+ : null;
+
// Billing lives on the root organization, and a sub-org role grants nothing there.
const canResolve =
isRootOrganization &&
permission.can(OrgPermissionBillingActions.Read, OrgPermissionSubjects.Billing) &&
permission.can(OrgPermissionBillingActions.ManageBilling, OrgPermissionSubjects.Billing);
+ // Paying again while a payment settles could charge twice.
+ const showPayButton = canResolve && failedNotices.length > 0 && !processingNotices.length;
+
+ if (!failedNotices.length) {
+ return <OrgAlertBanner role="status" isDismissible={false} text={processingMessage} />;
+ }
+
return (
<OrgAlertBanner
role="alert"
isDismissible={false}
text={
<>
- <span className="font-medium">Action needed:</span> {buildMessage(notices)}
+ <span className="font-medium">Action needed:</span> {buildFailureMessage(failedNotices)}
+ {processingMessage && ` ${processingMessage}`}
{!canResolve && " Ask an organization admin to update payment."}
</>
}
action={
- canResolve && (
+ showPayButton && (
<Link to="/organizations/$orgId/billing" params={{ orgId: currentOrg.id }}>
<Button variant="outline" size="xs">
Complete Payment
diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
index 022e08a8d4..ed02794542 100644
--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx
@@ -20,7 +20,8 @@ import {
useCreateBillingV2PortalSession,
useGetBillingV2Catalog,
useGetBillingV2Organizations,
- useGetBillingV2Overview
+ useGetBillingV2Overview,
+ useRefreshBillingV2Entitlements
} from "@app/hooks/api";
import { Overview } from "./components/Overview";
@@ -85,6 +86,7 @@ export const BillingV2Page = () => {
const createPortalSession = useCreateBillingV2PortalSession();
const addPaymentMethod = useAddBillingV2PaymentMethod();
const confirmTrialPayment = useConfirmBillingV2TrialPayment();
+ const refreshEntitlements = useRefreshBillingV2Entitlements();
// More than one organization means the server decided this caller may switch: an instance admin on
// self-hosted, where one licence spans every org on the box. Cloud is bounded to the logged-in root
@@ -109,7 +111,7 @@ export const BillingV2Page = () => {
type: "success",
text: "Subscription started. It may take a moment to appear here."
});
- refetch();
+ refreshEntitlements.mutate({ orgId: selectedOrgId });
} else if (checkout === "canceled") {
createNotification({ type: "info", text: "Checkout was canceled." });
}
@@ -220,7 +222,10 @@ export const BillingV2Page = () => {
}
window.open(trialApprovalUrl, "_blank", "noopener,noreferrer");
setTrialApproval(null);
- refetch();
+ const orgIdAtApproval = selectedOrgId;
+ window.addEventListener("focus", () => refreshEntitlements.mutate({ orgId: orgIdAtApproval }), {
+ once: true
+ });
};
// Billing name/email and address are edited in the Stripe billing portal.