Skip to content

Commit 78a0df2

Browse files
committed
Enhance subscription update preview with quantity checks and billing messages
1 parent d863b85 commit 78a0df2

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

src/backend/base/langflow/services/paddle/subscriptions.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ async def preview_subscription_update(
792792
paddle_client.subscriptions.get,
793793
subscription_id,
794794
)
795+
current_quantity = subscription.items[0].quantity
796+
795797
status = str(getattr(subscription, "status", "")).lower()
796798

797799
items = await _build_updated_items(
@@ -815,12 +817,18 @@ async def preview_subscription_update(
815817

816818
plan_price_map = _get_enabled_plan_monthly_price_map()
817819

818-
proration_mode = _determine_proration_mode(
819-
current_plan_key=current_plan_key,
820-
new_plan_key=new_plan_key,
821-
plan_price_map=plan_price_map,
822-
status=status,
823-
)
820+
if new_quantity > current_quantity and not new_price_id:
821+
if status == "trialing":
822+
proration_mode = SubscriptionProrationBillingMode.DoNotBill
823+
else:
824+
proration_mode = SubscriptionProrationBillingMode.ProratedImmediately
825+
else:
826+
proration_mode = _determine_proration_mode(
827+
current_plan_key=current_plan_key,
828+
new_plan_key=new_plan_key,
829+
plan_price_map=plan_price_map,
830+
status=status,
831+
)
824832

825833
operation = PreviewUpdateSubscription(
826834
items=[

src/frontend/src/pages/ChangePlansPage/index.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type BillingAccessResponse = {
2626
subscription_seats?: number | null;
2727
seats?: number | null;
2828
quantity?: number | null;
29+
next_billed_at?: string | null;
2930
};
3031

3132
type PaddlePricesResponse = Record<string, string>;
@@ -207,6 +208,25 @@ export default function ChangePlansPage() {
207208
setPendingSeats((prev) => prev + 1);
208209
};
209210

211+
function buildPreviewMessage(previewData: any, nextBillingDate?: string): string | null {
212+
if (!previewData) return null;
213+
214+
const hasImmediateCharge = Boolean(previewData?.immediate_transaction);
215+
const amount = extractPreviewAmount(previewData);
216+
217+
if (hasImmediateCharge && amount !== null) {
218+
return `You will be charged ${toCurrency(amount)} today.`;
219+
}
220+
221+
if (nextBillingDate) {
222+
const date = new Date(nextBillingDate);
223+
const formatted = date.toLocaleDateString(undefined, { dateStyle: "medium" });
224+
return `Your plan will change on ${formatted}. No charge today.`;
225+
}
226+
227+
return "This change will take effect on your next billing date. No charge today.";
228+
}
229+
210230
const handlePlanSelect = async (planKey: string) => {
211231
if (mode !== "plan" || actionsBlocked || planKey === currentPlanKey) {
212232
return;
@@ -232,7 +252,7 @@ export default function ChangePlansPage() {
232252
const amount = extractPreviewAmount(preview);
233253
setPreviewData(preview);
234254
setPreviewMessage(
235-
amount === null ? null : `You will be charged ${toCurrency(amount)} today.`,
255+
buildPreviewMessage(preview, billing?.next_billed_at)
236256
);
237257
setSummaryMessage(
238258
`Plan change: ${currentPlanKey || "current"}${planKey} (${currentSeats} seats).`,
@@ -257,7 +277,7 @@ export default function ChangePlansPage() {
257277
const amount = extractPreviewAmount(preview);
258278
setPreviewData(preview);
259279
setPreviewMessage(
260-
amount === null ? null : `You will be charged ${toCurrency(amount)} today.`,
280+
buildPreviewMessage(preview, billing?.next_billed_at)
261281
);
262282
} else {
263283
const selected = STATIC_PLANS.find((plan) => plan.key === selectedPlanKey);
@@ -275,7 +295,7 @@ export default function ChangePlansPage() {
275295
const amount = extractPreviewAmount(preview);
276296
setPreviewData(preview);
277297
setPreviewMessage(
278-
amount === null ? null : `You will be charged ${toCurrency(amount)} today.`,
298+
buildPreviewMessage(preview, billing?.next_billed_at)
279299
);
280300
setSummaryMessage(
281301
`Plan change: ${currentPlanKey || "current"}${selectedPlanKey} (${currentSeats} seats).`,

0 commit comments

Comments
 (0)