Skip to content

Commit 81483af

Browse files
committed
Enhance subscription handling by adding subscription_plan_key to response and updating plan key formatting in Pricing Plans page
1 parent b614002 commit 81483af

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,31 @@ async def has_active_subscription(
7272
return {
7373
"has_access": False,
7474
"subscription_status": None,
75+
"subscription_plan_key": None,
7576
"paddle_subscription_id": None,
7677
"organisation_created_by": created_by,
7778
}
7879

79-
status = await get_subscription_status(subscription_id=sub_id, client=client)
80+
paddle_client = client or get_paddle_client()
81+
subscription = await asyncio.to_thread(
82+
paddle_client.subscriptions.get,
83+
sub_id,
84+
)
85+
status = getattr(subscription, "status", None)
86+
if status:
87+
status = str(status).lower()
8088
has_access = status in ACTIVE_SUBSCRIPTION_STATUSES if status else False
89+
subscription_custom_data = _normalize_custom_data(
90+
getattr(subscription, "custom_data", None)
91+
)
92+
plan_key = subscription_custom_data.get("plan_key")
93+
if plan_key is not None:
94+
plan_key = str(plan_key)
8195
logger.info(f"Subscription {sub_id} - status: {status}, has_access: {has_access}, active_statuses: {ACTIVE_SUBSCRIPTION_STATUSES}")
8296
return {
8397
"has_access": has_access,
8498
"subscription_status": status,
99+
"subscription_plan_key": plan_key,
85100
"paddle_subscription_id": sub_id,
86101
"organisation_created_by": created_by,
87102
}
@@ -417,4 +432,4 @@ async def retry_with_backoff(
417432
)
418433
await asyncio.sleep(delay)
419434

420-
raise last_exception
435+
raise last_exception

src/frontend/src/pages/SettingsPage/pages/PricingPlansPage/index.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@ import ForwardedIconComponent from "@/components/common/genericIconComponent";
55
import Loading from "@/components/ui/loading";
66
import { api } from "@/controllers/API/api";
77
import { getURL } from "@/controllers/API/helpers/constants";
8+
import planConfigData from "../../../../../public/plan_config.json";
89

910
type BillingAccessResponse = {
1011
has_access?: boolean;
1112
subscription_status?: string | null;
13+
subscription_plan_key?: string | null;
1214
paddle_subscription_id?: string | null;
1315
};
1416

17+
const PLAN_NAME_BY_KEY = Object.fromEntries(
18+
(planConfigData.plans ?? []).map((plan) => [
19+
String(plan?.paddle?.plan_key ?? "").toLowerCase(),
20+
String(plan?.name ?? "").trim(),
21+
]),
22+
) as Record<string, string>;
23+
24+
function formatPlanKey(planKey: string): string {
25+
return planKey
26+
.replace(/[_-]+/g, " ")
27+
.replace(/\s+/g, " ")
28+
.trim()
29+
.replace(/\b\w/g, (char) => char.toUpperCase());
30+
}
31+
1532
function SelectedPlan({ billing }: { billing: BillingAccessResponse | null }) {
1633
const selectedPlan = useMemo(() => {
1734
if (!billing?.has_access) return "Free";
1835

19-
const status = (billing.subscription_status ?? "").toLowerCase();
20-
if (status === "trialing") return "Paid (Trialing)";
36+
const planKey = (billing.subscription_plan_key ?? "").toLowerCase();
37+
const planName = PLAN_NAME_BY_KEY[planKey];
38+
if (planName) return planName;
39+
if (planKey) return formatPlanKey(planKey);
2140

22-
return "Paid";
41+
const status = (billing.subscription_status ?? "").toLowerCase();
42+
return status === "trialing" ? "Paid (Trialing)" : "Paid";
2343
}, [billing]);
2444

2545
return (

0 commit comments

Comments
 (0)