basel00omar Claude Opus 4.8 commited on
Commit
1d5dce6
ยท
1 Parent(s): 0b21dd2

feat(billing): free first project per tool, retire Starter tier (3 tiers)

Browse files

Three product changes requested:

1. Free first project per tool on sign-up. Every new (unsubscribed) user now
gets ONE free project per tool for their whole lifetime, before subscribing.
utils/usage.py: added lifetime_usage() and a free-project branch in
project_entitlement (free_base=1 when base==0 and not admin). billing.py now
derives can_create / project_limit from project_entitlement (single source of
truth) and exposes free_projects.

2. Retired the 50 AED Starter tier -> only 3 paid tiers remain (Professional,
Business, Studio). plans_catalog now excludes tier 1, and /checkout rejects
tier 1 with a 400. PLANS[1] is kept only so existing Starter subs still resolve.

3. Landing / About / Dashboard copy: "1st month (2 projects) free" -> "Start your
1st project for free"; free card shows "Your 1st project free / per tool";
paid cards relabelled TIER 1-3; Dashboard start-bar now shows the create form
to users who still have their free project and only prompts to subscribe (to a
plan, from 120 AED) once it's used โ€” it no longer checks out the retired tier 1.

Frontend builds clean; new-user entitlement verified (free_left=1, can_create) on
all three tools.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

api/billing.py CHANGED
@@ -113,8 +113,12 @@ async def get_subscription_details(feature: str = Query("qto"), current_user: di
113
  pass
114
 
115
  is_admin = role == "admin"
116
- # Consumable model: create if there's monthly room OR an unused add-on credit.
117
- can_create = is_admin or (usage_projects < plan.projects) or (extra_projects > 0)
 
 
 
 
118
 
119
  return {
120
  "plan_name": plan.name,
@@ -122,7 +126,8 @@ async def get_subscription_details(feature: str = Query("qto"), current_user: di
122
  "subscription_status": sub.get("status") if sub else "inactive",
123
  "current_period_end": sub.get("current_period_end") if sub else None,
124
  "extra_projects": extra_projects,
125
- "project_limit": plan.projects + extra_projects,
 
126
  "can_create": can_create,
127
  "monthly_base": plan.projects,
128
  "has_had_trial": has_had_trial,
@@ -139,7 +144,7 @@ async def get_subscription_details(feature: str = Query("qto"), current_user: di
139
  "projects_limit": p.projects,
140
  "ai_calls": p.ai_calls,
141
  "exports": p.exports
142
- } for tier, p in PLANS.items() if tier > 0
143
  ]
144
  }
145
 
@@ -152,6 +157,9 @@ async def get_checkout_url(
152
  try:
153
  # Map tier back to int if it's a digit
154
  req_tier = int(tier) if tier.isdigit() else tier
 
 
 
155
  url = create_checkout_session(current_user, req_tier, feature)
156
  return {"checkout_url": url}
157
  except HTTPException:
 
113
  pass
114
 
115
  is_admin = role == "admin"
116
+ # Single source of truth for entitlement (monthly room OR add-on credit OR
117
+ # the one-time free project every new user gets before subscribing).
118
+ from utils.usage import project_entitlement
119
+ ent = project_entitlement({"id": user_id, "role": role}, feature)
120
+ free_left = ent.get("free_left", 0)
121
+ can_create = ent["can_create"]
122
 
123
  return {
124
  "plan_name": plan.name,
 
126
  "subscription_status": sub.get("status") if sub else "inactive",
127
  "current_period_end": sub.get("current_period_end") if sub else None,
128
  "extra_projects": extra_projects,
129
+ "free_projects": free_left,
130
+ "project_limit": plan.projects + extra_projects + free_left,
131
  "can_create": can_create,
132
  "monthly_base": plan.projects,
133
  "has_had_trial": has_had_trial,
 
144
  "projects_limit": p.projects,
145
  "ai_calls": p.ai_calls,
146
  "exports": p.exports
147
+ } for tier, p in PLANS.items() if tier > 1 # tier 1 (Starter) retired -> 3 paid tiers
148
  ]
149
  }
150
 
 
157
  try:
158
  # Map tier back to int if it's a digit
159
  req_tier = int(tier) if tier.isdigit() else tier
