Checkpoint from VS Code for cloud agent session
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Authenticated account endpoints — usage summary and API key management."""
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.extensions import limiter
|
||||
@@ -9,7 +10,15 @@ from app.services.account_service import (
|
||||
revoke_api_key,
|
||||
)
|
||||
from app.services.policy_service import get_usage_summary_for_user
|
||||
from app.services.stripe_service import (
|
||||
is_stripe_configured,
|
||||
get_stripe_price_id,
|
||||
)
|
||||
from app.utils.auth import get_current_user_id
|
||||
import stripe
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
account_bp = Blueprint("account", __name__)
|
||||
|
||||
@@ -29,6 +38,69 @@ def get_usage_route():
|
||||
return jsonify(get_usage_summary_for_user(user_id, user["plan"])), 200
|
||||
|
||||
|
||||
@account_bp.route("/subscription", methods=["GET"])
|
||||
@limiter.limit("60/hour")
|
||||
def get_subscription_status():
|
||||
"""Return subscription status for the authenticated user."""
|
||||
user_id = get_current_user_id()
|
||||
if user_id is None:
|
||||
return jsonify({"error": "Authentication required."}), 401
|
||||
|
||||
user = get_user_by_id(user_id)
|
||||
if user is None:
|
||||
return jsonify({"error": "User not found."}), 404
|
||||
|
||||
# If Stripe is not configured, return basic info
|
||||
if not is_stripe_configured():
|
||||
return jsonify(
|
||||
{
|
||||
"plan": user["plan"],
|
||||
"stripe_configured": False,
|
||||
"subscription": None,
|
||||
}
|
||||
), 200
|
||||
|
||||
# Retrieve subscription info from Stripe if available
|
||||
subscription_info = None
|
||||
if user.get("stripe_subscription_id"):
|
||||
try:
|
||||
from app.services.stripe_service import get_stripe_secret_key
|
||||
|
||||
stripe.api_key = get_stripe_secret_key()
|
||||
|
||||
subscription = stripe.Subscription.retrieve(user["stripe_subscription_id"])
|
||||
subscription_info = {
|
||||
"id": subscription.id,
|
||||
"status": subscription.status,
|
||||
"current_period_start": subscription.current_period_start,
|
||||
"current_period_end": subscription.current_period_end,
|
||||
"cancel_at_period_end": subscription.cancel_at_period_end,
|
||||
"items": [
|
||||
{
|
||||
"price": item.price.id,
|
||||
"quantity": item.quantity,
|
||||
}
|
||||
for item in subscription.items.data
|
||||
],
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Failed to retrieve subscription {user['stripe_subscription_id']}: {e}"
|
||||
)
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"plan": user["plan"],
|
||||
"stripe_configured": True,
|
||||
"subscription": subscription_info,
|
||||
"pricing": {
|
||||
"monthly_price_id": get_stripe_price_id("monthly"),
|
||||
"yearly_price_id": get_stripe_price_id("yearly"),
|
||||
},
|
||||
}
|
||||
), 200
|
||||
|
||||
|
||||
@account_bp.route("/api-keys", methods=["GET"])
|
||||
@limiter.limit("60/hour")
|
||||
def list_api_keys_route():
|
||||
|
||||
Reference in New Issue
Block a user