read.markets/app/templates
Giorgio Gilestro ce36ce36fd referrals: close D.3 — both parties get 45 days credit on conversion
The referral feature was half-built: codes captured, banner shown,
counts displayed — but no money flowed when a referred user paid.
The Settings page hard-coded "— (D.3)" for Active credits and the
marketing copy promised "50% off for 3 months" with nothing behind it.

Closing the loop:

- New `convert_referral(session, user)` in referral_service.py looks
  up the user's Referral row, stamps `converted_at` + `credited_at`,
  and extends `credit_until` by 45 days on BOTH the buyer and the
  referrer. Idempotent — replayed webhooks and renewals are no-ops.
  Stacks correctly when the user already has a credit window running
  (anchors at max(now, current_credit_until) like cli.grant_credit).

- Stripe webhook wires this into `_grant_paid`. A captured
  `first_paid_transition = user.tier != "paid"` gate avoids the DB
  lookup on every renewal event; convert_referral's own idempotency
  is the second line of defence.

- `_grant_paid` now takes `session` as its first positional arg so
  the conversion runs inside the same transaction as the tier flip
  and audit-row write. A mid-flight failure rolls everything back
  together — no partial state.

- Settings page replaces the "— (D.3)" placeholder with the live
  count of conversions still inside their 45-day credit window, plus
  a "+N days on your account" hint when the user has any credit of
  their own (referrer bonus, admin grant, or future refund-as-credit).

- Marketing copy on pricing.html + settings.html switches from "50%
  off for 3 months" to "45 days of paid access" — same economic value,
  honest about the actual mechanism (full free access rather than
  discounted billing).

Credit-amount rationale: 50% × 3 months ≈ 1.5 months of free
service ≈ 45 days. Pure-credit delivery is processor-agnostic, needs
no Stripe coupon plumbing, and stacks cleanly across referrals.

7 new tests in test_referral_conversion.py cover the happy path,
idempotency, no-referral no-op, credit stacking, deleted-referrer
survival, end-to-end webhook → credit landing, and the renewal-event
no-double-credit guarantee.

Also bundled: the Restore-button class fix from earlier
(portfolio.js — the cloud-restore "Restore" submit was unstyled and
picked up browser defaults; now uses .settings-btn like the rest of
the action-button family).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 23:05:29 +02:00
..
partials news: clamp free + anonymous to last 6h; paid keeps 24h 2026-05-25 22:49:21 +02:00
about.html public: landing + pricing + legal pages, apex-ready, lawyer-reviewed 2026-05-24 00:08:02 +02:00
base.html security: stop localStorage leaking portfolios across users 2026-05-26 19:14:17 +02:00
dashboard.html pricing: land £7/£70 paid tier and make behaviour match 2026-05-26 11:34:37 +02:00
disclaimer.html pricing: land £7/£70 paid tier and make behaviour match 2026-05-26 11:34:37 +02:00
landing.html pricing: land £7/£70 paid tier and make behaviour match 2026-05-26 11:34:37 +02:00
log.html pricing: land £7/£70 paid tier and make behaviour match 2026-05-26 11:34:37 +02:00
login.html public: landing + pricing + legal pages, apex-ready, lawyer-reviewed 2026-05-24 00:08:02 +02:00
news.html brand: rename product to "Read the Markets" (read.markets) 2026-05-22 19:39:38 +01:00
pricing.html referrals: close D.3 — both parties get 45 days credit on conversion 2026-05-26 23:05:29 +02:00
privacy.html public: landing + pricing + legal pages, apex-ready, lawyer-reviewed 2026-05-24 00:08:02 +02:00
public_base.html public: landing + pricing + legal pages, apex-ready, lawyer-reviewed 2026-05-24 00:08:02 +02:00
settings.html referrals: close D.3 — both parties get 45 days credit on conversion 2026-05-26 23:05:29 +02:00
terms.html stripe: per-cadence cooling-off + manage-subscription button 2026-05-26 20:06:19 +02:00
upload.html sync: encrypted cloud backup for portfolios + settings UX rework 2026-05-23 16:15:54 +02:00
verify.html ui: collapsible settings sections + welcome-email + larger auth inputs 2026-05-26 22:32:59 +02:00