2024-02-06 13:21:13 +08:00
|
|
|
from flask_login import current_user
|
|
|
|
from flask_restful import Resource, reqparse
|
|
|
|
|
2023-12-03 20:59:29 +08:00
|
|
|
from controllers.console import api
|
|
|
|
from controllers.console.setup import setup_required
|
2024-01-12 12:34:01 +08:00
|
|
|
from controllers.console.wraps import account_initialization_required, only_edition_cloud
|
2023-12-03 20:59:29 +08:00
|
|
|
from libs.login import login_required
|
|
|
|
from services.billing_service import BillingService
|
|
|
|
|
|
|
|
|
|
|
|
class Subscription(Resource):
|
|
|
|
@setup_required
|
|
|
|
@login_required
|
|
|
|
@account_initialization_required
|
|
|
|
@only_edition_cloud
|
|
|
|
def get(self):
|
|
|
|
parser = reqparse.RequestParser()
|
2024-08-26 15:29:10 +08:00
|
|
|
parser.add_argument("plan", type=str, required=True, location="args", choices=["professional", "team"])
|
|
|
|
parser.add_argument("interval", type=str, required=True, location="args", choices=["month", "year"])
|
2023-12-03 20:59:29 +08:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-01-26 18:26:15 +08:00
|
|
|
BillingService.is_tenant_owner_or_admin(current_user)
|
2023-12-18 16:59:31 +08:00
|
|
|
|
2024-08-26 15:29:10 +08:00
|
|
|
return BillingService.get_subscription(
|
|
|
|
args["plan"], args["interval"], current_user.email, current_user.current_tenant_id
|
|
|
|
)
|
2023-12-03 20:59:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Invoices(Resource):
|
|
|
|
@setup_required
|
|
|
|
@login_required
|
|
|
|
@account_initialization_required
|
|
|
|
@only_edition_cloud
|
|
|
|
def get(self):
|
2024-01-26 18:26:15 +08:00
|
|
|
BillingService.is_tenant_owner_or_admin(current_user)
|
|
|
|
return BillingService.get_invoices(current_user.email, current_user.current_tenant_id)
|
2023-12-03 20:59:29 +08:00
|
|
|
|
|
|
|
|
2024-08-26 15:29:10 +08:00
|
|
|
api.add_resource(Subscription, "/billing/subscription")
|
|
|
|
api.add_resource(Invoices, "/billing/invoices")
|