-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (27 loc) · 1.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import stripe
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.requests import Request
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
stripe.api_key = os.getenv("STRIPE_API_KEY")
@app.get("/payment")
async def payment_page(request:Request):
context = {"request":request}
return templates.TemplateResponse("payment.html", context)
@app.post("/payment")
async def make_payment(request: Request):
# Retrieve payment details from request
payment_details = await request.json()
# Create a payment intent using the Stripe API
intent = stripe.PaymentIntent.create(
amount=payment_details["amount"],
currency=payment_details["currency"],
payment_method_types=["card"]
)
# Return a JSON response containing the payment intent ID
return JSONResponse({"client_secret": intent.client_secret})