added beginnings of stripe payment for subscriptions
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
hls
|
hls
|
||||||
|
venv/
|
||||||
BIN
core/__pycache__/forms.cpython-312.pyc
Normal file
BIN
core/__pycache__/forms.cpython-312.pyc
Normal file
Binary file not shown.
@@ -3,7 +3,7 @@ from flask_session import Session
|
|||||||
from core.blueprints.utils import logged_in_user
|
from core.blueprints.utils import logged_in_user
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__, template_folder="../../ui/templates/")
|
app = Flask(__name__, template_folder="../../ui/templates/", static_folder="../../ui/static")
|
||||||
app.config["SECRET_KEY"] = ""
|
app.config["SECRET_KEY"] = ""
|
||||||
app.config["SESSION_PERMANENT"] = False
|
app.config["SESSION_PERMANENT"] = False
|
||||||
app.config["SESSION_TYPE"] = "filesystem"
|
app.config["SESSION_TYPE"] = "filesystem"
|
||||||
@@ -14,8 +14,10 @@ def create_app():
|
|||||||
with app.app_context():
|
with app.app_context():
|
||||||
from core.blueprints.authentication import auth_bp
|
from core.blueprints.authentication import auth_bp
|
||||||
from core.blueprints.main import main_bp
|
from core.blueprints.main import main_bp
|
||||||
|
from core.blueprints.stripe import stripe_bp
|
||||||
|
|
||||||
app.register_blueprint(auth_bp)
|
app.register_blueprint(auth_bp)
|
||||||
app.register_blueprint(main_bp)
|
app.register_blueprint(main_bp)
|
||||||
|
app.register_blueprint(stripe_bp)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
BIN
core/blueprints/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
core/blueprints/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
core/blueprints/__pycache__/authentication.cpython-312.pyc
Normal file
BIN
core/blueprints/__pycache__/authentication.cpython-312.pyc
Normal file
Binary file not shown.
BIN
core/blueprints/__pycache__/main.cpython-312.pyc
Normal file
BIN
core/blueprints/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
BIN
core/blueprints/__pycache__/stripe.cpython-312.pyc
Normal file
BIN
core/blueprints/__pycache__/stripe.cpython-312.pyc
Normal file
Binary file not shown.
BIN
core/blueprints/__pycache__/utils.cpython-312.pyc
Normal file
BIN
core/blueprints/__pycache__/utils.cpython-312.pyc
Normal file
Binary file not shown.
38
core/blueprints/stripe.py
Normal file
38
core/blueprints/stripe.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
from flask import render_template, Blueprint, request, jsonify
|
||||||
|
|
||||||
|
import stripe
|
||||||
|
|
||||||
|
stripe_bp = Blueprint("stripe", __name__)
|
||||||
|
|
||||||
|
stripe.api_key = 'sk_test_51QikGlGk6yuk3uA8muEMPjMhUvbZWZiMCYQArZRXcFVn26hbt1kTz5yUVWkk3RQlltArbAXmVmkfEHU2z1Ch5Obv00Y03oT127'
|
||||||
|
|
||||||
|
@stripe_bp.route('/create-checkout-session', methods=['POST'])
|
||||||
|
def create_checkout_session():
|
||||||
|
try:
|
||||||
|
session = stripe.checkout.Session.create(
|
||||||
|
ui_mode = 'embedded',
|
||||||
|
payment_method_types=['card'],
|
||||||
|
line_items=[
|
||||||
|
{
|
||||||
|
'price': 'price_1QikNCGk6yuk3uA86mZf3dmM', #Subscription ID
|
||||||
|
'quantity': 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
mode='subscription',
|
||||||
|
redirect_on_completion = 'never'
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return str(e)
|
||||||
|
|
||||||
|
return jsonify(clientSecret=session.client_secret)
|
||||||
|
|
||||||
|
@stripe_bp.route('/session-status', methods=['GET']) # check for payment status
|
||||||
|
def session_status():
|
||||||
|
session = stripe.checkout.Session.retrieve(request.args.get('session_id'))
|
||||||
|
|
||||||
|
return jsonify(status=session.status, customer_email=session.customer_details.email)
|
||||||
|
|
||||||
|
@stripe_bp.route('/checkout', methods=['GET'])
|
||||||
|
def checkout():
|
||||||
|
return render_template("checkout.html")
|
||||||
BIN
database/__pycache__/database.cpython-312.pyc
Normal file
BIN
database/__pycache__/database.cpython-312.pyc
Normal file
Binary file not shown.
21
ui/static/checkout.js
Normal file
21
ui/static/checkout.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const stripe = Stripe("pk_test_51QikGlGk6yuk3uA8MT3uQrPMpUqJlKzkxfbrfrd34yXolWSbJYEFWm674s2aUydZyjjS0W2oByEJTV0LXMs1pWTk002ioHxQl6");
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
|
// Create a Checkout Session
|
||||||
|
async function initialize() {
|
||||||
|
const fetchClientSecret = async () => {
|
||||||
|
const response = await fetch("/create-checkout-session", {
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
const { clientSecret } = await response.json();
|
||||||
|
return clientSecret;
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkout = await stripe.initEmbeddedCheckout({
|
||||||
|
fetchClientSecret,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mount Checkout
|
||||||
|
checkout.mount('#checkout');
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Live Stream</title>
|
<title>Live Stream</title>
|
||||||
|
{% block header_config %}
|
||||||
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block main_content %}
|
{% block main_content %}
|
||||||
|
|||||||
15
ui/templates/checkout.html
Normal file
15
ui/templates/checkout.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block header_config %}
|
||||||
|
<link rel="stylesheet" href="style.css" />
|
||||||
|
<script src="https://js.stripe.com/v3/"></script>
|
||||||
|
<script src="{{ url_for('static', filename='checkout.js') }}" defer></script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block main_content %}
|
||||||
|
<!-- Display a payment form -->
|
||||||
|
<div id="checkout">
|
||||||
|
<!-- Checkout will insert the payment form here -->
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user