Spaces:
Sleeping
Sleeping
| """ | |
| Payment.py: Plan enforcement and payment logic (Stripe stub). | |
| """ | |
| import os | |
| from .Config import PLAN_LIMITS, PLAN_PRICING | |
| class PaymentManager: | |
| def __init__(self): | |
| self.stripe_api_key = os.getenv("STRIPE_API_KEY") | |
| def check_plan_limit(self, plan, requested_tokens): | |
| limit = PLAN_LIMITS.get(plan, 0) | |
| return requested_tokens <= limit | |
| def get_price(self, plan): | |
| return PLAN_PRICING.get(plan, 0) | |
| def requires_payment(self, plan, requested_tokens): | |
| if plan == "free": | |
| return requested_tokens > PLAN_LIMITS["free"] | |
| return plan not in PLAN_LIMITS | |
| def create_checkout_session(self, plan, job_id): | |
| # Stub: Integrate with Stripe API in production | |
| return f"https://checkout.stripe.com/pay/{plan}/{job_id}" | |
| payment_manager = PaymentManager() |