
- 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
74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
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)
|
|
|
|
app = FastAPI(
|
|
title="Stripe Payment Integration Service",
|
|
description="A FastAPI service for handling Stripe payments",
|
|
version="1.0.0",
|
|
)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(payments_router, prefix="/api/v1")
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""Base endpoint with service information"""
|
|
return {
|
|
"title": "Stripe Payment Integration Service",
|
|
"description": "A FastAPI service for handling Stripe payments",
|
|
"version": "1.0.0",
|
|
"documentation": "/docs",
|
|
"health_check": "/health",
|
|
}
|
|
|
|
|
|
@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,
|
|
}
|