Fix/pylint cleanup (#8)
Some checks are pending
CI / build (3.10) (push) Waiting to run
CI / build (3.8) (push) Waiting to run
CI / build (3.9) (push) Waiting to run

* Fix pylint warnings across all 24 Python files in web_server

- Add module, class, and function docstrings (C0114, C0115, C0116)
- Fix import ordering: stdlib before third-party before local (C0411)
- Replace wildcard imports with explicit named imports (W0401)
- Remove trailing whitespace and add missing final newlines (C0303, C0304)
- Replace dict() with dict literals (R1735)
- Remove unused imports and variables (W0611, W0612)
- Narrow broad Exception catches to specific exceptions (W0718)
- Replace f-string logging with lazy % formatting (W1203)
- Fix variable naming: UPPER_CASE for constants, snake_case for locals (C0103)
- Add pylint disable comments for necessary global statements (W0603)
- Fix no-else-return, simplifiable-if-expression, singleton-comparison
- Fix bad indentation in stripe.py (W0311)
- Add encoding="utf-8" to open() calls (W1514)
- Add check=True to subprocess.run() calls (W1510)
- Register Celery task modules via conf.include

* Update `package-lock.json` add peer dependencies
This commit is contained in:
Christopher Ahern
2026-02-07 20:57:28 +00:00
committed by GitHub
parent fed1a2f288
commit 2758be8680
25 changed files with 680 additions and 419 deletions

View File

@@ -1,7 +1,11 @@
"""Stripe payment integration blueprint."""
import os
from flask import Blueprint, request, jsonify, session as s
from blueprints.middleware import login_required
from utils.user_utils import subscribe
import os, stripe
import stripe
stripe_bp = Blueprint("stripe", __name__)
@@ -20,7 +24,7 @@ def create_checkout_session():
# Checks to see who is subscribing to who
user_id = s.get("user_id")
streamer_id = request.args.get("streamer_id")
session = stripe.checkout.Session.create(
checkout_session = stripe.checkout.Session.create(
ui_mode = 'embedded',
payment_method_types=['card'],
line_items=[
@@ -33,19 +37,24 @@ def create_checkout_session():
redirect_on_completion = 'never',
client_reference_id = f"{user_id}-{streamer_id}"
)
except Exception as e:
except (ValueError, TypeError, KeyError) as e:
return str(e), 500
return jsonify(clientSecret=session.client_secret)
return jsonify(clientSecret=checkout_session.client_secret)
@stripe_bp.route('/session-status') # check for payment status
@stripe_bp.route('/session-status') # check for payment status
def session_status():
"""
Used to query payment status
"""
session = stripe.checkout.Session.retrieve(request.args.get('session_id'))
"""
Used to query payment status
"""
checkout_session = stripe.checkout.Session.retrieve(
request.args.get('session_id')
)
return jsonify(status=session.status, customer_email=session.customer_details.email)
return jsonify(
status=checkout_session.status,
customer_email=checkout_session.customer_details.email
)
@stripe_bp.route('/stripe/webhook', methods=['POST'])
def stripe_webhook():
@@ -65,13 +74,20 @@ def stripe_webhook():
raise e
except stripe.error.SignatureVerificationError as e:
raise e
if event['type'] == "checkout.session.completed": # Handles payment success webhook
session = event['data']['object']
product_id = stripe.checkout.Session.list_line_items(session['id'])['data'][0]['price']['product']
# Handles payment success webhook
if event['type'] == "checkout.session.completed":
checkout_session = event['data']['object']
product_id = stripe.checkout.Session.list_line_items(
checkout_session['id']
)['data'][0]['price']['product']
if product_id == subscription:
client_reference_id = session.get("client_reference_id")
user_id, streamer_id = map(int, client_reference_id.split("-"))
client_reference_id = checkout_session.get(
"client_reference_id"
)
user_id, streamer_id = map(
int, client_reference_id.split("-")
)
subscribe(user_id, streamer_id)
return "Success", 200
return "Success", 200