vpn/app/services/billing.py
2026-09-23 01:19:36 +00:00

26 lines
934 B
Python

from __future__ import annotations
from datetime import date
from app.models import PaymentInfo
def payment_banner(payment: PaymentInfo, today: date | None = None) -> str | None:
today = today or date.today()
due = payment.due_date(today.year, today.month)
days = (due - today).days
if days < 0:
next_month = 1 if today.month == 12 else today.month + 1
next_year = today.year + 1 if today.month == 12 else today.year
due = payment.due_date(next_year, next_month)
days = (due - today).days
if days > 5:
return None
if days == 0:
return f"Сегодня день оплаты · {payment.monthly_price_rub} ₽"
return f"Оплата через {days} дн. · {due.strftime('%-d.%m')} · {payment.monthly_price_rub} ₽"
def month_key(today: date | None = None) -> str:
today = today or date.today()
return f"{today.year:04d}-{today.month:02d}"