Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Show discounted price on Pro plan billing card (#2695)

posthog-eu[bot]aba12e2082e2
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 0ae4e9ae3..bd9fe08ff 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -674,7 +674,10 @@
"spaceUpdatedSuccess": "Space updated successfully",
"ssoAuthenticationOnly": "Authentication is managed through Single Sign-On (SSO). Password management is not available.",
"startOfWeek": "Start of week",
+ "submit": "Submit",
+ "subscriptionCardAmountDiscount": "{amount} discount applied",
"subscriptionCardEndsOn": "Ends {date}",
+ "subscriptionCardPercentDiscount": "{percent}% discount applied",
"subscriptionCardPerMonth": "per month",
"subscriptionCardPerYear": "per year",
"subscriptionCardRenewsOn": "Renews {date}",
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx
index 5ad531953..8e5db523e 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/plan-card.tsx
@@ -13,7 +13,7 @@ export function PlanCardHeader({
return (
<div
className={cn(
- "flex @sm:flex-row flex-col items-start @sm:items-center gap-3 p-3",
+ "flex @sm:flex-row flex-col items-start gap-3 p-3",
className,
)}
{...props}
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsx
new file mode 100644
index 000000000..2806480a9
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.test.tsx
@@ -0,0 +1,73 @@
+import { describe, expect, it, vi } from "vitest";
+import { render, screen } from "@/test/test-utils";
+
+import { ProPlanCard } from "./pro-plan-card";
+
+// The card pulls in server actions and client-only hooks that aren't relevant
+// to the price rendering under test, so stub them out.
+vi.mock("@rallly/posthog/client", () => ({
+ posthog: { capture: vi.fn() },
+}));
+
+vi.mock("@/features/billing/actions", () => ({
+ openCustomerPortalAction: vi.fn(),
+}));
+
+vi.mock("@/lib/safe-action/client", () => ({
+ useSafeAction: () => ({ execute: vi.fn(), isExecuting: false }),
+}));
+
+vi.mock("@/lib/datetime/client", () => ({
+ useDateTimeConfig: () => ({ locale: "en" }),
+ useDateTime: () => ({ formatDateTime: () => "Jan 1, 2026" }),
+}));
+
+vi.mock("./manage-seats-dialog", () => ({
+ ManageSeatsDialog: () => null,
+}));
+
+const baseProps = {
+ amount: 800,
+ currency: "usd",
+ interval: "month" as const,
+ seats: 2,
+ usedSeats: 1,
+ status: "active" as const,
+ cancelAtPeriodEnd: false,
+ periodEnd: new Date("2026-01-01T00:00:00Z"),
+};
+
+describe("ProPlanCard", () => {
+ // Note: ICU interpolation isn't wired up in this render harness, so the
+ // discount note renders its raw template rather than an interpolated string.
+ // The price figures come from Intl.NumberFormat, so those are asserted exactly.
+
+ it("shows the full price when there is no discount", () => {
+ render(<ProPlanCard {...baseProps} />);
+
+ // amount (800) * seats (2) / 100 = $16.00, not struck through
+ const price = screen.getByText("$16.00");
+ expect(price).toBeInTheDocument();
+ expect(price).not.toHaveClass("line-through");
+ expect(screen.queryByText(/discount applied/)).not.toBeInTheDocument();
+ });
+
+ it("applies a percentage discount and shows the original price struck through", () => {
+ render(<ProPlanCard {...baseProps} discountPercentOff={50} />);
+
+ // Discounted total is shown as the headline price (16.00 - 50% = 8.00)
+ expect(screen.getByText("$8.00")).toBeInTheDocument();
+ // Original price is shown struck through
+ expect(screen.getByText("$16.00")).toHaveClass("line-through");
+ expect(screen.getByText(/discount applied/)).toBeInTheDocument();
+ });
+
+ it("applies a fixed-amount discount", () => {
+ render(<ProPlanCard {...baseProps} discountAmountOff={400} />);
+
+ // 1600 - 400 = 1200 -> $12.00
+ expect(screen.getByText("$12.00")).toBeInTheDocument();
+ expect(screen.getByText("$16.00")).toHaveClass("line-through");
+ expect(screen.getByText(/discount applied/)).toBeInTheDocument();
+ });
+});
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx
index 25eed16cf..357153d26 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/pro-plan-card.tsx
@@ -34,6 +34,8 @@ import {
export function ProPlanCard({
amount,
+ discountPercentOff,
+ discountAmountOff,
currency,
interval,
seats,
@@ -44,6 +46,8 @@ export function ProPlanCard({
className,
}: {
amount: number;
+ discountPercentOff?: number | null;
+ discountAmountOff?: number | null;
currency: string;
interval: BillingInterval;
seats: number;
@@ -57,11 +61,29 @@ export function ProPlanCard({
const { formatDateTime } = useDateTime();
const openCustomerPortal = useSafeAction(openCustomerPortalAction);
- // amount is the per-seat unit amount in the currency's minor unit
- const price = new Intl.NumberFormat(locale, {
- style: "currency",
- currency: currency.toUpperCase(),
- }).format((amount * seats) / 100);
+ const formatCurrency = (minorUnitAmount: number) =>
+ new Intl.NumberFormat(locale, {
+ style: "currency",
+ currency: currency.toUpperCase(),
+ }).format(minorUnitAmount / 100);
+
+ // amount is the per-seat unit amount in the currency's minor unit. Coupons
+ // and promotion codes are applied by Stripe at the invoice level, so we apply
+ // the stored discount here to reflect what the customer is actually charged.
+ const subtotal = amount * seats;
+ let discountedTotal = subtotal;
+ if (discountPercentOff) {
+ discountedTotal = Math.round(
+ discountedTotal * (1 - discountPercentOff / 100),
+ );
+ }
+ if (discountAmountOff) {
+ discountedTotal = Math.max(0, discountedTotal - discountAmountOff);
+ }
+ const hasDiscount = discountedTotal !== subtotal;
+
+ const price = formatCurrency(discountedTotal);
+ const originalPrice = formatCurrency(subtotal);
const date = formatDateTime(periodEnd, "date");
const endsAtPeriodEnd = status === "canceled" || cancelAtPeriodEnd;
@@ -104,7 +126,14 @@ export function ProPlanCard({
</PlanCardDescription>
</PlanCardContent>
<PlanCardPrice>
- <PlanCardPriceValue>{price}</PlanCardPriceValue>
+ <PlanCardPriceValue className="flex items-center @sm:justify-end gap-x-1.5">
+ {hasDiscount ? (
+ <span className="font-normal text-muted-foreground line-through">
+ {originalPrice}
+ </span>
+ ) : null}
+ <span>{price}</span>
+ </PlanCardPriceValue>
<PlanCardPriceDescription>
{interval === "month" ? (
<Trans i18nKey="subscriptionCardPerMonth" defaults="per month" />
@@ -112,6 +141,23 @@ export function ProPlanCard({
<Trans i18nKey="subscriptionCardPerYear" defaults="per year" />
)}
</PlanCardPriceDescription>
+ {hasDiscount ? (
+ <PlanCardPriceDescription className="text-green-600">
+ {discountPercentOff ? (
+ <Trans
+ i18nKey="subscriptionCardPercentDiscount"
+ defaults="{percent}% discount applied"
+ values={{ percent: discountPercentOff }}
+ />
+ ) : (
+ <Trans
+ i18nKey="subscriptionCardAmountDiscount"
+ defaults="{amount} discount applied"
+ values={{ amount: formatCurrency(discountAmountOff ?? 0) }}
+ />
+ )}
+ </PlanCardPriceDescription>
+ ) : null}
</PlanCardPrice>
</PlanCardHeader>
<PlanCardFooter>
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx
index 0531a8f20..ae5818ff7 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/page.tsx
@@ -110,6 +110,8 @@ export default async function BillingSettingsPage({
{subscription?.active ? (
<ProPlanCard
amount={subscription.amount}
+ discountPercentOff={subscription.discountPercentOff}
+ discountAmountOff={subscription.discountAmountOff}
currency={subscription.currency}
interval={subscription.interval}
seats={subscription.quantity}
diff --git a/apps/web/src/features/billing/data.ts b/apps/web/src/features/billing/data.ts
index 79a0d9f18..d06436a3d 100644
--- a/apps/web/src/features/billing/data.ts
+++ b/apps/web/src/features/billing/data.ts
@@ -28,6 +28,8 @@ export async function getSpaceSubscription(spaceId: string) {
quantity: subscription.quantity,
subscriptionItemId: subscription.subscriptionItemId,
amount: subscription.amount,
+ discountPercentOff: subscription.discountPercentOff,
+ discountAmountOff: subscription.discountAmountOff,
cancelAtPeriodEnd: subscription.cancelAtPeriodEnd,
currency: subscription.currency,
interval: subscription.interval,
diff --git a/apps/web/src/features/billing/webhook/mutations.ts b/apps/web/src/features/billing/webhook/mutations.ts
index 67778dfdc..aee951af6 100644
--- a/apps/web/src/features/billing/webhook/mutations.ts
+++ b/apps/web/src/features/billing/webhook/mutations.ts
@@ -218,8 +218,14 @@ async function onCustomerSubscriptionCreated(event: Stripe.Event) {
);
const isActive = isSubscriptionActive(subscription);
- const { priceId, currency, interval, amount } =
- getSubscriptionDetails(subscription);
+ const {
+ priceId,
+ currency,
+ interval,
+ amount,
+ discountPercentOff,
+ discountAmountOff,
+ } = getSubscriptionDetails(subscription);
const res = subscriptionMetadataSchema.safeParse(subscription.metadata);
@@ -253,6 +259,8 @@ async function onCustomerSubscriptionCreated(event: Stripe.Event) {
currency,
interval,
amount,
+ discountPercentOff,
+ discountAmountOff,
status: subscription.status,
createdAt: toDate(subscription.created),
periodStart: toDate(subscription.current_period_start),
@@ -270,6 +278,8 @@ async function onCustomerSubscriptionCreated(event: Stripe.Event) {
currency,
interval,
amount,
+ discountPercentOff,
+ discountAmountOff,
status: subscription.status,
createdAt: toDate(subscription.created),
periodStart: toDate(subscription.current_period_start),
@@ -405,8 +415,14 @@ async function onCustomerSubscriptionUpdated(event: Stripe.Event) {
);
const isActive = isSubscriptionActive(subscription);
- const { priceId, currency, interval, amount } =
- getSubscriptionDetails(subscription);
+ const {
+ priceId,
+ currency,
+ interval,
+ amount,
+ discountPercentOff,
+ discountAmountOff,
+ } = getSubscriptionDetails(subscription);
const res = subscriptionMetadataSchema.safeParse(subscription.metadata);
@@ -439,6 +455,8 @@ async function onCustomerSubscriptionUpdated(event: Stripe.Event) {
subscriptionItemId,
quantity,
amount,
+ discountPercentOff,
+ discountAmountOff,
status: subscription.status,
periodStart: toDate(subscription.current_period_start),
periodEnd: toDate(subscription.current_period_end),
@@ -455,6 +473,8 @@ async function onCustomerSubscriptionUpdated(event: Stripe.Event) {
subscriptionItemId,
quantity,
amount,
+ discountPercentOff,
+ discountAmountOff,
status: subscription.status,
createdAt: toDate(subscription.created),
periodStart: toDate(subscription.current_period_start),
diff --git a/apps/web/src/features/billing/webhook/utils.ts b/apps/web/src/features/billing/webhook/utils.ts
index 5c4119e61..4eb37b94a 100644
--- a/apps/web/src/features/billing/webhook/utils.ts
+++ b/apps/web/src/features/billing/webhook/utils.ts
@@ -43,10 +43,18 @@ export function getSubscriptionDetails(subscription: Stripe.Subscription) {
throw new Error(`Invalid interval: ${interval}`);
}
+ // Coupons and promotion codes are applied at the invoice level, so they are
+ // not reflected in the price's unit_amount. Capture the discount here so the
+ // billing UI can show the actual amount the customer is charged. Defaults to
+ // null so an ended discount clears the stored values on the next webhook.
+ const coupon = subscription.discount?.coupon;
+
return {
interval: intervalResult.data,
currency,
amount,
priceId: subscriptionItem.price.id,
+ discountPercentOff: coupon?.percent_off ?? null,
+ discountAmountOff: coupon?.amount_off ?? null,
};
}
diff --git a/packages/database/prisma/migrations/20260719120000_add_subscription_discount_columns/migration.sql b/packages/database/prisma/migrations/20260719120000_add_subscription_discount_columns/migration.sql
new file mode 100644
index 000000000..525ca8b34
--- /dev/null
+++ b/packages/database/prisma/migrations/20260719120000_add_subscription_discount_columns/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "subscriptions" ADD COLUMN "discount_amount_off" INTEGER,
+ADD COLUMN "discount_percent_off" DOUBLE PRECISION;
diff --git a/packages/database/prisma/models/billing.prisma b/packages/database/prisma/models/billing.prisma
index 0ec73fede..dd7f9b283 100644
--- a/packages/database/prisma/models/billing.prisma
+++ b/packages/database/prisma/models/billing.prisma
@@ -4,6 +4,8 @@ model Subscription {
quantity Int @default(1)
subscriptionItemId String @map("subscription_item_id")
amount Int
+ discountPercentOff Float? @map("discount_percent_off")
+ discountAmountOff Int? @map("discount_amount_off")
status SubscriptionStatus
active Boolean
currency String