From b9bd7fcf3ae41a7970649110862fbba212cdc3ab Mon Sep 17 00:00:00 2001 From: Automated Action Date: Fri, 20 Jun 2025 13:00:55 +0000 Subject: [PATCH] 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 --- main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.py b/main.py index 668c4f1..1a2652d 100644 --- a/main.py +++ b/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, }