160
+ # Starter (tier 1, 50 AED) has been retired โ€” only 3 paid tiers remain.
161
+ if req_tier == 1:
162
+ raise HTTPException(status_code=400, detail="The Starter plan is no longer available. Please choose Professional, Business or Studio.")
163
  url = create_checkout_session(current_user, req_tier, feature)
164
  return {"checkout_url": url}
165
  except HTTPException:
frontend/src/components/About.jsx CHANGED
@@ -63,7 +63,7 @@ export default function About({ isArabic, onNavigate }) {
63
  ];
64
 
65
  const plans = [
66
- ['Starter', '1', t('project / month', 'ู…ุดุฑูˆุน / ุดู‡ุฑ')],
67
  ['Professional', '3', t('projects / month', 'ู…ุดุงุฑูŠุน / ุดู‡ุฑ')],
68
  ['Business', '8', t('projects / month', 'ู…ุดุงุฑูŠุน / ุดู‡ุฑ')],
69
  ['Studio', '20', t('projects / month', 'ู…ุดุงุฑูŠุน / ุดู‡ุฑ')],
@@ -145,8 +145,8 @@ export default function About({ isArabic, onNavigate }) {
145
  {/* Plans */}
146
  <h2 style={h2}>{t('Plans', 'ุงู„ุจุงู‚ุงุช')}</h2>
147
  <p style={{ ...p, margin: '4px 0 16px', fontSize: '0.9rem' }}>
148
- {t('Each tool is sold independently across four monthly tiers, plus a one-time โ€œextra projectโ€ add-on. The first subscription includes 2 free projects in the first month โ€” cancellable anytime.',
149
- 'ูƒู„ ุฃุฏุงุฉ ุชูุจุงุน ู…ุณุชู‚ู„ุฉ ุนุจุฑ ุฃุฑุจุน ุจุงู‚ุงุช ุดู‡ุฑูŠุฉุŒ ุจุงู„ุฅุถุงูุฉ ู„ู…ุดุฑูˆุน ุฅุถุงููŠ ู„ู…ุฑุฉ ูˆุงุญุฏุฉ. ุฃูˆู„ ุงุดุชุฑุงูƒ ูŠุดู…ู„ ู…ุดุฑูˆุนูŠู† ู…ุฌุงู†ุงู‹ ููŠ ุงู„ุดู‡ุฑ ุงู„ุฃูˆู„ โ€” ู‚ุงุจู„ ู„ู„ุฅู„ุบุงุก ููŠ ุฃูŠ ูˆู‚ุช.')}
150
  </p>
151
  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))', gap: 14, marginBottom: 32 }}>
