Add environment variable loading and Stripe configuration endpoints
- Added dotenv loading in main.py to read .env file - Enhanced health check endpoint to show Stripe and webhook configuration status - Added /config/stripe endpoint to safely expose publishable key for frontend - Environment variables are now properly loaded from .env file - Added status indicators for proper configuration verification
This commit is contained in:
parent
2b3f1e32c7
commit
b9bd7fcf3a
26
main.py
26
main.py
@ -1,8 +1,12 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from dotenv import load_dotenv
|
||||
from app.api.payments import router as payments_router
|
||||
from app.db.base import engine, Base
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
# Create database tables
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
@ -40,8 +44,30 @@ async def root():
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint"""
|
||||
import os
|
||||
|
||||
stripe_configured = bool(os.getenv("STRIPE_SECRET_KEY"))
|
||||
webhook_configured = bool(os.getenv("STRIPE_WEBHOOK_SECRET"))
|
||||
|
||||
return {
|
||||
"status": "healthy",
|
||||
"service": "stripe-payment-integration-service",
|
||||
"version": "1.0.0",
|
||||
"stripe_configured": stripe_configured,
|
||||
"webhook_configured": webhook_configured,
|
||||
}
|
||||
|
||||
|
||||
@app.get("/config/stripe")
|
||||
async def get_stripe_config():
|
||||
"""Get Stripe publishable key for frontend use"""
|
||||
import os
|
||||
|
||||
publishable_key = os.getenv("STRIPE_PUBLISHABLE_KEY")
|
||||
|
||||
return {
|
||||
"publishable_key": publishable_key,
|
||||
"test_mode": publishable_key.startswith("pk_test_")
|
||||
if publishable_key
|
||||
else False,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user