stripe helper func updated
Browse files- utils/helper.py +45 -0
utils/helper.py
CHANGED
@@ -379,3 +379,48 @@ def call_gpt(prompt: str, content: str) -> str:
|
|
379 |
|
380 |
# Extracts and returns the response content from the model's completion
|
381 |
return response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
380 |
# Extracts and returns the response content from the model's completion
|
381 |
return response.choices[0].message.content
|
382 |
+
|
383 |
+
|
384 |
+
import os
|
385 |
+
import time
|
386 |
+
|
387 |
+
import requests
|
388 |
+
import streamlit as st
|
389 |
+
import stripe
|
390 |
+
|
391 |
+
# Set your secret key. Remember to switch to your live secret key in production!
|
392 |
+
stripe.api_key = os.environ["STRIPE_API_KEY"]
|
393 |
+
|
394 |
+
# Set the product id.
|
395 |
+
stripe_price_id = os.environ["STRIPE_PRICE_ID"]
|
396 |
+
|
397 |
+
|
398 |
+
# Function to create a Stripe Checkout Session
|
399 |
+
def create_checkout_session():
|
400 |
+
try:
|
401 |
+
session = stripe.checkout.Session.create(
|
402 |
+
payment_method_types=["card"],
|
403 |
+
line_items=[
|
404 |
+
{
|
405 |
+
"price": stripe_price_id, # Replace with your actual Stripe price ID
|
406 |
+
"quantity": 1,
|
407 |
+
}
|
408 |
+
],
|
409 |
+
mode="payment",
|
410 |
+
success_url="https://your-website.com/success?session_id={CHECKOUT_SESSION_ID}",
|
411 |
+
cancel_url="https://your-website.com/cancel",
|
412 |
+
)
|
413 |
+
return session.id, session.url
|
414 |
+
except Exception as e:
|
415 |
+
st.error(f"Error creating checkout session: {e}")
|
416 |
+
return None, None
|
417 |
+
|
418 |
+
|
419 |
+
# Function to check payment status
|
420 |
+
def check_payment_status(session_id):
|
421 |
+
try:
|
422 |
+
session = stripe.checkout.Session.retrieve(session_id)
|
423 |
+
return session.payment_status == "paid"
|
424 |
+
except Exception as e:
|
425 |
+
st.error(f"Error checking payment status: {e}")
|
426 |
+
return False
|