152
  {plans.map(([name, n, unit]) => (
 
63
  ];
64
 
65
  const plans = [
66
+ [t('Free', 'ู…ุฌุงู†ูŠ'), '1', t('1st project / tool', 'ู…ุดุฑูˆุน ุฃูˆู„ / ุฃุฏุงุฉ')],
67
  ['Professional', '3', t('projects / month', 'ู…ุดุงุฑูŠุน / ุดู‡ุฑ')],
68
  ['Business', '8', t('projects / month', 'ู…ุดุงุฑูŠุน / ุดู‡ุฑ')],
69
  ['Studio', '20', t('projects / month', 'ู…ุดุงุฑูŠุน / ุดู‡ุฑ')],
 
145
  {/* Plans */}
146
  <h2 style={h2}>{t('Plans', 'ุงู„ุจุงู‚ุงุช')}</h2>
147
  <p style={{ ...p, margin: '4px 0 16px', fontSize: '0.9rem' }}>
148
+ {t('Each tool is sold independently across three monthly tiers, plus a one-time โ€œextra projectโ€ add-on. Every new user gets their first project free on each tool โ€” no subscription needed to start.',
149
+ 'ูƒู„ ุฃุฏุงุฉ ุชูุจุงุน ู…ุณุชู‚ู„ุฉ ุนุจุฑ ุซู„ุงุซ ุจุงู‚ุงุช ุดู‡ุฑูŠุฉุŒ ุจุงู„ุฅุถุงูุฉ ู„ู…ุดุฑูˆุน ุฅุถุงููŠ ู„ู…ุฑุฉ ูˆุงุญุฏุฉ. ูƒู„ ู…ุณุชุฎุฏู… ุฌุฏูŠุฏ ุจูŠุงุฎุฏ ู…ุดุฑูˆุนู‡ ุงู„ุฃูˆู„ ู…ุฌุงู†ุงู‹ ุนู„ู‰ ูƒู„ ุฃุฏุงุฉ โ€” ู…ู† ุบูŠุฑ ุงุดุชุฑุงูƒ.')}
150
  </p>
151
  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))', gap: 14, marginBottom: 32 }}>
152
  {plans.map(([name, n, unit]) => (
frontend/src/components/Dashboard.jsx CHANGED
@@ -459,14 +459,14 @@ export default function Dashboard({ token, isArabic, onSelectProject, onNavigate
459
 
460
  {/* Start Project Bar */}
461
  <div style={{ marginTop: '5px' }}>
462
- {!isAdmin && details && details.plan_tier === 0 ? (
463
  <button
464
- onClick={() => handleCheckout(1, 'qto')}
465
  style={{ width: '100%', padding: '10px', backgroundColor: 'var(--success)', color: 'white', border: 'none', borderRadius: '6px', fontWeight: 'bold', fontSize: '0.85rem', cursor: 'pointer', boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)' }}
466
  >
467
- {details?.has_had_trial ? (isArabic ? 'ุงุดุชุฑูƒ ููŠ ุจุงู‚ุฉ Starter' : 'Subscribe to Starter Tier') : (isArabic ? 'ุงุดุชุฑูƒ ู„ู…ุดุฑูˆุนูŠู† ู…ุฌุงู†ุงู‹ ุจุงู„ุดู‡ุฑ ุงู„ุฃูˆู„!' : 'Subscribe for 2 free projects in 1st month!')}
468
  <div style={{ fontSize: '0.7rem', marginTop: '3px', fontWeight: 'normal' }}>
469
- {details?.has_had_trial ? (isArabic ? '50 ุฏุฑู‡ู… ุดู‡ุฑูŠุงู‹' : '50 AED / month') : (isArabic ? '(ูŠู…ูƒู†ูƒ ุงู„ุฅู„ุบุงุก ููŠ ุฃูŠ ูˆู‚ุชุŒ ุจุฏูˆู† ุฑุณูˆู…!)' : '(Cancel anytime, no charges applied!)')}
470
  </div>
471
  </button>
472
  ) : (!isAdmin && details && details.can_create === false) ? (
@@ -625,14 +625,14 @@ export default function Dashboard({ token, isArabic, onSelectProject, onNavigate
625
 
626
  {/* Start Project Bar */}
627
  <div style={{ marginTop: '5px' }}>
628
- {!isAdmin && programmeAccess && programmeAccess.plan_tier === 0 ? (
629
  <button
630
- onClick={() => handleCheckout(1, 'programme')}
631
  style={{ width: '100%', padding: '10px', backgroundColor: 'var(--success)', color: 'white', border: 'none', borderRadius: '6px', fontWeight: 'bold', fontSize: '0.85rem', cursor: 'pointer', boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)' }}
632
  >
633
- {programmeAccess?.has_had_trial ? (isArabic ? 'ุงุดุชุฑูƒ ููŠ ุจุงู‚ุฉ Starter' : 'Subscribe to Starter Tier') : (isArabic ? 'ุงุดุชุฑูƒ ู„ู…ุดุฑูˆุนูŠู† ู…ุฌุงู†ุงู‹ ุจุงู„ุดู‡ุฑ ุงู„ุฃูˆู„!' : 'Subscribe for 2 free projects in 1st month!')}
634
  <div style={{ fontSize: '0.7rem', marginTop: '3px', fontWeight: 'normal' }}>
635
- {programmeAccess?.has_had_trial ? (isArabic ? '50 ุฏุฑู‡ู… ุดู‡ุฑูŠุงู‹' : '50 AED / month') : (isArabic ? '(ูŠู…ูƒู†ูƒ ุงู„ุฅู„ุบุงุก ููŠ ุฃูŠ ูˆู‚ุชุŒ ุจุฏูˆู† ุฑุณูˆู…!)' : '(Cancel anytime, no charges applied!)')}
636
  </div>
637
  </button>
638
  ) : (!isAdmin && programmeAccess && !programmeAccess.can_create) ? (
@@ -795,14 +795,14 @@ export default function Dashboard({ token, isArabic, onSelectProject, onNavigate
795
 
796
  {/* Start Project Bar */}
797
  <div style={{ marginTop: '5px' }}>
798
- {!isAdmin && cashflowAccess && cashflowAccess.plan_tier === 0 ? (
799
  <button
800
- onClick={() => handleCheckout(1, 'cashflow')}
801
  style={{ width: '100%', padding: '10px', backgroundColor: 'var(--success)', color: 'white', border: 'none', borderRadius: '6px', fontWeight: 'bold', fontSize: '0.85rem', cursor: 'pointer', boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)' }}
802
  >
803
- {cashflowAccess?.has_had_trial ? (isArabic ? 'ุงุดุชุฑูƒ ููŠ ุจุงู‚ุฉ Starter' : 'Subscribe to Starter Tier') : (isArabic ? 'ุงุดุชุฑูƒ ู„ู…ุดุฑูˆุนูŠู† ู…ุฌุงู†ุงู‹ ุจุงู„ุดู‡ุฑ ุงู„ุฃูˆู„!' : 'Subscribe for 2 free projects in 1st month!')}
804
  <div style={{ fontSize: '0.7rem', marginTop: '3px', fontWeight: 'normal' }}>
805
- {cashflowAccess?.has_had_trial ? (isArabic ? '50 ุฏุฑู‡ู… ุดู‡ุฑูŠุงู‹' : '50 AED / month') : (isArabic ? '(ูŠู…ูƒู†ูƒ ุงู„ุฅู„ุบุงุก ููŠ ุฃูŠ ูˆู‚ุชุŒ ุจุฏูˆู† ุฑุณูˆู…!)' : '(Cancel anytime, no charges applied!)')}
806
  </div>
807
  </button>
808
  ) : (!isAdmin && cashflowAccess && !cashflowAccess.can_create) ? (
 
459
 
460
  {/* Start Project Bar */}
461
  <div style={{ marginTop: '5px' }}>
462
+ {!isAdmin && details && details.plan_tier === 0 && !details.can_create ? (
463
  <button
464
+ onClick={() => handleCheckout(2, 'qto')}
465
  style={{ width: '100%', padding: '10px', backgroundColor: 'var(--success)', color: 'white', border: 'none', borderRadius: '6px', fontWeight: 'bold', fontSize: '0.85rem', cursor: 'pointer', boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)' }}
466
  >
467
+ {isArabic ? 'ุงุดุชุฑูƒ ููŠ ุจุงู‚ุฉ' : 'Subscribe to a plan'}
468
  <div style={{ fontSize: '0.7rem', marginTop: '3px', fontWeight: 'normal' }}>
469
+ {isArabic ? 'ู…ู† 120 ุฏุฑู‡ู… ุดู‡ุฑูŠุงู‹ โ€” 3 ู…ุดุงุฑูŠุน' : 'from 120 AED / month โ€” 3 projects'}
470
  </div>
471
  </button>
472
  ) : (!isAdmin && details && details.can_create === false) ? (
 
625
 
626
  {/* Start Project Bar */}
627
  <div style={{ marginTop: '5px' }}>
628
+ {!isAdmin && programmeAccess && programmeAccess.plan_tier === 0 && !programmeAccess.can_create ? (
629
  <button
630
+ onClick={() => handleCheckout(2, 'programme')}
631
  style={{ width: '100%', padding: '10px', backgroundColor: 'var(--success)', color: 'white', border: 'none', borderRadius: '6px', fontWeight: 'bold', fontSize: '0.85rem', cursor: 'pointer', boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)' }}
632
  >
633
+ {isArabic ? 'ุงุดุชุฑูƒ ููŠ ุจุงู‚ุฉ' : 'Subscribe to a plan'}
634
  <div style={{ fontSize: '0.7rem', marginTop: '3px', fontWeight: 'normal' }}>
635
+ {isArabic ? 'ู…ู† 120 ุฏุฑู‡ู… ุดู‡ุฑูŠุงู‹ โ€” 3 ู…ุดุงุฑูŠุน' : 'from 120 AED / month โ€” 3 projects'}
636
  </div>
637
  </button>
638
  ) : (!isAdmin && programmeAccess && !programmeAccess.can_create) ? (
 
795
 
796
  {/* Start Project Bar */}
797
  <div style={{ marginTop: '5px' }}>
798
+ {!isAdmin && cashflowAccess && cashflowAccess.plan_tier === 0 && !cashflowAccess.can_create ? (
799
  <button
800
+ onClick={() => handleCheckout(2, 'cashflow')}
801
  style={{ width: '100%', padding: '10px', backgroundColor: 'var(--success)', color: 'white', border: 'none', borderRadius: '6px', fontWeight: 'bold', fontSize: '0.85rem', cursor: 'pointer', boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)' }}
802
  >
803
+ {isArabic ? 'ุงุดุชุฑูƒ ููŠ ุจุงู‚ุฉ' : 'Subscribe to a plan'}
804
  <div style={{ fontSize: '0.7rem', marginTop: '3px', fontWeight: 'normal' }}>
805
+ {isArabic ? 'ู…ู† 120 ุฏุฑู‡ู… ุดู‡ุฑูŠุงู‹ โ€” 3 ู…ุดุงุฑูŠุน' : 'from 120 AED / month โ€” 3 projects'}
806
  </div>
807
  </button>
808
  ) : (!isAdmin && cashflowAccess && !cashflowAccess.can_create) ? (
frontend/src/components/LandingPage.jsx CHANGED
@@ -114,9 +114,9 @@ export default function LandingPage({ isArabic, setIsArabic, onGetStarted }) {
114
 
115
  <button className="btn btn-primary" onClick={onGetStarted} style={{ padding: '12px 35px', fontSize: '1.05rem', fontWeight: 700 }}>
116
  {isArabic ? (
117
- <>ุงุจุฏุฃ ุดู‡ุฑูƒ ุงู„ุฃูˆู„ (ู…ุดุฑูˆุนูŠู†) <span style={{ color: '#c62828', fontSize: '1.15em', fontWeight: '900' }}>ู…ุฌุงู†ุงู‹</span></>
118
  ) : (
119
- <>Start your 1st month (2 projects) <span style={{ color: '#c62828', fontSize: '1.15em', fontWeight: '900' }}>for free</span></>
120
  )}
121
  </button>
122
  </section>
@@ -274,24 +274,22 @@ export default function LandingPage({ isArabic, setIsArabic, onGetStarted }) {
274
  boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)',
275
  zIndex: 10
276
  }}>
277
- ๐ŸŒŸ {isArabic ? 'ุดู‡ุฑ ู…ุฌุงู†ูŠ (ู…ุดุฑูˆุนูŠู†)' : '1 Month Free (2 Projects)'}
278
  </div>
279
-
280
- <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--text-muted)', display: 'block', marginTop: '10px' }}>TIER 1</span>
281
-
282
- <div style={{ textDecoration: 'line-through', opacity: 0.5, fontSize: '0.9rem', marginTop: '5px' }}>50 AED</div>
283
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '5px 0', color: 'var(--primary)' }}>Free</h3>
284
- <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ู„ุดู‡ุฑ ุงู„ุฃูˆู„' : '1st month'}</p>
285
-
286
  <hr style={{ border: 'none', height: '1px', backgroundColor: 'var(--border-color)', margin: '15px 0' }} />
287
  <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', gap: '8px' }}>
288
- <h4 style={{ fontWeight: 700, color: 'var(--text-muted)', textDecoration: 'line-through' }}>{isArabic ? 'ู…ุดุฑูˆุน ูˆุงุญุฏ' : '1 Project'}</h4>
289
- <h4 style={{ fontWeight: 800, color: 'var(--success)' }}>{isArabic ? 'ู…ุดุฑูˆุนูŠู†' : '2 Projects'}</h4>
290
  </div>
291
  </div>
292
 
293
  <div className="glass-card" style={{ textAlign: 'center', padding: '25px 15px', border: '2px solid #3b82f6', borderRadius: '12px' }}>
294
- <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--primary)' }}>TIER 2</span>
295
  <div style={{ textDecoration: 'line-through', opacity: 0.5, fontSize: '0.9rem', marginTop: '5px' }}>120 AED</div>
296
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '5px 0', color: 'var(--success)' }}>60 AED</h3>
297
  <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุดู‡ุฑ' : 'per month'}</p>
@@ -304,7 +302,7 @@ export default function LandingPage({ isArabic, setIsArabic, onGetStarted }) {
304
  </div>
305
 
306
  <div className="glass-card" style={{ textAlign: 'center', padding: '25px 15px', border: '2px solid #3b82f6', borderRadius: '12px' }}>
307
- <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--text-muted)' }}>TIER 3</span>
308
  <div style={{ textDecoration: 'line-through', opacity: 0.5, fontSize: '0.9rem', marginTop: '5px' }}>250 AED</div>
309
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '5px 0', color: 'var(--success)' }}>125 AED</h3>
310
  <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุดู‡ุฑ' : 'per month'}</p>
@@ -317,7 +315,7 @@ export default function LandingPage({ isArabic, setIsArabic, onGetStarted }) {
317
  </div>
318
 
319
  <div className="glass-card" style={{ textAlign: 'center', padding: '25px 15px', border: '2px solid #3b82f6', borderRadius: '12px' }}>
320
- <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--text-muted)' }}>TIER 4</span>
321
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '10px 0 5px' }}>500 AED</h3>
322
  <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุดู‡ุฑ' : 'per month'}</p>
323
  <hr style={{ border: 'none', height: '1px', backgroundColor: 'var(--border-color)', margin: '15px 0' }} />
 
114
 
115
  <button className="btn btn-primary" onClick={onGetStarted} style={{ padding: '12px 35px', fontSize: '1.05rem', fontWeight: 700 }}>
116
  {isArabic ? (
117
+ <>ุงุจุฏุฃ ู…ุดุฑูˆุนูƒ ุงู„ุฃูˆู„ <span style={{ color: '#c62828', fontSize: '1.15em', fontWeight: '900' }}>ู…ุฌุงู†ุงู‹</span></>
118
  ) : (
119
+ <>Start your 1st project <span style={{ color: '#c62828', fontSize: '1.15em', fontWeight: '900' }}>for free</span></>
120
  )}
121
  </button>
122
  </section>
 
274
  boxShadow: '0 4px 10px rgba(16, 185, 129, 0.3)',
275
  zIndex: 10
276
  }}>
277
+ ๐ŸŒŸ {isArabic ? 'ุงุจุฏุฃ ู…ุฌุงู†ุงู‹' : 'Start Free'}
278
  </div>
279
+
280
+ <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--text-muted)', display: 'block', marginTop: '10px' }}>FREE</span>
281
+
 
282
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '5px 0', color: 'var(--primary)' }}>Free</h3>
283
+ <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุฃุฏุงุฉ' : 'per tool'}</p>
284
+
285
  <hr style={{ border: 'none', height: '1px', backgroundColor: 'var(--border-color)', margin: '15px 0' }} />
286
  <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', gap: '8px' }}>
287
+ <h4 style={{ fontWeight: 800, color: 'var(--success)' }}>{isArabic ? 'ู…ุดุฑูˆุนูƒ ุงู„ุฃูˆู„ ู…ุฌุงู†ุงู‹' : 'Your 1st project free'}</h4>
 
288
  </div>
289
  </div>
290
 
291
  <div className="glass-card" style={{ textAlign: 'center', padding: '25px 15px', border: '2px solid #3b82f6', borderRadius: '12px' }}>
292
+ <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--primary)' }}>TIER 1</span>
293
  <div style={{ textDecoration: 'line-through', opacity: 0.5, fontSize: '0.9rem', marginTop: '5px' }}>120 AED</div>
294
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '5px 0', color: 'var(--success)' }}>60 AED</h3>
295
  <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุดู‡ุฑ' : 'per month'}</p>
 
302
  </div>
303
 
304
  <div className="glass-card" style={{ textAlign: 'center', padding: '25px 15px', border: '2px solid #3b82f6', borderRadius: '12px' }}>
305
+ <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--text-muted)' }}>TIER 2</span>
306
  <div style={{ textDecoration: 'line-through', opacity: 0.5, fontSize: '0.9rem', marginTop: '5px' }}>250 AED</div>
307
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '5px 0', color: 'var(--success)' }}>125 AED</h3>
308
  <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุดู‡ุฑ' : 'per month'}</p>
 
315
  </div>
316
 
317
  <div className="glass-card" style={{ textAlign: 'center', padding: '25px 15px', border: '2px solid #3b82f6', borderRadius: '12px' }}>
318
+ <span style={{ fontSize: '0.85rem', fontWeight: 700, color: 'var(--text-muted)' }}>TIER 3</span>
319
  <h3 style={{ fontSize: '2rem', fontWeight: 800, margin: '10px 0 5px' }}>500 AED</h3>
320
  <p style={{ fontSize: '0.85rem', color: 'var(--text-secondary)', marginBottom: '15px' }}>{isArabic ? 'ู„ูƒู„ ุดู‡ุฑ' : 'per month'}</p>
321
  <hr style={{ border: 'none', height: '1px', backgroundColor: 'var(--border-color)', margin: '15px 0' }} />
utils/usage.py CHANGED
@@ -77,13 +77,40 @@ def monthly_usage(user_id: int, event_type: str, feature: str = "qto") -> int:
77
  return total
78
 
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  def project_entitlement(user: dict, feature: str = "qto") -> dict:
81
  """Single source of truth for 'can this user create a project right now?'.
82
 
83
  Monthly model: the tier gives `base` projects PER MONTH (resets monthly).
84
  Add-ons are ONE-TIME credits consumed only when creating beyond the monthly
85
- base โ€” they are not a permanent bump. So a user can create when they still
86
- have room in the month OR they hold at least one unused add-on credit.
 
 
87
  """
88
  user_id = int(user.get("id"))
89
  role = user.get("role")
@@ -97,8 +124,18 @@ def project_entitlement(user: dict, feature: str = "qto") -> dict:
97
  print(f"Error fetching extra projects: {e}")
98
  credits = 0
99
  used = monthly_usage(user_id, EVENT_PROJECT, feature)
100
- can_create = is_admin or (used < base) or (credits > 0)
101
- return {"base": base, "used": used, "credits": credits, "can_create": can_create, "is_admin": is_admin}
 
 
 
 
 
 
 
 
 
 
102
 
103
 
104
  def check_limit(user: dict, event_type: str, amount: int = 1, feature: str = "qto") -> tuple[bool, str]:
 
77
  return total
78
 
79
 
80
+ def lifetime_usage(user_id: int, event_type: str, feature: str = "qto") -> int:
81
+ """Total count of an event for a feature over the account's whole lifetime
82
+ (no monthly reset). Used for the one-time free project each new user gets."""
83
+ df = safe_query(
84
+ "SELECT quantity, metadata FROM qto_usage_logs WHERE user_id=%s AND event_type=%s",
85
+ (user_id, event_type),
86
+ )
87
+ if df.empty:
88
+ return 0
89
+ total = 0
90
+ for _, row in df.iterrows():
91
+ try:
92
+ meta = json.loads(row["metadata"] or "{}")
93
+ if meta.get("feature", "qto") == feature:
94
+ total += int(row["quantity"] or 0)
95
+ except Exception:
96
+ pass
97
+ return total
98
+
99
+
100
+ # Every new user gets this many free projects PER TOOL, once (lifetime), before
101
+ # they ever subscribe โ€” so they can try each tool on a real project for free.
102
+ FREE_PROJECTS_PER_FEATURE = 1
103
+
104
+
105
  def project_entitlement(user: dict, feature: str = "qto") -> dict:
106
  """Single source of truth for 'can this user create a project right now?'.
107
 
108
  Monthly model: the tier gives `base` projects PER MONTH (resets monthly).
109
  Add-ons are ONE-TIME credits consumed only when creating beyond the monthly
110
+ base โ€” they are not a permanent bump. On top of that, an unsubscribed user
111
+ (no paid tier) gets ONE free project per tool for their whole lifetime, so a
112
+ user can create when they still have monthly room OR hold an unused add-on
113
+ credit OR still have their free project.
114
  """
115
  user_id = int(user.get("id"))
116
  role = user.get("role")
 
124
  print(f"Error fetching extra projects: {e}")
125
  credits = 0
126
  used = monthly_usage(user_id, EVENT_PROJECT, feature)
127
+
128
+ # One-time free project for users without a paid plan (base == 0).
129
+ free_base = FREE_PROJECTS_PER_FEATURE if (base == 0 and not is_admin) else 0
130
+ free_used = lifetime_usage(user_id, EVENT_PROJECT, feature) if free_base else 0
131
+ free_left = max(free_base - free_used, 0)
132
+
133
+ can_create = is_admin or (used < base) or (credits > 0) or (free_left > 0)
134
+ return {
135
+ "base": base, "used": used, "credits": credits,
136
+ "free_base": free_base, "free_left": free_left,
137
+ "can_create": can_create, "is_admin": is_admin,
138
+ }
139
 
140
 
141
  def check_limit(user: dict, event_type: str, amount: int = 1, feature: str = "qto") -> tuple[bool, str]: