Jun 28 - Update payment flows

This commit is contained in:
2026-06-28 18:22:45 -04:00
parent 6c10b93c9d
commit 3d031a2ddf
2 changed files with 88 additions and 7 deletions
+17 -7
View File
@@ -56,9 +56,12 @@ def subscribe():
abort(400)
from control.base import control_session
from control.models import Tenant as ControlTenant
from control.models import Tenant as ControlTenant, Plan
from app.billing.stripe_client import create_stripe_customer, create_checkout_session
# Allow tenant to pick a plan via ?plan=<code> when on Free.
requested_plan_code = request.args.get('plan')
with control_session() as s:
t = s.get(ControlTenant, tenant.id)
if t is None:
@@ -66,13 +69,20 @@ def subscribe():
return redirect(url_for('tenant_settings.plan'))
plan = t.plan
# If a specific plan was requested (e.g. from the plan picker), use it.
if requested_plan_code:
chosen = s.query(Plan).filter_by(code=requested_plan_code).first()
if chosen and chosen.stripe_price_id:
plan = chosen
# If still on Free (no price ID), show the plan picker instead.
if plan is None or not plan.stripe_price_id:
flash(
'Your current plan does not have a Stripe price configured. '
'Please contact support to set up billing.',
'warning',
)
return redirect(url_for('tenant_settings.plan'))
paid_plans = (s.query(Plan)
.filter(Plan.stripe_price_id.isnot(None))
.order_by(Plan.price_cents)
.all())
return render_template('billing/plan_picker.html', plans=paid_plans)
# Get or create Stripe customer. Write back immediately within the
# control_session so the customer_id is persisted before the redirect.