read.markets/alembic/versions
Giorgio Gilestro a07fd144ea stripe: per-cadence cooling-off + manage-subscription button
Bundles three related pieces that came out of the operator's first
end-to-end test of the paid flow:

1. Manage subscription button on /settings (paid users with a real
   Stripe sub — i.e. not credit-granted access). POSTs to the existing
   /api/stripe/portal endpoint; Stripe-hosted customer portal handles
   card updates, cancellation, monthly↔annual switch, invoice history.
   Replaces the stale "Paid features unlock with Paddle (D.3) or
   invite credits" hint for free users with a live link to /pricing.

2. Per-cadence cooling-off treatment:

   - **Annual £70**: 14-day free trial via
     subscription_data.trial_period_days=14. No money moves during
     the trial, so the CCR 2013 14-day refund question doesn't arise
     (nothing paid = nothing to refund). Card is still required at
     checkout so Stripe can charge on day 15.

   - **Monthly £7**: bills immediately. A 14-day trial there would
     give away ~50% of cycle one. Instead, /pricing now carries a
     required tick-box above the Subscribe buttons (subscribe stays
     disabled until checked) — by ticking, the user expressly
     consents to begin performance immediately and acknowledges that
     this extinguishes their statutory 14-day right under Reg 36
     CCR 2013. Consent collected on our own page (not via Stripe's
     account-wide consent_collection.terms_of_service) so each
     product can keep its own Terms URL as we add more.

3. T&C §6 clause 1 split into 1a (annual / trial substitute) +
   1b (monthly / Reg 36 waiver via on-page tick-box). Clause 2
   (post-cooling-off cancellation) unchanged.

Settings page shows "Free trial — N days remaining" while the
sub is in `trialing` status, falling back to "Paid subscription
active." once it transitions to active. Countdown is computed
server-side from User.stripe_trial_end_at (new column, migration
0020) populated by the subscription.created/updated webhook from
the Stripe trial_end timestamp; cleared on the trialing→active
transition and on revoke.

Drive-by: fixed a structlog kwarg-name collision on
`log.warning(..., event=event_type, ...)` in both polar_webhook.py
and stripe_billing.py — `event` is structlog's positional event
name and "got multiple values" crashed the user-not-found log
path. Renamed to `event_type=` everywhere it appeared. Caught by
the new trialing-stores-trial-end test.

Tests
- 4 new in test_stripe_billing.py covering monthly (no trial, no
  consent_collection), annual (trial, no consent), trialing stores
  trial_end, trialing→active clears trial_end.
- 1 existing test renamed + reworked for the consent split.
- Full suite: 224 passed, 5 skipped.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 20:06:19 +02:00
..
0001_initial_schema.py initial commit — cassandra v0.1 2026-05-15 21:56:10 +01:00
0002_position_name.py initial commit — cassandra v0.1 2026-05-15 21:56:10 +01:00
0003_log_tone_analysis.py initial commit — cassandra v0.1 2026-05-15 21:56:10 +01:00
0004_indicator_summaries.py add Eurostat + UK ONS sources; valuation/bubble/economy/bonds groups; aggregate read; market-open header 2026-05-15 23:07:42 +01:00
0005_widen_quote_symbol.py add Eurostat + UK ONS sources; valuation/bubble/economy/bonds groups; aggregate read; market-open header 2026-05-15 23:07:42 +01:00
0006_instrument_map.py phase B (1/4): CSV parser + InstrumentMap (T212 shortcode → Yahoo ticker) 2026-05-16 10:53:08 +01:00
0007_users.py phase A: user accounts + session-cookie auth 2026-05-16 11:12:10 +01:00
0008_email_otps.py phase G: data minimisation + passwordless auth + DeepSeek-first LLM 2026-05-18 14:16:57 +01:00
0009_ticker_universe.py phase G: data minimisation + passwordless auth + DeepSeek-first LLM 2026-05-18 14:16:57 +01:00
0010_drop_password.py phase G: data minimisation + passwordless auth + DeepSeek-first LLM 2026-05-18 14:16:57 +01:00
0011_drop_portfolio_tables.py phase G: data minimisation + passwordless auth + DeepSeek-first LLM 2026-05-18 14:16:57 +01:00
0012_headlines_tags.py news: auto-tag headlines + market-aware cadence + filter UI 2026-05-21 23:25:03 +01:00
0013_referrals.py phase D milestones 1+2: referral system + paid-access gate 2026-05-21 23:25:35 +01:00
0014_user_credit_until.py phase D milestones 1+2: referral system + paid-access gate 2026-05-21 23:25:35 +01:00
0015_portfolio_sync.py sync: encrypted cloud backup for portfolios + settings UX rework 2026-05-23 16:15:54 +02:00
0016_portfolio_sync_pepper_fp.py sync: detect orphaned blobs (pepper rotation) + fix AESGCM arg order 2026-05-25 12:49:11 +02:00
0017_email_digest.py db: drop redundant user_id index on email_sends 2026-05-25 22:55:33 +02:00
0018_polar_webhook.py polar: build /api/polar/webhook handler 2026-05-26 17:42:41 +02:00
0019_stripe.py stripe: wire checkout, customer portal, and webhook for read.markets 2026-05-26 18:45:13 +02:00
0020_trial_end.py stripe: per-cadence cooling-off + manage-subscription button 2026-05-26 20:06:19 +02:00