Files
gsfdc/demo-dify/dify/api/services/billing_portal_service.py
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

49 lines
1.6 KiB
Python

"""Application service for Console Billing portal links."""
from collections.abc import Callable
from typing import Protocol
from machinery.context import RequestContext
from services.account_errors import AccountNotFoundError
from services.account_ports import AccountRepository
class BillingPortalLink(Protocol):
@property
def url(self) -> str: ...
class BillingPortalService:
def __init__(
self,
*,
accounts: AccountRepository,
get_subscription: Callable[[str, str, str, str], BillingPortalLink],
get_invoices: Callable[[str, str], BillingPortalLink],
) -> None:
self._accounts = accounts
self._get_subscription = get_subscription
self._get_invoices = get_invoices
def get_subscription(
self,
context: RequestContext,
*,
plan: str,
interval: str,
) -> BillingPortalLink:
email, workspace_id = self._resolve_account_email_and_workspace_id(context)
return self._get_subscription(plan, interval, email, workspace_id)
def get_invoices(self, context: RequestContext) -> BillingPortalLink:
email, workspace_id = self._resolve_account_email_and_workspace_id(context)
return self._get_invoices(email, workspace_id)
def _resolve_account_email_and_workspace_id(self, context: RequestContext) -> tuple[str, str]:
workspace_id = context.active_workspace_id
account = self._accounts.get(context.account_id)
if account is None:
raise AccountNotFoundError
return account.email, workspace_id