Jun 28 - Update and polish UI/UX
This commit is contained in:
@@ -231,12 +231,12 @@ def plan():
|
||||
subscription_status = None
|
||||
trial_ends_at = None
|
||||
has_stripe_customer = False
|
||||
invoices = []
|
||||
if _mt_enabled():
|
||||
tenant_ctx = getattr(g, 'tenant', None)
|
||||
if tenant_ctx is not None:
|
||||
subscription_status = tenant_ctx.subscription_status
|
||||
trial_ends_at = tenant_ctx.trial_ends_at
|
||||
# Check whether stripe_customer_id is set (for "Manage Billing" link).
|
||||
if billing_enabled:
|
||||
try:
|
||||
from control.base import control_session
|
||||
@@ -244,8 +244,32 @@ def plan():
|
||||
with control_session() as s:
|
||||
t = s.get(ControlTenant, tenant_ctx.id)
|
||||
has_stripe_customer = bool(t and t.stripe_customer_id)
|
||||
stripe_customer_id = t.stripe_customer_id if t else None
|
||||
except Exception:
|
||||
pass
|
||||
stripe_customer_id = None
|
||||
|
||||
# Fetch last 10 invoices from Stripe.
|
||||
if stripe_customer_id:
|
||||
try:
|
||||
import stripe as _stripe
|
||||
_stripe.api_key = current_app.config.get('STRIPE_SECRET_KEY', '')
|
||||
raw = _stripe.Invoice.list(customer=stripe_customer_id, limit=10)
|
||||
for inv in raw.auto_paging_iter():
|
||||
import datetime as _dt
|
||||
invoices.append({
|
||||
'id': inv.id,
|
||||
'number': inv.number or inv.id,
|
||||
'date': _dt.datetime.fromtimestamp(inv.created).strftime('%b %d, %Y'),
|
||||
'amount': '${:,.2f}'.format(inv.amount_paid / 100),
|
||||
'currency': (inv.currency or 'usd').upper(),
|
||||
'status': inv.status,
|
||||
'pdf_url': inv.invoice_pdf,
|
||||
'hosted_url': inv.hosted_invoice_url,
|
||||
})
|
||||
if len(invoices) >= 10:
|
||||
break
|
||||
except Exception as exc:
|
||||
logger.error('tenant_settings.plan: stripe invoice fetch failed: %s', exc)
|
||||
|
||||
return render_template(
|
||||
'tenant_settings/plan.html',
|
||||
@@ -255,6 +279,7 @@ def plan():
|
||||
subscription_status=subscription_status,
|
||||
trial_ends_at=trial_ends_at,
|
||||
has_stripe_customer=has_stripe_customer,
|
||||
invoices=invoices,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user