Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): split switch-to-yearly dialog copy into lines + surface charged-today amount (#13099)

Abhimanyu Yadav16f94ed90f1d
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
index 0cd62c1489..61df08c0fe 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
@@ -217,6 +217,8 @@ describe("YourPlanCard cycle toggle", () => {
billing_cycle: "monthly",
tier_costs: { PRO: 5000, MAX: 32000 },
tier_costs_yearly: { PRO: 51000, MAX: 326400 },
+ proration_credit_cents: 2500,
+ current_period_end: 1900000000,
has_active_stripe_subscription: true,
status: "active",
}),
@@ -233,15 +235,20 @@ describe("YourPlanCard cycle toggle", () => {
expect(
await screen.findByText(/Switch Pro to yearly billing\?/i),
).toBeDefined();
- expect(screen.getByText(/Save 15% with yearly billing\./i)).toBeDefined();
+ // Each line splits into a bold label span + regular value span, so we
+ // assert the two pieces separately.
+ expect(screen.getByText(/^Save 15% with yearly billing\.$/)).toBeDefined();
+ expect(screen.getByText("Pro yearly:")).toBeDefined();
expect(
- screen.getByText(
- /Pro is \$42\.50\/month when billed yearly, charged as \$510\.00\/year instead of \$600\.00\/year monthly\./i,
- ),
+ screen.getByText(/^\$510\.00\/year \(\$42\.50\/month\)\.$/),
).toBeDefined();
+ // 51000 yearly - 2500 proration credit = 48500 cents = $485.00 charged today.
+ expect(screen.getByText("Charged today:")).toBeDefined();
expect(
- screen.getByText(/charged the prorated difference immediately/i),
+ screen.getByText(/^\$485\.00 \(prorated from your monthly plan\)\.$/),
).toBeDefined();
+ expect(screen.getByText("Renews")).toBeDefined();
+ expect(screen.getByText(/^\$510\.00\/year on /)).toBeDefined();
expect(
screen.getByRole("button", { name: /switch to yearly/i }),
).toBeDefined();
@@ -270,15 +277,18 @@ describe("YourPlanCard cycle toggle", () => {
expect(
await screen.findByText(/Switch Max to yearly billing\?/i),
).toBeDefined();
+ expect(screen.getByText("Max yearly:")).toBeDefined();
expect(
- screen.getByText(
- /Max is \$272\.00\/month when billed yearly, charged as \$3,264\.00\/year instead of \$3,840\.00\/year monthly\./i,
- ),
+ screen.getByText(/^\$3,264\.00\/year \(\$272\.00\/month\)\.$/),
).toBeDefined();
+ // No proration_credit_cents in this fixture → falls back to generic
+ // "prorated difference today" line instead of an exact dollar amount.
expect(
- screen.getByText(
- /After this period, your plan renews yearly at \$3,264\.00\./i,
- ),
+ screen.getByText(/^You'll be charged the prorated difference today\.$/),
+ ).toBeDefined();
+ expect(screen.getByText("Renews")).toBeDefined();
+ expect(
+ screen.getByText(/^at \$3,264\.00\/year after this period\.$/),
).toBeDefined();
});
@@ -307,10 +317,12 @@ describe("YourPlanCard cycle toggle", () => {
).toBeDefined();
expect(
screen.getByText(
- /switch to monthly billing at the end of your current yearly period/i,
+ /^Switches to monthly at the end of your current yearly period\.$/,
),
).toBeDefined();
- expect(screen.getByText(/New monthly price: \$50\.00/)).toBeDefined();
+ expect(screen.getByText("New price:")).toBeDefined();
+ expect(screen.getByText(/^\$50\.00\/month\.$/)).toBeDefined();
+ expect(screen.getByText(/^No charge today\.$/)).toBeDefined();
});
it("falls back to the generic dialog title when prices are missing (NO_TIER-like)", async () => {
@@ -340,9 +352,12 @@ describe("YourPlanCard cycle toggle", () => {
).toBeDefined();
// No tier_costs / tier_costs_yearly in the payload — body falls back to
// proration-only copy without the savings/pricing lines.
+ expect(
+ screen.getByText(/^You'll be charged the prorated difference today\.$/),
+ ).toBeDefined();
expect(
screen.getByText(
- /charged the prorated difference immediately\. After this period, your plan renews on the new yearly cadence\./i,
+ /^Renews on the new yearly cadence after this period\.$/,
),
).toBeDefined();
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx
index fe2c4b3f4c..465209d6c7 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/SwitchCycleDialog.tsx
@@ -9,7 +9,7 @@ interface Props {
onOpenChange: (open: boolean) => void;
targetCycle: "monthly" | "yearly";
title?: string;
- body: string;
+ body: { label?: string; text: string }[];
isSaving: boolean;
onConfirm: () => void;
}
@@ -32,10 +32,26 @@ export function SwitchCycleDialog({
controlled={{ isOpen, set: onOpenChange }}
>
<Dialog.Content>
- <div className="flex flex-col gap-4">
- <Text variant="body" as="span" className="text-zinc-700">
- {body}
- </Text>
+ <div className="flex flex-col gap-2">
+ {body.map((line, index) => (
+ <div
+ key={`${index}-${line.label ?? ""}-${line.text}`}
+ className="flex flex-wrap gap-1"
+ >
+ {line.label ? (
+ <Text
+ variant="body"
+ as="span"
+ className="font-semibold text-zinc-700"
+ >
+ {line.label}
+ </Text>
+ ) : null}
+ <Text variant="body" as="span" className="text-zinc-700">
+ {line.text}
+ </Text>
+ </div>
+ ))}
</div>
<Dialog.Footer>
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts
index c0e66514ab..27da6ce9f1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/YourPlanCard/useYourPlanCard.ts
@@ -131,6 +131,14 @@ export function useYourPlanCard() {
const currentTierKey = effectiveTier ?? "NO_TIER";
const currentYearlyCents = tierCostsYearly[currentTierKey];
const currentMonthlyCents = tierCosts[currentTierKey];
+ // Stripe credits the unused portion of the user's current monthly invoice
+ // when switching to yearly with proration_behavior="always_invoice"; the
+ // backend computes the same value (monthly_cost * remaining / total) and
+ // exposes it on the status payload so we can show the actual charge today.
+ const prorationCreditCents = subscription.data?.proration_credit_cents ?? 0;
+ const currentPeriodEndMs = subscription.data?.current_period_end
+ ? subscription.data.current_period_end * 1000
+ : null;
const plan = subscription.data
? {
@@ -347,52 +355,84 @@ export function useYourPlanCard() {
: `Switch ${tierLabel} to monthly billing?`;
}
- function getDialogBody(): string {
- if (!pendingCycle) return "";
+ function getDialogBody(): { label?: string; text: string }[] {
+ if (!pendingCycle) return [];
+ const periodEndLabel = currentPeriodEndMs
+ ? formatShortDate(currentPeriodEndMs)
+ : null;
if (pendingCycle === "yearly") {
- const yearly =
- currentYearlyCents !== undefined ? formatCents(currentYearlyCents) : "";
const tierLabel = effectiveTier ? PLAN_LABEL[effectiveTier] : null;
- const prorationLine = [
- "You'll be charged the prorated difference immediately.",
- yearly
- ? `After this period, your plan renews yearly at ${yearly}.`
- : "After this period, your plan renews on the new yearly cadence.",
- ].join(" ");
- // Surface the yearly savings up front when we have both prices — the
- // 15% discount is the user's primary motivator for accepting the
- // prorated charge and shouldn't be buried.
- if (
+ // `<=` (not `<`) so a misconfigured 0%-savings yearly price still gets
+ // the explicit price breakdown rather than falling through to generic
+ // copy — the savings line itself is suppressed when savings == 0.
+ const hasPrices =
currentMonthlyCents !== undefined &&
currentYearlyCents !== undefined &&
currentMonthlyCents > 0 &&
- currentYearlyCents < currentMonthlyCents * 12
- ) {
- const annualMonthlyCents = currentMonthlyCents * 12;
- const savingsPercent = Math.round(
- ((annualMonthlyCents - currentYearlyCents) / annualMonthlyCents) *
- 100,
- );
- const monthlyEquivalent = formatCents(
- Math.round(currentYearlyCents / 12),
- );
- const annualMonthly = formatCents(annualMonthlyCents);
- const savingsLine = `Save ${savingsPercent}% with yearly billing.`;
- const pricingLine = tierLabel
- ? `${tierLabel} is ${monthlyEquivalent}/month when billed yearly, charged as ${yearly}/year instead of ${annualMonthly}/year monthly.`
- : `It's ${monthlyEquivalent}/month when billed yearly, charged as ${yearly}/year instead of ${annualMonthly}/year monthly.`;
- return [savingsLine, pricingLine, prorationLine].join(" ");
+ currentYearlyCents <= currentMonthlyCents * 12;
+ if (!hasPrices) {
+ return [
+ { text: "You'll be charged the prorated difference today." },
+ {
+ text:
+ currentYearlyCents !== undefined
+ ? `Renews at ${formatCents(currentYearlyCents)}/year after this period.`
+ : "Renews on the new yearly cadence after this period.",
+ },
+ ];
}
- return prorationLine;
+ const yearly = formatCents(currentYearlyCents!);
+ const monthlyEquivalent = formatCents(
+ Math.round(currentYearlyCents! / 12),
+ );
+ const savingsPercent = Math.round(
+ ((currentMonthlyCents! * 12 - currentYearlyCents!) /
+ (currentMonthlyCents! * 12)) *
+ 100,
+ );
+ // Net charge today = full yearly price minus the unused-monthly credit
+ // Stripe will apply. Only surface the exact amount when the backend
+ // returned a non-zero credit (admin-granted plans / no Stripe customer
+ // return 0 and we fall back to the generic line).
+ const netChargeCents = Math.max(
+ 0,
+ currentYearlyCents! - prorationCreditCents,
+ );
+ const chargedToday =
+ prorationCreditCents > 0
+ ? {
+ label: "Charged today:",
+ text: `${formatCents(netChargeCents)} (prorated from your monthly plan).`,
+ }
+ : { text: "You'll be charged the prorated difference today." };
+ const renews = periodEndLabel
+ ? { label: "Renews", text: `${yearly}/year on ${periodEndLabel}.` }
+ : { label: "Renews", text: `at ${yearly}/year after this period.` };
+ return [
+ savingsPercent > 0
+ ? { text: `Save ${savingsPercent}% with yearly billing.` }
+ : null,
+ {
+ label: tierLabel ? `${tierLabel} yearly:` : "Yearly:",
+ text: `${yearly}/year (${monthlyEquivalent}/month).`,
+ },
+ chargedToday,
+ renews,
+ ].filter(
+ (line): line is { label?: string; text: string } => line !== null,
+ );
}
const monthly =
currentMonthlyCents !== undefined ? formatCents(currentMonthlyCents) : "";
return [
- "Your plan will switch to monthly billing at the end of your current yearly period; no charge today.",
- monthly ? `New monthly price: ${monthly}.` : "",
- ]
- .filter(Boolean)
- .join(" ");
+ {
+ text: periodEndLabel
+ ? `Switches to monthly billing on ${periodEndLabel}.`
+ : "Switches to monthly at the end of your current yearly period.",
+ },
+ monthly ? { label: "New price:", text: `${monthly}/month.` } : null,
+ { text: "No charge today." },
+ ].filter((line): line is { label?: string; text: string } => line !== null);
}
function getTierUpgradeDialogBody(): string {